facebookresearch / facebookresearch/SlowFast

Error when feeding input to pretrained MViTv model

Open
#600 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bugs / Unexpected behaviors
I loaded the pretrained MViT model by using class "MViT" imported from "SlowFast/slowfast/models/video_model_builder.py" and then loading the checkpoint. Here I tried "MVIT_B_32x3_CONV.yaml" and "MVITv2_B_32x3.yaml". This step was successful. Then I have input data with size torch.Size([#batch_size, 3, 32, 224, 224]), then it gave me error:

```
File SlowFast\slowfast\models\video_model_builder.py:1209, in MViT.forward(self, x, bboxes, return_attn)
1207 if self.use_fixed_sincos_pos:
1208 cls_tokens = cls_tokens + self.pos_embed[:, :s, :]
-> 1209 x = torch.cat((cls_tokens, x), dim=1)
1211 if self.use_abs_pos:
1212 if self.sep_pos_embed:

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 96 but got size 16 for tensor number 1 in the list.
```
I suppose the input size is correct since it passes

`
assert len(bcthw) == 5 and (T, H, W) == (self.T, self.H, self.W), bcthw`

If my step to use your pretrained model is wrong, please let me know because I only found building MViT model from "SlowFast/slowfast/models/video_model_builder.py"

## Instructions To Reproduce the Issue:

Code to reproduce the error:

```
import torch
from slowfast.config.defaults import get_cfg
path_to_config = 'configs/Kinetics/MVITv2_B_32x3.yaml'
cfg = get_cfg()
cfg.merge_from_file(path_to_config)
from slowfast.models.video_model_builder import MViT
model = MViT(cfg)

from slowfast.utils.checkpoint import load_checkpoint
path_to_checkpoint = 'MViTv2_B_32x3_k400_f304025456.pyth' #pretrained checkpoint file
load_checkpoint(path_to_checkpoint, model,data_parallel=False)

model.eval()

#we can create an input tensor with expected size and here I set the batch size to be 5
input = torch.ones((5,3,32,224,224))
output = model(input)

```

We can still get the error using MViTv1

```
from slowfast.config.defaults import get_cfg
path_to_config = 'configs/Kinetics/MVIT_B_32x3_CONV.yaml'
cfg = get_cfg()
cfg.merge_from_file(path_to_config)
from slowfast.models.video_model_builder import MViT
model = MViT(cfg)

from slowfast.utils.checkpoint import load_checkpoint
path_to_checkpoint = 'k400.pyth' #pretrained checkpoint file
load_checkpoint(path_to_checkpoint, model,data_parallel=False)

model.eval()

#we can create an input tensor with expected size and here I set the batch size to be 5
input = torch.ones((5,3,32,224,224))
output = model(input)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.