-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnn_fv_32.m
51 lines (46 loc) · 1.61 KB
/
cnn_fv_32.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
%% cnn conv fea multi-scale + fv
clear all;clc;
caffe.reset_all();
caffe.set_mode_gpu();
model_fold = './model/vgg16';
model = prepare_model(model_fold);
net = caffe.Net(model.model_file,model.weights_file,'test');
img_fold = 'R:\qcz\Dataset\Oxford5k\oxbuild_images';
gnd_train = fullfile(img_fold,'../','gnd_oxford5k.mat');
gnd_test = fullfile(img_fold,'../','gnd_oxford5k.mat');
gnd_train = load(gnd_train);
gnd_test = load(gnd_test);
try
load('data_oxford_conv5_3.mat');
catch
img_list = gnd_train.imlist;
data = cell(length(img_list),1);
for ind = 1:length(img_list)
img_path = fullfile(img_fold,[img_list{ind},'.jpg']);
[im,scale] = prepare_blob_for_cnn(img_path,model,600);
t1 = clock;
net.blobs('data').reshape([size(im,1),size(im,2),3,1]);
net.reshape();
res = net.forward({im});
t2 = clock();
data{ind} = res{1};
fprintf('%d th img : %s -- time is : %f\n',ind,img_list{ind},etime(t2,t1));
end
save('data_oxford_conv5_3.mat','data','-v7.3');
end
%% reshape + L2 normalization
fprintf('reshape + normalization\n');
data = cellfun(@(x) reshape(x,[],size(x,3)),data,'un',0);
data = cellfun(@(x) vecpostproc(x'),data,'un',0);
%% train fv
gmm_num = 256;
try
load(['gmm_',num2str(gmm_num),'.mat']);
catch
data_gmm = single(cell2mat(data'));
clear data;
fprintf('trainging gmm ---\n');
[means,covariances,priors] = vl_gmm(data_gmm,gmm_num);
save(['gmm_',num2str(gmm_num),'.mat'],'means','covariances','priors','-v7.3');
fprintf('gmm training finished---\n');
end