forked from kevinlisun/clothes_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a4_local_features_llc.m
153 lines (131 loc) · 4.69 KB
/
a4_local_features_llc.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
warning off
clear all
close all
clc
flag = true;
para.bsp = 1;
para.finddd = 0;
para.lbp = 0;
para.sc = 0;
para.dlcm = 0;
para.sift = 0;
is_norm = 1;
addpath('./BSplineFitting');
addpath('./LLC');
addpath('./SurfaceFeature');
addpath('./Functions');
addpath('./FINDDD');
addpath(genpath([pwd,'/GPML']));
addpath('./ShapeContent');
addpath('./Utilities');
addpath('./vlfeat/toolbox');
vl_setup
startup
%% script setting
% the file is start with date to distinguish
flile_header = 'clothes_dataset_RH';
%create firectory
dataset_dir = ['~/',flile_header];
current_dir='~/bags';
category = 'towel';
size_class=3;
size_move=12;
% clothes is the number of flattening experiments, n_iteration is the
% number of flattening iteration in each experiment [1:7,10:12,15:16]
clothes = [1:50];
captures = 0:20;
kofkmeans = 256;
coding_opt = 'LLC'
pooling_opt = 'sum'
knn = 5
%% read code book
codebook_dir = [current_dir,'/Features/'];
load([codebook_dir,'code_book',num2str(kofkmeans),'.mat']);
%% main loop
for iter_j = 1:size_class
for iter_k = 1:size_move
name_file = [current_dir,'/Features/local_descriptors_' category int2str(iter_j) '_move' int2str(iter_k)]
if exist([name_file '.mat'],'file')
load([name_file '.mat']);
for iter_i = 1:length(allfeatures_local)
local_descriptors = allfeatures_local(iter_i);
% for iter_i = 1:length(clothes)
% clothes_i = clothes(iter_i);
% disp(['start read descriptors of clothes id: ', num2str(clothes_i), ' ...']);
% if clothes_i < 10
% current_dir = strcat(dataset_dir,'/0',num2str(clothes_i),'/');
% else
% current_dir = strcat(dataset_dir,'/',num2str(clothes_i),'/');
% end
% % feature extraction
% for iter_j = 1:length(captures)
% capture_i = captures(iter_j);
% % read features from the disk
% featureFile = strcat(current_dir,'Features/local_descriptors_capture',num2str(capture_i),'.mat');
% if ~exist(featureFile,'file')
% continue;
% end
% load(featureFile);
%% coding
if para.bsp
if strcmp(coding_opt,'BOW')
[ code.bsp ] = Coding( local_descriptors.bsp, code_book.bsp, is_norm );
end
if strcmp(coding_opt,'LLC')
code.bsp = LLC_pooling( local_descriptors.bsp, code_book.bsp, code_book.bsp_weights, knn, pooling_opt );
end
allfeatures_local(iter_i).dscr_bsp = code.bsp;
end
if para.finddd
if strcmp(coding_opt,'BOW')
[ code.finddd ] = Coding( local_descriptors.finddd, code_book.finddd, is_norm );
end
if strcmp(coding_opt,'LLC')
code.finddd = LLC_pooling( local_descriptors.finddd, code_book.finddd, code_book.bsp_weights, knn, pooling_opt );
end
end
if para.lbp
if strcmp(coding_opt,'BOW')
[ code.lbp ] = Coding( local_descriptors.lbp, code_book.lbp, is_norm );
end
if strcmp(coding_opt,'LLC')
code.lbp = LLC_pooling( local_descriptors.lbp, code_book.lbp,code_book.bsp_weights, knn, pooling_opt );
end
end
if para.sc
if strcmp(coding_opt,'BOW')
[ code.sc ] = Coding( local_descriptors.sc, code_book.sc, is_norm );
end
if strcmp(coding_opt,'LLC')
code.sc = LLC_pooling( local_descriptors.sc, code_book.sc, code_book.bsp_weights, knn, pooling_opt );
end
end
if para.dlcm
if strcmp(coding_opt,'BOW')
[ code.dlcm ] = Coding( local_descriptors.dlcm, code_book.dlcm, is_norm );
end
if strcmp(coding_opt,'LLC')
code.dlcm = LLC_pooling( local_descriptors.dlcm, code_book.dlcm, code_book.bsp_weights, knn, pooling_opt );
end
end
if para.sift
if strcmp(coding_opt,'BOW')
[ code.sift ] = Coding( local_descriptors.sift, code_book.sift, is_norm );
end
if strcmp(coding_opt,'LLC')
code.sift = LLC_pooling( local_descriptors.sift, code_book.sift, code_book.bsp_weights, knn, pooling_opt );
end
end
% code_dir = [ current_dir, 'Codes' ];
% if ~exist(code_dir,'dir')
% mkdir(code_dir);
% end
% save([code_dir,'/',coding_opt,'_codes_capture',num2str(capture_i),'.mat'],'code')
% clear code;
end
save([current_dir,'/Features/local_descriptors_' category int2str(iter_j) '_move' int2str(iter_k) '.mat'],'allfeatures_local');
end
%%
% disp(['fininsh coding of clothing ', num2str(clothes_i), ' ...']);
end
end