facebookresearch/swav

Evaluate on custom dataset

daniiki opened this issue · 4 comments

Hi, how can you evaluate different models on a custom dataset?

Hi,
You will need to adapt this class to your own dataset:

class MultiCropDataset(datasets.ImageFolder):
def __init__(
self,
data_path,
size_crops,
nmb_crops,
min_scale_crops,
max_scale_crops,
size_dataset=-1,
return_index=False,
):
super(MultiCropDataset, self).__init__(data_path)
assert len(size_crops) == len(nmb_crops)
assert len(min_scale_crops) == len(nmb_crops)
assert len(max_scale_crops) == len(nmb_crops)
if size_dataset >= 0:
self.samples = self.samples[:size_dataset]
self.return_index = return_index
trans = []
color_transform = transforms.Compose([get_color_distortion(), RandomGaussianBlur()])
mean = [0.485, 0.456, 0.406]
std = [0.228, 0.224, 0.225]
for i in range(len(size_crops)):
randomresizedcrop = transforms.RandomResizedCrop(
size_crops[i],
scale=(min_scale_crops[i], max_scale_crops[i]),
)
trans.extend([transforms.Compose([
randomresizedcrop,
transforms.RandomHorizontalFlip(p=0.5),
color_transform,
transforms.ToTensor(),
transforms.Normalize(mean=mean, std=std)])
] * nmb_crops[i])
self.trans = trans
def __getitem__(self, index):
path, _ = self.samples[index]
image = self.loader(path)
multi_crops = list(map(lambda trans: trans(image), self.trans))
if self.return_index:
return index, multi_crops
return multi_crops

Hi again,
thanks for answering! Is there a way to use a pretrained model on deepclusteringv2 and evaluate on your own dataset. I want to test how good the clustering results are on my custom dataset without finetuning/training?
I know that you provide two deepclusteringv2 pretrained models, but which file to use for testing?

I think you should use the best deepcluster-v2 model, that is https://dl.fbaipublicfiles.com/deepcluster/deepclusterv2_800ep_pretrain.pth.tar

Closing for no activity - feel free to reopen the issue if you still need assistance.