We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
RuntimeError: Expected 5-dimensional input for 5-dimensional weight [64, 3, 3, 7, 7], but got 4-dimensional input of size [64, 1, 256, 256] instead
Hi, there, i have succefully converted TSN .pth model to .onnx format in colab, and now i want to convert other models like ircsnto to onnx format, but i came across an error as the title described. The command i run in colab : `!python tools/pytorch2onnx.py ./configs/recognition/csn/ircsn_ig65m_pretrained_bnfrozen_r152_32x2x1_58e_kinetics400_rgb.py ./checkpoints/ircsn_ig65m_pretrained_bnfrozen_r152_32x2x1_58e_kinetics400_rgb_20200812-9037a758.pth --shape 32 2 1 256 256 --verify --show`
Its output logs are : 
```
Traceback (most recent call last):
  File "tools/pytorch2onnx.py", line 163, in <module>
    verify=args.verify)
  File "tools/pytorch2onnx.py", line 74, in pytorch2onnx
    opset_version=opset_version)
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/__init__.py", line 168, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 69, in export
    use_external_data_format=use_external_data_format)
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 488, in _export
    fixed_batch_size=fixed_batch_size)
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 334, in _model_to_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 291, in _trace_and_get_graph_from_model
    torch.jit._get_trace_graph(model, args, _force_outplace=False, _return_inputs_states=True)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 278, in _get_trace_graph
    outs = ONNXTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 361, in forward
    self._force_outplace,
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 348, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/content/mmaction2/mmaction/models/recognizers/recognizer3d.py", line 59, in forward_dummy
    x = self.extract_feat(imgs)
  File "/usr/local/lib/python3.6/dist-packages/mmcv/runner/fp16_utils.py", line 84, in new_func
    return old_func(*args, **kwargs)
  File "/content/mmaction2/mmaction/models/recognizers/base.py", line 72, in extract_feat
    x = self.backbone(imgs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/content/mmaction2/mmaction/models/backbones/resnet3d.py", line 795, in forward
    x = self.conv1(x)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/mmcv/cnn/bricks/conv_module.py", line 192, in forward
    x = self.conv(x)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/mmcv/cnn/bricks/wrappers.py", line 79, in forward
    return super().forward(x)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 485, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Expected 5-dimensional input for 5-dimensional weight [64, 3, 3, 7, 7], but got 4-dimensional input of size [64, 1, 256, 256] instead
```
I also tried on i3d and tpn, they all have similiar errors, what is the common reason for this type of error ? Thanks !


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mmaction/models/recognizers/recognizer3d.py`
Content:
```
1 from ..registry import RECOGNIZERS
2 from .base import BaseRecognizer
3 
4 
5 @RECOGNIZERS.register_module()
6 class Recognizer3D(BaseRecognizer):
7     """3D recognizer model framework."""
8 
9     def forward_train(self, imgs, labels, **kwargs):
10         """Defines the computation performed at every call when training."""
11         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
12         losses = dict()
13 
14         x = self.extract_feat(imgs)
15         if hasattr(self, 'neck'):
16             x, loss_aux = self.neck(x, labels.squeeze())
17             losses.update(loss_aux)
18 
19         cls_score = self.cls_head(x)
20         gt_labels = labels.squeeze()
21         loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)
22         losses.update(loss_cls)
23 
24         return losses
25 
26     def _do_test(self, imgs):
27         """Defines the computation performed at every call when evaluation,
28         testing and gradcam."""
29         num_segs = imgs.shape[1]
30         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
31 
32         x = self.extract_feat(imgs)
33         if hasattr(self, 'neck'):
34             x, _ = self.neck(x)
35 
36         cls_score = self.cls_head(x)
37         cls_score = self.average_clip(cls_score, num_segs)
38 
39         return cls_score
40 
41     def forward_test(self, imgs):
42         """Defines the computation performed at every call when evaluation and
43         testing."""
44         return self._do_test(imgs).cpu().numpy()
45 
46     def forward_dummy(self, imgs):
47         """Used for computing network FLOPs.
48 
49         See ``tools/analysis/get_flops.py``.
50 
51         Args:
52             imgs (torch.Tensor): Input images.
53 
54         Returns:
55             Tensor: Class score.
56         """
57         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
58 
59         x = self.extract_feat(imgs)
60         outs = (self.cls_head(x), )
61         return outs
62 
63     def forward_gradcam(self, imgs):
64         """Defines the computation performed at every call when using gradcam
65         utils."""
66         return self._do_test(imgs)
67
```

Path: `mmaction/models/recognizers/recognizer2d.py`
Content:
```
1 from ..registry import RECOGNIZERS
2 from .base import BaseRecognizer
3 
4 
5 @RECOGNIZERS.register_module()
6 class Recognizer2D(BaseRecognizer):
7     """2D recognizer model framework."""
8 
9     def forward_train(self, imgs, labels, **kwargs):
10         """Defines the computation performed at every call when training."""
11         batches = imgs.shape[0]
12         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
13         num_segs = imgs.shape[0] // batches
14 
15         losses = dict()
16 
17         x = self.extract_feat(imgs)
18         if hasattr(self, 'neck'):
19             x = [
20                 each.reshape((-1, num_segs) +
21                              each.shape[1:]).transpose(1, 2).contiguous()
22                 for each in x
23             ]
24             x, _ = self.neck(x, labels.squeeze())
25             x = x.squeeze(2)
26             num_segs = 1
27 
28         cls_score = self.cls_head(x, num_segs)
29         gt_labels = labels.squeeze()
30         loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)
31         losses.update(loss_cls)
32 
33         return losses
34 
35     def _do_test(self, imgs):
36         """Defines the computation performed at every call when evaluation,
37         testing and gradcam."""
38         batches = imgs.shape[0]
39 
40         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
41         num_segs = imgs.shape[0] // batches
42 
43         losses = dict()
44 
45         x = self.extract_feat(imgs)
46         if hasattr(self, 'neck'):
47             x = [
48                 each.reshape((-1, num_segs) +
49                              each.shape[1:]).transpose(1, 2).contiguous()
50                 for each in x
51             ]
52             x, loss_aux = self.neck(x)
53             x = x.squeeze(2)
54             losses.update(loss_aux)
55             num_segs = 1
56 
57         # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes]
58         # When using `TSMHead`, shape is [batch_size * num_crops, num_classes]
59         # `num_crops` is calculated by:
60         #   1) `twice_sample` in `SampleFrames`
61         #   2) `num_sample_positions` in `DenseSampleFrames`
62         #   3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline`
63         #   4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1`
64         cls_score = self.cls_head(x, num_segs)
65 
66         assert cls_score.size()[0] % batches == 0
67         # calculate num_crops automatically
68         cls_score = self.average_clip(cls_score,
69                                       cls_score.size()[0] // batches)
70 
71         return cls_score
72 
73     def forward_test(self, imgs):
74         """Defines the computation performed at every call when evaluation and
75         testing."""
76         return self._do_test(imgs).cpu().numpy()
77 
78     def forward_dummy(self, imgs):
79         """Used for computing network FLOPs.
80 
81         See ``tools/analysis/get_flops.py``.
82 
83         Args:
84             imgs (torch.Tensor): Input images.
85 
86         Returns:
87             Tensor: Class score.
88         """
89         batches = imgs.shape[0]
90         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
91         num_segs = imgs.shape[0] // batches
92 
93         x = self.extract_feat(imgs)
94         outs = (self.cls_head(x, num_segs), )
95         return outs
96 
97     def forward_gradcam(self, imgs):
98         """Defines the computation performed at every call when using gradcam
99         utils."""
100         return self._do_test(imgs)
101
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mmaction/models/recognizers/recognizer2d.py b/mmaction/models/recognizers/recognizer2d.py
--- a/mmaction/models/recognizers/recognizer2d.py
+++ b/mmaction/models/recognizers/recognizer2d.py
@@ -91,6 +91,16 @@
         num_segs = imgs.shape[0] // batches
 
         x = self.extract_feat(imgs)
+        if hasattr(self, 'neck'):
+            x = [
+                each.reshape((-1, num_segs) +
+                             each.shape[1:]).transpose(1, 2).contiguous()
+                for each in x
+            ]
+            x, _ = self.neck(x)
+            x = x.squeeze(2)
+            num_segs = 1
+
         outs = (self.cls_head(x, num_segs), )
         return outs
 
diff --git a/mmaction/models/recognizers/recognizer3d.py b/mmaction/models/recognizers/recognizer3d.py
--- a/mmaction/models/recognizers/recognizer3d.py
+++ b/mmaction/models/recognizers/recognizer3d.py
@@ -55,8 +55,11 @@
             Tensor: Class score.
         """
         imgs = imgs.reshape((-1, ) + imgs.shape[2:])
-
         x = self.extract_feat(imgs)
+
+        if hasattr(self, 'neck'):
+            x, _ = self.neck(x)
+
         outs = (self.cls_head(x), )
         return outs

{"golden_diff": "diff --git a/mmaction/models/recognizers/recognizer2d.py b/mmaction/models/recognizers/recognizer2d.py\n--- a/mmaction/models/recognizers/recognizer2d.py\n+++ b/mmaction/models/recognizers/recognizer2d.py\n@@ -91,6 +91,16 @@\n         num_segs = imgs.shape[0] // batches\n \n         x = self.extract_feat(imgs)\n+        if hasattr(self, 'neck'):\n+            x = [\n+                each.reshape((-1, num_segs) +\n+                             each.shape[1:]).transpose(1, 2).contiguous()\n+                for each in x\n+            ]\n+            x, _ = self.neck(x)\n+            x = x.squeeze(2)\n+            num_segs = 1\n+\n         outs = (self.cls_head(x, num_segs), )\n         return outs\n \ndiff --git a/mmaction/models/recognizers/recognizer3d.py b/mmaction/models/recognizers/recognizer3d.py\n--- a/mmaction/models/recognizers/recognizer3d.py\n+++ b/mmaction/models/recognizers/recognizer3d.py\n@@ -55,8 +55,11 @@\n             Tensor: Class score.\n         \"\"\"\n         imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n-\n         x = self.extract_feat(imgs)\n+\n+        if hasattr(self, 'neck'):\n+            x, _ = self.neck(x)\n+\n         outs = (self.cls_head(x), )\n         return outs\n", "issue": "RuntimeError: Expected 5-dimensional input for 5-dimensional weight [64, 3, 3, 7, 7], but got 4-dimensional input of size [64, 1, 256, 256] instead\nHi, there, i have succefully converted TSN .pth model to .onnx format in colab, and now i want to convert other models like ircsnto to onnx format, but i came across an error as the title described. The command i run in colab : `!python tools/pytorch2onnx.py ./configs/recognition/csn/ircsn_ig65m_pretrained_bnfrozen_r152_32x2x1_58e_kinetics400_rgb.py ./checkpoints/ircsn_ig65m_pretrained_bnfrozen_r152_32x2x1_58e_kinetics400_rgb_20200812-9037a758.pth --shape 32 2 1 256 256 --verify --show`\r\nIts output logs are : \r\n```\r\nTraceback (most recent call last):\r\n  File \"tools/pytorch2onnx.py\", line 163, in <module>\r\n    verify=args.verify)\r\n  File \"tools/pytorch2onnx.py\", line 74, in pytorch2onnx\r\n    opset_version=opset_version)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/onnx/__init__.py\", line 168, in export\r\n    custom_opsets, enable_onnx_checker, use_external_data_format)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py\", line 69, in export\r\n    use_external_data_format=use_external_data_format)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py\", line 488, in _export\r\n    fixed_batch_size=fixed_batch_size)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py\", line 334, in _model_to_graph\r\n    graph, torch_out = _trace_and_get_graph_from_model(model, args, training)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py\", line 291, in _trace_and_get_graph_from_model\r\n    torch.jit._get_trace_graph(model, args, _force_outplace=False, _return_inputs_states=True)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py\", line 278, in _get_trace_graph\r\n    outs = ONNXTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 550, in __call__\r\n    result = self.forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py\", line 361, in forward\r\n    self._force_outplace,\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py\", line 348, in wrapper\r\n    outs.append(self.inner(*trace_inputs))\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 548, in __call__\r\n    result = self._slow_forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 534, in _slow_forward\r\n    result = self.forward(*input, **kwargs)\r\n  File \"/content/mmaction2/mmaction/models/recognizers/recognizer3d.py\", line 59, in forward_dummy\r\n    x = self.extract_feat(imgs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/mmcv/runner/fp16_utils.py\", line 84, in new_func\r\n    return old_func(*args, **kwargs)\r\n  File \"/content/mmaction2/mmaction/models/recognizers/base.py\", line 72, in extract_feat\r\n    x = self.backbone(imgs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 548, in __call__\r\n    result = self._slow_forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 534, in _slow_forward\r\n    result = self.forward(*input, **kwargs)\r\n  File \"/content/mmaction2/mmaction/models/backbones/resnet3d.py\", line 795, in forward\r\n    x = self.conv1(x)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 548, in __call__\r\n    result = self._slow_forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 534, in _slow_forward\r\n    result = self.forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/mmcv/cnn/bricks/conv_module.py\", line 192, in forward\r\n    x = self.conv(x)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 548, in __call__\r\n    result = self._slow_forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py\", line 534, in _slow_forward\r\n    result = self.forward(*input, **kwargs)\r\n  File \"/usr/local/lib/python3.6/dist-packages/mmcv/cnn/bricks/wrappers.py\", line 79, in forward\r\n    return super().forward(x)\r\n  File \"/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py\", line 485, in forward\r\n    self.padding, self.dilation, self.groups)\r\nRuntimeError: Expected 5-dimensional input for 5-dimensional weight [64, 3, 3, 7, 7], but got 4-dimensional input of size [64, 1, 256, 256] instead\r\n```\r\nI also tried on i3d and tpn, they all have similiar errors, what is the common reason for this type of error ? Thanks !\r\n\n", "before_files": [{"content": "from ..registry import RECOGNIZERS\nfrom .base import BaseRecognizer\n\n\n@RECOGNIZERS.register_module()\nclass Recognizer3D(BaseRecognizer):\n    \"\"\"3D recognizer model framework.\"\"\"\n\n    def forward_train(self, imgs, labels, **kwargs):\n        \"\"\"Defines the computation performed at every call when training.\"\"\"\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x, loss_aux = self.neck(x, labels.squeeze())\n            losses.update(loss_aux)\n\n        cls_score = self.cls_head(x)\n        gt_labels = labels.squeeze()\n        loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)\n        losses.update(loss_cls)\n\n        return losses\n\n    def _do_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation,\n        testing and gradcam.\"\"\"\n        num_segs = imgs.shape[1]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x, _ = self.neck(x)\n\n        cls_score = self.cls_head(x)\n        cls_score = self.average_clip(cls_score, num_segs)\n\n        return cls_score\n\n    def forward_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation and\n        testing.\"\"\"\n        return self._do_test(imgs).cpu().numpy()\n\n    def forward_dummy(self, imgs):\n        \"\"\"Used for computing network FLOPs.\n\n        See ``tools/analysis/get_flops.py``.\n\n        Args:\n            imgs (torch.Tensor): Input images.\n\n        Returns:\n            Tensor: Class score.\n        \"\"\"\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n\n        x = self.extract_feat(imgs)\n        outs = (self.cls_head(x), )\n        return outs\n\n    def forward_gradcam(self, imgs):\n        \"\"\"Defines the computation performed at every call when using gradcam\n        utils.\"\"\"\n        return self._do_test(imgs)\n", "path": "mmaction/models/recognizers/recognizer3d.py"}, {"content": "from ..registry import RECOGNIZERS\nfrom .base import BaseRecognizer\n\n\n@RECOGNIZERS.register_module()\nclass Recognizer2D(BaseRecognizer):\n    \"\"\"2D recognizer model framework.\"\"\"\n\n    def forward_train(self, imgs, labels, **kwargs):\n        \"\"\"Defines the computation performed at every call when training.\"\"\"\n        batches = imgs.shape[0]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x = [\n                each.reshape((-1, num_segs) +\n                             each.shape[1:]).transpose(1, 2).contiguous()\n                for each in x\n            ]\n            x, _ = self.neck(x, labels.squeeze())\n            x = x.squeeze(2)\n            num_segs = 1\n\n        cls_score = self.cls_head(x, num_segs)\n        gt_labels = labels.squeeze()\n        loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)\n        losses.update(loss_cls)\n\n        return losses\n\n    def _do_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation,\n        testing and gradcam.\"\"\"\n        batches = imgs.shape[0]\n\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x = [\n                each.reshape((-1, num_segs) +\n                             each.shape[1:]).transpose(1, 2).contiguous()\n                for each in x\n            ]\n            x, loss_aux = self.neck(x)\n            x = x.squeeze(2)\n            losses.update(loss_aux)\n            num_segs = 1\n\n        # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes]\n        # When using `TSMHead`, shape is [batch_size * num_crops, num_classes]\n        # `num_crops` is calculated by:\n        #   1) `twice_sample` in `SampleFrames`\n        #   2) `num_sample_positions` in `DenseSampleFrames`\n        #   3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline`\n        #   4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1`\n        cls_score = self.cls_head(x, num_segs)\n\n        assert cls_score.size()[0] % batches == 0\n        # calculate num_crops automatically\n        cls_score = self.average_clip(cls_score,\n                                      cls_score.size()[0] // batches)\n\n        return cls_score\n\n    def forward_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation and\n        testing.\"\"\"\n        return self._do_test(imgs).cpu().numpy()\n\n    def forward_dummy(self, imgs):\n        \"\"\"Used for computing network FLOPs.\n\n        See ``tools/analysis/get_flops.py``.\n\n        Args:\n            imgs (torch.Tensor): Input images.\n\n        Returns:\n            Tensor: Class score.\n        \"\"\"\n        batches = imgs.shape[0]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        x = self.extract_feat(imgs)\n        outs = (self.cls_head(x, num_segs), )\n        return outs\n\n    def forward_gradcam(self, imgs):\n        \"\"\"Defines the computation performed at every call when using gradcam\n        utils.\"\"\"\n        return self._do_test(imgs)\n", "path": "mmaction/models/recognizers/recognizer2d.py"}], "after_files": [{"content": "from ..registry import RECOGNIZERS\nfrom .base import BaseRecognizer\n\n\n@RECOGNIZERS.register_module()\nclass Recognizer3D(BaseRecognizer):\n    \"\"\"3D recognizer model framework.\"\"\"\n\n    def forward_train(self, imgs, labels, **kwargs):\n        \"\"\"Defines the computation performed at every call when training.\"\"\"\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x, loss_aux = self.neck(x, labels.squeeze())\n            losses.update(loss_aux)\n\n        cls_score = self.cls_head(x)\n        gt_labels = labels.squeeze()\n        loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)\n        losses.update(loss_cls)\n\n        return losses\n\n    def _do_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation,\n        testing and gradcam.\"\"\"\n        num_segs = imgs.shape[1]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x, _ = self.neck(x)\n\n        cls_score = self.cls_head(x)\n        cls_score = self.average_clip(cls_score, num_segs)\n\n        return cls_score\n\n    def forward_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation and\n        testing.\"\"\"\n        return self._do_test(imgs).cpu().numpy()\n\n    def forward_dummy(self, imgs):\n        \"\"\"Used for computing network FLOPs.\n\n        See ``tools/analysis/get_flops.py``.\n\n        Args:\n            imgs (torch.Tensor): Input images.\n\n        Returns:\n            Tensor: Class score.\n        \"\"\"\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        x = self.extract_feat(imgs)\n\n        if hasattr(self, 'neck'):\n            x, _ = self.neck(x)\n\n        outs = (self.cls_head(x), )\n        return outs\n\n    def forward_gradcam(self, imgs):\n        \"\"\"Defines the computation performed at every call when using gradcam\n        utils.\"\"\"\n        return self._do_test(imgs)\n", "path": "mmaction/models/recognizers/recognizer3d.py"}, {"content": "from ..registry import RECOGNIZERS\nfrom .base import BaseRecognizer\n\n\n@RECOGNIZERS.register_module()\nclass Recognizer2D(BaseRecognizer):\n    \"\"\"2D recognizer model framework.\"\"\"\n\n    def forward_train(self, imgs, labels, **kwargs):\n        \"\"\"Defines the computation performed at every call when training.\"\"\"\n        batches = imgs.shape[0]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x = [\n                each.reshape((-1, num_segs) +\n                             each.shape[1:]).transpose(1, 2).contiguous()\n                for each in x\n            ]\n            x, _ = self.neck(x, labels.squeeze())\n            x = x.squeeze(2)\n            num_segs = 1\n\n        cls_score = self.cls_head(x, num_segs)\n        gt_labels = labels.squeeze()\n        loss_cls = self.cls_head.loss(cls_score, gt_labels, **kwargs)\n        losses.update(loss_cls)\n\n        return losses\n\n    def _do_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation,\n        testing and gradcam.\"\"\"\n        batches = imgs.shape[0]\n\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        losses = dict()\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x = [\n                each.reshape((-1, num_segs) +\n                             each.shape[1:]).transpose(1, 2).contiguous()\n                for each in x\n            ]\n            x, loss_aux = self.neck(x)\n            x = x.squeeze(2)\n            losses.update(loss_aux)\n            num_segs = 1\n\n        # When using `TSNHead` or `TPNHead`, shape is [batch_size, num_classes]\n        # When using `TSMHead`, shape is [batch_size * num_crops, num_classes]\n        # `num_crops` is calculated by:\n        #   1) `twice_sample` in `SampleFrames`\n        #   2) `num_sample_positions` in `DenseSampleFrames`\n        #   3) `ThreeCrop/TenCrop/MultiGroupCrop` in `test_pipeline`\n        #   4) `num_clips` in `SampleFrames` or its subclass if `clip_len != 1`\n        cls_score = self.cls_head(x, num_segs)\n\n        assert cls_score.size()[0] % batches == 0\n        # calculate num_crops automatically\n        cls_score = self.average_clip(cls_score,\n                                      cls_score.size()[0] // batches)\n\n        return cls_score\n\n    def forward_test(self, imgs):\n        \"\"\"Defines the computation performed at every call when evaluation and\n        testing.\"\"\"\n        return self._do_test(imgs).cpu().numpy()\n\n    def forward_dummy(self, imgs):\n        \"\"\"Used for computing network FLOPs.\n\n        See ``tools/analysis/get_flops.py``.\n\n        Args:\n            imgs (torch.Tensor): Input images.\n\n        Returns:\n            Tensor: Class score.\n        \"\"\"\n        batches = imgs.shape[0]\n        imgs = imgs.reshape((-1, ) + imgs.shape[2:])\n        num_segs = imgs.shape[0] // batches\n\n        x = self.extract_feat(imgs)\n        if hasattr(self, 'neck'):\n            x = [\n                each.reshape((-1, num_segs) +\n                             each.shape[1:]).transpose(1, 2).contiguous()\n                for each in x\n            ]\n            x, _ = self.neck(x)\n            x = x.squeeze(2)\n            num_segs = 1\n\n        outs = (self.cls_head(x, num_segs), )\n        return outs\n\n    def forward_gradcam(self, imgs):\n        \"\"\"Defines the computation performed at every call when using gradcam\n        utils.\"\"\"\n        return self._do_test(imgs)\n", "path": "mmaction/models/recognizers/recognizer2d.py"}]}