-
Notifications
You must be signed in to change notification settings - Fork 218
/
run_cifar10.m
66 lines (53 loc) · 2.13 KB
/
run_cifar10.m
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
close all;
clear;
% -- settings start here ---
% set 1 to use gpu, and 0 to use cpu
use_gpu = 1;
% top K returned images
top_k = 1000;
feat_len = 48;
% set result folder
result_folder = './analysis';
% models
model_file = './examples/cvprw15-cifar10/KevinNet_CIFAR10_48.caffemodel';
% model definition
model_def_file = './examples/cvprw15-cifar10/KevinNet_CIFAR10_48_deploy.prototxt';
% train-test
test_file_list = './examples/cvprw15-cifar10/dataset/test-file-list.txt';
test_label_file = './examples/cvprw15-cifar10/dataset/test-label.txt';
train_file_list = './examples/cvprw15-cifar10/dataset/train-file-list.txt';
train_label_file = './examples/cvprw15-cifar10/dataset/train-label.txt';
% --- settings end here ---
% outputs
feat_test_file = sprintf('%s/feat-test.mat', result_folder);
feat_train_file = sprintf('%s/feat-train.mat', result_folder);
binary_test_file = sprintf('%s/binary-test.mat', result_folder);
binary_train_file = sprintf('%s/binary-train.mat', result_folder);
% map and precision outputs
map_file = sprintf('%s/map.txt', result_folder);
precision_file = sprintf('%s/precision-at-k.txt', result_folder);
% feature extraction- test set
if exist(binary_test_file, 'file') ~= 0
load(binary_test_file);
else
[feat_test , list_im_test] = matcaffe_batch_feat(test_file_list, use_gpu, feat_len, model_def_file, model_file);
save(feat_test_file, 'feat_test', '-v7.3');
binary_test = (feat_test>0.5);
save(binary_test_file,'binary_test','-v7.3');
end
% feature extraction- training set
if exist(binary_train_file, 'file') ~= 0
load(binary_train_file);
else
[feat_train , list_im_train] = matcaffe_batch_feat(train_file_list, use_gpu, feat_len, model_def_file, model_file);
save(feat_train_file, 'feat_train', '-v7.3');
binary_train = (feat_train>0.5);
save(binary_train_file,'binary_train','-v7.3');
end
trn_label = load(train_label_file);
tst_label = load(test_label_file);
[map, precision_at_k] = precision( trn_label, binary_train, tst_label, binary_test, top_k, 1);
fprintf('MAP = %f\n',map);
save(map_file, 'map', '-ascii');
P = [[1:1:top_k]' precision_at_k'];
save(precision_file, 'P', '-ascii');