xyupeng / ContrastiveCrop

[CVPR 2022 Oral] Crafting Better Contrastive Views for Siamese Representation Learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError in SimCLR linear classification

JiarunLiu opened this issue · comments

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?

if 'model_state' in ckpt.keys(): # simclr
state_dict = ckpt['model_state']

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