forked from layumi/2016_person_re-ID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_data.m
executable file
·45 lines (43 loc) · 1.25 KB
/
prepare_data.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
clear;
p = '/home/zzd/re_ID/market1501/bounding_box_train/';
pp = '/home/zzd/re_ID/market1501/bounding_box_train/*.jpg';
pw = '/home/zzd/re_ID/market1501/bounding_box_train_256/';
%mkdir(pw);
imdb.meta.sets=['train','test'];
file = dir(pp);
counter_data=1;
counter_last = 1;
class = 0;
c_last = '';
cc = [];
for i=1:length(file)
url = strcat(p,file(i).name);
im = imread(url);
im = imresize(im,[256,256]); % save 256*256 image in advance for faster IO
url256 = strcat(pw,file(i).name);
imwrite(im,url256);
imdb.images.data(counter_data) = cellstr(url256);
c = strsplit(file(i).name,'_');
if(~isequal(c{1},c_last))
class = class + 1;
fprintf('%d::%d\n',class,counter_data-counter_last);
cc=[cc;counter_data-counter_last];
c_last = c{1};
counter_last = counter_data;
end
imdb.images.label(:,counter_data) = class;
counter_data = counter_data + 1;
end
s = counter_data-1;
imdb.images.set = ones(1,s);
imdb.images.set(:,randi(s,[round(0.1*s),1])) = 2;
% no validation for small class
cc = [cc;9];
cc = cc(2:end);
list = find(imdb.images.set==2);
for i=1:numel(list)
if cc(imdb.images.label(list(i)))<10
imdb.images.set(list(i))=1;
end
end
save('url_data.mat','imdb','-v7.3');