xyupeng / ContrastiveCrop

[CVPR 2022 Oral] Crafting Better Contrastive Views for Siamese Representation Learning
MIT License
284 stars 27 forks source link

KeyError in SimCLR linear classification #1

Closed JiarunLiu closed 2 years ago

JiarunLiu commented 2 years ago

Hi, Thanks for your amazing work.

I got the following error when i trying to run the linear classification experiment of SimCLR:

Command:

python DDP_linear.py configs/linear/cifar10_res18.py --load ./checkpoints/small/cifar10/simclr_alpha0.1_th0.1/last.pth

Error:

  File "/home/futong/jiarunliu/ContrastiveCrop/DDP_linear.py", line 276, in main_worker
    load_weights(cfg.load, model, optimizer, resume=False)
  File "/home/futong/jiarunliu/ContrastiveCrop/DDP_linear.py", line 107, in load_weights
    for k, v in state_dict.items():
UnboundLocalError: local variable 'state_dict' referenced before assignment

And I have checked the aviaible keys in SimCLR's checkpoint:

>>> ckpt = torch.load("checkpoints/small/cifar10/simclr_alpha0.1_th0.1/last.pth", map_location='cpu')
>>> ckpt.keys()
dict_keys(['optimizer_state', 'simclr_state', 'boxes', 'epoch'])

Maybe you should consider change the key here? https://github.com/xyupeng/ContrastiveCrop/blob/dab4100839972ecab0c864256d397867260e76a8/DDP_linear.py#L84-L85

xyupeng commented 2 years ago

Hi jiarun, Yes you are right. Thank you for pointing it out. I have fixed the bug.