self-supervised-histopathology icon indicating copy to clipboard operation
self-supervised-histopathology copied to clipboard

Differences in models

Open lesolorzanov opened this issue 8 months ago • 0 comments

Hello. I've been using your model weights and it was all working fine a couple years ago. I was trying today and I was getting weird results and I noticed that your model's state_dict has weights for layers 'fc.1.bias', 'fc.1.weight', 'fc.3.bias', 'fc.3.weight' while the resnet definition I am using today as of 2024 contains only 'fc.bias', 'fc.weight'. I am assuming this is why it wasn't working.

While I can override and create those last fc layers, I was wondering if there is any "fc2" that existed before? I wonder if it would have been possible to put here the definition of the model, since pytorch themselves may and indeed seem to have changed the definition of the model.


model = torchvision.models.__dict__['resnet18'](pretrained=False)
model_dict = model.state_dict()
model_dict["fc.weight"].shape
> torch.Size([1000, 512])

MODEL_PATH = "pretrained_models/tenpercent_resnet18.ckpt"
state = torch.load(MODEL_PATH, map_location='cuda:0')
state_dict = state['state_dict']

for k in ['fc.1.weight', 'fc.1.bias', 'fc.3.weight', 'fc.3.bias']:
    print(state_dict[k].shape)

> torch.Size([512, 512])
> torch.Size([512])
> torch.Size([128, 512])
> torch.Size([128])


torchvision.__version__
> '0.8.2'
torch.__version__
> '1.7.1'
sys.version
> '3.6.10 | packaged by conda-forge | (default, Apr 24 2020, 16:44:11) \n[GCC 7.3.0]'

lesolorzanov avatar Jun 22 '24 14:06 lesolorzanov