-
Notifications
You must be signed in to change notification settings - Fork 18
/
create_sublist.m
42 lines (39 loc) · 1.47 KB
/
create_sublist.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
list = 'list.txt';
list_fid = fopen(list,'r');
C = textscan(list_fid,'%s %d %d %d');
fclose(list_fid);
folder_map = containers.Map;
person_id = zeros(length(C{1}),1);
for i=1:length(C{1})
path_split = strsplit(C{1}{i},{'\','/'});
if ~isKey(folder_map,path_split{1})
folder_map(path_split{1}) = length(folder_map.keys) + 1;
end;
person_id(i) = folder_map(path_split{1});
end;
subfolder = 'sublist';
if exist(subfolder,'dir')==0
mkdir(subfolder);
end;
total_person = max(person_id);
for p = 1:total_person
disp(p);
if exist(fullfile(subfolder,num2str(p)),'dir')==0
mkdir(fullfile(subfolder,num2str(p)));
end;
list_train = fopen(fullfile(subfolder,num2str(p),'list_train.txt'),'w');
list_val = fopen(fullfile(subfolder,num2str(p),'list_val.txt'),'w');
for i=1:length(C{1})
if person_id(i) == p
fprintf(list_val, '%s %d %d %d\r\n', C{1}{i}, C{2}(i), C{3}(i), C{4}(i));
else
fprintf(list_train, '%s %d %d %d\r\n', C{1}{i}, C{2}(i), C{3}(i), C{4}(i));
end;
end;
fclose(list_train);
fclose(list_val);
resample_train_list(fullfile(subfolder,num2str(p),'list_train.txt'), fullfile(subfolder,num2str(p),'list_train_resample.txt'), 3);
% add_balance_weight(fullfile(subfolder,num2str(p),'list_train.txt'), 2, 3);
% add_balance_weight(fullfile(subfolder,num2str(p),'list_val.txt'), 2, 3);
% add_balance_weight(fullfile(subfolder,num2str(p),'list_train_resample.txt'), 2, 3);
end;