Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

size mismatch for weights and bias #104

Open
gwyy-mh opened this issue Dec 14, 2019 · 4 comments
Open

size mismatch for weights and bias #104

gwyy-mh opened this issue Dec 14, 2019 · 4 comments

Comments

@gwyy-mh
Copy link

gwyy-mh commented Dec 14, 2019

I downloaded the bn_inception pth file, and train, but error occurs that : Runtime error size mismatch for conv1_7x7_s2_bn.weight copying a param with shape for torch.Size([1, 64]) from checkpoint, the shape in current model is torch.Size([64]). I am a new person in this field, so I don't know how to deal with it.

@quanh1990
Copy link

I downloaded the bn_inception pth file, and train, but error occurs that : Runtime error size mismatch for conv1_7x7_s2_bn.weight copying a param with shape for torch.Size([1, 64]) from checkpoint, the shape in current model is torch.Size([64]). I am a new person in this field, so I don't know how to deal with it.

Hello, I met the same problem as you and I sloved it using command as follows

pip install torch==0.3.1 torchvision==0.2.1

you can try

@dandingol03
Copy link

@quanh1990 hi, can you share the link of bn_inception pre-trained model with me? thanks

@zaidbhat1234
Copy link

@gwyy-mh and @quanh1990 Can you please share the link of the bn_inception pth file pre-trained model?

@mxl1990
Copy link

mxl1990 commented Jul 28, 2022

For higher version pytorch > 0.3.1,you can change code to convert checkpoint to avoid this error.
For example, you chose BNInception, so find tf_model_zoo\bninception\pytorch_load.py code in init function
state_dict = torch.utils.model_zoo.load_url(weight_url) state_dict = self.convert_state_dict(state_dict) self.load_state_dict(state_dict)
then add a function after init function
def convert_state_dict(self, state_dict): cv_state_dict = {} for key in state_dict: current_tensor = state_dict[key] # print(current_tensor.dim()) if current_tensor.dim() == 2: cv_state_dict[key] = current_tensor.squeeze() else: cv_state_dict[key] = current_tensor return cv_state_dict
then can solve this with higher version pytorch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants