-
Notifications
You must be signed in to change notification settings - Fork 0
/
ametrics.py
78 lines (61 loc) · 2.38 KB
/
ametrics.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from image import *
import os
def calc_precision_single_query(resultados, classname):
p = 0
for chave in resultados:
if classname in chave:
p += 1
precision = p / len(resultados)
return precision
import json
def mock_json(resultados, classname, tecnica):
jsonn = []
for arq in resultados:
if classname in arq:
jsonn.append({'img': arq, 'relevant': True, 'irrelevant': False })
else:
jsonn.append({'img': arq, 'relevant': False, 'irrelevant': True })
jsonn.append({'classname': classname})
jsonn.append({'tecnica': tecnica})
return jsonn
def collect_cbir(tecnica):
cont = 0
avg_geral = []
print(f"START {tecnica}")
avg_classes = {'Hors':[], 'Food':[], 'Dino':[], 'Moun':[], 'Elep':[], 'Afri':[], 'Beac':[], 'Buse':[], 'Buil':[], 'Flow':[]}
with open(f'single_results_{tecnica}ox.txt', 'a') as arquivo:
for fil in os.listdir('oxfordflowers'):
print(f"ARQUIVO {fil}")
avg_file = []
cbir = CBIR()
hists = cbir.run_process(f'oxfordflowers/{fil}')
avg_file.append(calc_precision_single_query(hists, "Flow"))
for i in range(4):
jsonn = mock_json(hists, "Flow", tecnica)
tecnica = jsonn.pop()['tecnica']
nomeclasse = jsonn.pop()['classname']
if tecnica == "qpm":
hists = cbir.refilter_imgs(jsonn)
elif tecnica == "multiquery":
hists = cbir.multiple_query_point_search(jsonn)
elif tecnica == "rfra":
hists = cbir.rfra(jsonn)
avg_file.append(calc_precision_single_query(hists, "Flow"))
print(avg_file)
arquivo.write(fil + ':' + str(avg_file) + '\n')
avg_geral.append((fil, np.mean(avg_file)))
cont += 1
for tup in avg_geral:
fil = tup[0][:4]
avg_classes["Flow"].append(tup[1])
with open('resultsox.txt', 'a') as f:
f.write(tecnica + "\n")
for classe in avg_classes:
avg_classes[classe] = np.mean(avg_classes[classe])
f.write(classe + ':' + str(avg_classes[classe])+'\n')
f.write("\n")
print(avg_geral)
print(avg_classes)
# collect_cbir("qpm")
collect_cbir("multiquery")
collect_cbir("rfra")