Download the CLEAR-10/-100 Trainset & Unlabeled Metadata.
Run the below Python script in the downloaded folder.
Folder Structure Preview:
root/
| class_names.txt (each line is a class name)
| labeled_metadata.json (with paths to labeled images' metadata)
| all_metadata.json (with paths to all images' metadata)
| download_all_images.py (for downloading unlabeled images)
ββββlabeled_images
| ββββ1
| | ββββcomputer
| | | | 235821044.jpg
| | | | ...
| | ββββcamera
| | | | 269400202.jpg
| | | | ...
| | ββββ...
| ββββ2
| ββββ...
ββββlabeled_metadata
| ββββ1
| | | computer.json (dict: key is flickr ID, value is metadata)
| | | camera.json
| | | ...
| ββββ2
| ββββ...
ββββall_metadata
β β 0.json
| | 1.json
| | ...
ββββfeatures
| ββββmoco_b0
| | | features.json (with paths to labeled images' features files)
| | | state_dict.pth.tar (a copy of the state_dict file)
| | ββββ1
| | | | computer.pth (dict: key is flickr ID, value is torch tensor)
| | | | camera.pth
| | | | ...
| | ββββ2
| | | | ...
| | ββββ...
Loading the pre-trained MoCo model on 0th bucket
Here is a short example script for loading the state_dict.pth.tar under features/moco_b0 folder:
'''
Load pretrain model for image features
'''
import torch
from torchvision.models import resnet50
def load_model(state_dict_path='./features/moco_b0/state_dict.pth.tar'):
model = resnet50(pretrained=False)
model.fc = torch.nn.Identity()
state_dict = torch.load(state_dict_path)
model.load_state_dict(state_dict)
for p in model.parameters():
p.requires_grad= False
model.eval()
return model
Good to know: You can also download CLEAR-10 / CLEAR-100 on Avalanche with a few lines of code!