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

Provided pre-trained load issue #115

Open
Rasoul77 opened this issue Jul 19, 2022 · 3 comments
Open

Provided pre-trained load issue #115

Rasoul77 opened this issue Jul 19, 2022 · 3 comments

Comments

@Rasoul77
Copy link

Rasoul77 commented Jul 19, 2022

I tried to use the provided pre-trained PTH file presented in the Update section using the following code snippet, but it returns errors of missing keys,

import torch
from networks.resnet_big import SupConResNet

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f"device to use: {device}")

model = SupConResNet()
model.to(device=device)
model.load_state_dict(torch.load("./supcon.pth", map_location=device))
model.eval()

which results,

Error(s) in loading state_dict for SupConResNet:
	Missing key(s) in state_dict: "encoder.conv1.weight", "encoder.bn1.weight", ...

Could you clarify for which model the pre-trained "supcon.pth" is provided?

@FraCorti
Copy link

Hi @Rasoul77, by chance did you find a solution?

@FraCorti
Copy link

@Rasoul77 I solved the serialization by creating the ResNet50 model from the old implementation (https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py), changing the first layer kernel size to 7 and deleting the fully connected part and taking only the projection head. The class that represents the network is SupConResNet.

@Khey17
Copy link

Khey17 commented Apr 3, 2023

@Rasoul77 Did you find a solution? I got the same error when i ran main_linear.py.
image

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

3 participants