question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

r3d_18(3D_resnet) do not work!! (When I import it in my torch.nn.Module)

See original GitHub issue

Hi, I just loaded pre-trained 3D-resnets (https://pytorch.org/vision/stable/models.html#video-classification) What I loaded is ResNet 3D 18(r3d_18) and my input shape is [1 x 3 x 192 x 112 x 112] where 1 is batch size, 3 is [R,G,B] and 192 is video_length and 112 and 112 is W and H.

I got this error, at forward()



  File "train_total.py", line 497, in forward
    timed_CNN_out_front = self.CNNlayers_front(pixel.cuda())
  File "/home/ai/anaconda3/envs/mos/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ai/anaconda3/envs/mos/lib/python3.6/site-packages/torch/nn/modules/container.py", line 92, in forward
    input = module(input)
  File "/home/ai/anaconda3/envs/mos/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ai/anaconda3/envs/mos/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "/home/ai/anaconda3/envs/mos/lib/python3.6/site-packages/torch/nn/functional.py", line 1372, in linear
    output = input.matmul(weight.t())
RuntimeError: size mismatch, m1: [512 x 1], m2: [512 x 400] at /opt/anaconda/conda-bld/pytorch-base_1600153523661/work/aten/src/THC/generic/THCTensorMathBlas.cu:290



Why this error come out?? I just read that resnet3D requries the above shape what I mentioned…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NicolasHugcommented, Jun 21, 2021

Thanks for the feedback @SungmanHong , you’re right that ideally model ablation / tweaking could be a bit easier. As @fmassa mentioned, hopefully #3597 will make this easier and will be available in the next release. We’ll make sure to write good docs to explain how to perform that.

Since the original problem is resolved here, I’ll close the issue if you don’t mind

0reactions
NeighborhoodCodingcommented, Jun 21, 2021

Thank you for helping me. I didn’t know that the flatten layer was missing because I lacked detailed debugging skills, so I asked foolishly, but thank you for your kind reply.

I think, PyTorch was good because we are able to selectively import the layers by nn.Sequential(*list(model.children()). For example, When we are doing transfer learning on images or videos, choosing What layers to import from pre-trained ResNets(Not all layers) would be great for very flexible and easy way coding for newbie researchers.

Of course, it may be difficult to ensure full compatibility for all models to nn.Sequential(*list(model.children()), but if compatibility is up-leveled, I think it would help researchers in many areas (in my case, 3d-resnet for video classification or regression).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Derived Class of Pytorch nn.Module Cannot be Loaded by ...
I have noticed that some saved nn.Modules cannot be loaded when the whole module is being imported into another module. To give an...
Read more >
Module — PyTorch 1.13 documentation
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def ... This function is called when building the module's state_dict() .
Read more >
How to use the torch.nn.Module function in torch - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... List, Optional from torch import...
Read more >
Classification in PyTorch
This module torch.nn also has various layers that you can use to build your ... are no tunable parameters associated with the ReLU...
Read more >
torch.nn.modules.module — transformers 4.4.2 documentation
It can modify the input inplace but it will not have effect on forward since ... You can assign the submodules as regular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found