facebookresearch / vissl

VISSL is FAIR's library of extensible, modular and scalable components for SOTA Self-Supervised Learning with images.
https://vissl.ai
MIT License
3.26k stars 334 forks source link

How to get image names from idx of features extracted? #401

Closed DC95 closed 3 years ago

DC95 commented 3 years ago

❓ How to get names of images from idx of features extracted?

Dear @QuentinDuval

Introduction - For evaluation of the Deepcluster_V2 model, I have tried the benchmark of KNN to analyze few samples from the test images which belong nearest to the train images. Since I am not operating on labelled or class dataset (top1 or top5 is irreleveant here). Therefore I am interested in collecting the top - k neighbours which I think is up to line 70 of nearest_neighbour_test.py

Output - The variable "retreived_neighbours" from nearest_neighbour_test.py gives k indices of the train image set nearest to the test image.

  1. for example top 5 neighbours for a test image - tensor([[ 2, 228, 11803, 13161, 1],], device='cuda:0')

Question - But I am not able to figure out how to get the image names from this?

Please note - I followed the answer of @prigoyal from #340. But could not understand or relate much

regards, DC

QuentinDuval commented 3 years ago

Hi @DC95,

The indices should correspond to the indices of the dataset, which means that you should be able to get the images like this: dataset[index]. This is used in the context of Cluster Fit if applied on an image folder.

One way to do this would be to use the function "get_image_paths": https://github.com/facebookresearch/vissl/blob/master/tools/cluster_features_and_label.py#L50

image_paths = get_image_paths(config, split="train")
for idx in [2, 228, 11803, 13161, 1]:
    print(image_paths[idx])

Could you tell me if that works for you? If so, we can make this function more easily available.

And thank you again @DC95 for using VISSL :) Quentin

DC95 commented 3 years ago

Dear @QuentinDuval

Thanks for the idea. Yes, it worked. We need to bring some more changes in the nearest_neighbour_test.py to get it done.

  1. from vissl.data import build_dataset
  2. under the main function after line 124 call the get_image_paths function
    image_paths = get_image_paths(config, split="TRAIN")
    for idx in [2, 228, 11803, 13161, 1]:   # as thrown by retrieved neighbour variable.
    print(image_paths[idx])

Thanks again, and I will keep knocking on the issue door in the future.

Regards, DC

QuentinDuval commented 3 years ago

Hi @DC95,

Excellent, I am very glad it worked :)

CC: @prigoyal, @iseessel : I think we can make that simpler on our side and add some utilities to do so.

Closing the issue.