lucidrains/byol-pytorch

Can't load ckpt

AndrewTal opened this issue · 4 comments

I use byol-pytorch-master/examples/lightning/train.py to generate ckpt locally after training, but when I load ckpt, there will be the following errors. How should I load it? Thanks a lot!
截屏2020-11-18 上午12 51 48

I tried this and it seemed okay, I don't know if it is correct.
截屏2020-11-18 下午12 19 15

At the same time, the resnet parameters have also changed. Is the ResNet model saved in this way correct?

yes, ckpt['state_dict'] saves the model's parameters. The way that pytorch lightning load checkpoint is different from pytorch, you should try the following code instead:

from torchvision import models
resnet = models.resnet50(pretrained=False)
cfg = dict(
    net=resnet,
    image_size = 256,
    hidden_layer = 'avgpool',
    projection_size = 256,
    projection_hidden_size = 4096,
    moving_average_decay = 0.99
)
model = SelfSupervisedLearner.load_from_checkpoint(
            'lightning_logs/version_1/checkpoints/epoch=127.ckpt', **cfg
          )

model = SelfSupervisedLearner.load_from_checkpoint(
'lightning_logs/version_1/checkpoints/epoch=127.ckpt', **cfg
)

when I tried this, I got another issue:" TypeError: load_from_checkpoint() got an unexpected keyword argument 'net'"

model = SelfSupervisedLearner.load_from_checkpoint(
'lightning_logs/version_1/checkpoints/epoch=127.ckpt', **cfg
)

when I tried this, I got another issue:" TypeError: load_from_checkpoint() got an unexpected keyword argument 'net'"

yes, I got this issue too.