-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore_neighbors.py
55 lines (38 loc) · 1.28 KB
/
explore_neighbors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 24 13:57:01 2022
@author: cyrilvallez
"""
import os
from helpers import utils
from fast_search import search
algorithm = 'SimCLR v2 ResNet50 2x'
# algorithm = 'Dhash 64 bits'
# main_dataset = 'BSDS500_original'
main_dataset = 'Kaggle_templates'
distractor_dataset = 'Flickr500K'
# query_dataset = 'BSDS500_attacks'
query_dataset = 'Kaggle_memes'
save_folder = 'SimCLR_memes'
metric = 'L2'
save_folder = 'Neighbors/' + save_folder + '/'
factory_str = 'Flat'
experiment = search.Experiment(algorithm, main_dataset, query_dataset,
distractor_dataset=distractor_dataset)
experiment.set_index(factory_str, metric=metric)
experiment.to_gpu()
experiment.fit(k=10)
_, correct = experiment.recall()
if save_folder[-1] != '/':
save_folder = '/'
os.makedirs(save_folder, exist_ok=True)
os.makedirs(save_folder + 'Correct', exist_ok=True)
os.makedirs(save_folder + 'Incorrect', exist_ok=True)
for index, status in enumerate(correct):
images = experiment.get_neighbors_of_query(index)
neighbors = utils.concatenate_images(images)
if status == 1:
neighbors.save(save_folder + f'Correct/{index}.png')
elif status == 0:
neighbors.save(save_folder + f'Incorrect/{index}.png')