|
| 1 | +function cifar_eval( trn_list, trn_label, trn_binary, tst_list, tst_label, tst_binary) |
| 2 | +K = 1000; |
| 3 | +fid = fopen('log_cifar10.txt', 'wt'); |
| 4 | + |
| 5 | +correct = zeros(K,1); |
| 6 | +total = zeros(K,1); |
| 7 | +error = zeros(K,1); |
| 8 | + |
| 9 | +for i = 1:10000 |
| 10 | + |
| 11 | + img_path = tst_list(i,1); |
| 12 | + query_label = get_label(img_path, tst_label); |
| 13 | + fprintf('query %d\n',i); |
| 14 | + query_binary = tst_binary(:,i); |
| 15 | + |
| 16 | + tic |
| 17 | + similarity = pdist2(trn_binary',query_binary','hamming'); |
| 18 | + toc |
| 19 | + fprintf('Complete Query [Euclidean] %.2f seconds\n',toc); |
| 20 | + |
| 21 | + [x2,y2]=sort(similarity); |
| 22 | + |
| 23 | + |
| 24 | + buffer_yes = zeros(K,1); |
| 25 | + buffer_total = zeros(K,1); |
| 26 | + |
| 27 | + for j = 1:K |
| 28 | + filename = trn_list(y2(j),1); |
| 29 | + retrieval_label = get_label(filename,trn_label); |
| 30 | + |
| 31 | + if (query_label==retrieval_label) |
| 32 | + buffer_yes(j,1) = 1; |
| 33 | + end |
| 34 | + buffer_total(j,1) = 1; |
| 35 | + |
| 36 | + end |
| 37 | + |
| 38 | + for j = 1:K |
| 39 | + for kk = 1:j |
| 40 | + correct(j,1) = correct(j,1) + buffer_yes(kk,1); |
| 41 | + total(j,1) = total(j,1) + buffer_total(kk,1); |
| 42 | + end |
| 43 | + end |
| 44 | +end |
| 45 | + accuracy = correct./total; |
| 46 | + plot(1:K,accuracy); |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +for i = 1:K |
| 51 | + fprintf(fid, '%d %f\n',i,correct(i,1)/total(i,1)); |
| 52 | +end |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +fclose(fid); |
| 57 | + |
| 58 | + |
| 59 | +end |
| 60 | + |
| 61 | + |
| 62 | +function [label_output] = get_label(img_path, labels) |
| 63 | + image_filename = regexp(img_path{1}, '/', 'split'); |
| 64 | + str0 = image_filename(6); |
| 65 | + |
| 66 | + base = 0; |
| 67 | + if (strcmp(str0,'test')==1) |
| 68 | + base = 0; |
| 69 | + end |
| 70 | + if (strcmp(str0,'batch1')==1) |
| 71 | + base = 0; |
| 72 | + end |
| 73 | + if (strcmp(str0,'batch2')==1) |
| 74 | + base = 10000; |
| 75 | + end |
| 76 | + if (strcmp(str0,'batch3')==1) |
| 77 | + base = 20000; |
| 78 | + end |
| 79 | + if (strcmp(str0,'batch4')==1) |
| 80 | + base = 30000; |
| 81 | + end |
| 82 | + if (strcmp(str0,'batch5')==1) |
| 83 | + base = 40000; |
| 84 | + end |
| 85 | + |
| 86 | + str1 = image_filename(7); |
| 87 | + str2 = str1{1}(1:end-4);%without '.jpg' |
| 88 | + x = str2num(str2); |
| 89 | + label_output = labels(x+base); |
| 90 | + |
| 91 | +end |
| 92 | + |
0 commit comments