-
Notifications
You must be signed in to change notification settings - Fork 3
/
SplitDataset.m
executable file
·84 lines (63 loc) · 2.63 KB
/
SplitDataset.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
function Dataset = SplitDataset(Dataset, train_idx, test_idx, prefix, suffix)
% function Dataset = SplitDataset(Dataset, train_idx, test_idx, prefix, suffix)
%
% Splits dataset into training and test (fills nesessary feilds and
% rearranges the files accordingly
%
% Input:
% Dataset = initial (not split) dataset structure
% train_idx = indices of training images
% test_idx = indices of test images
% prefix = all files used in MIM will start with prefix - use for
% specifying the folder, e.t.c.
% suffix = all files used in MIM will end with suffix - use to store
% different experiments
% Alexander Vezhnevets, 2012
Dataset.TrainImageIdx = 1: length(train_idx);
Dataset.TestImageIdx = length(train_idx) + 1 : length(train_idx) + length(test_idx);
load (Dataset.SpIndexFile);
load(Dataset.ImageIndexFile)
Images_spDB = Images_spDB([train_idx test_idx]);
ImagesDB = ImagesDB([train_idx test_idx]);
load (Dataset.labelsFile);
load (Dataset.featuresFile);
load (Dataset.objectnessFile);
new_offset = 0;
% old_features = features;
% old_OP_mtx = OP_mtx;
% old_OP = OP;
% old_Labels = Labels;
% Labels = Labels * 0 -1;
remix = zeros(1,size(Features,1));
for i = 1 : length(Images_spDB)
cur_imsp_idx = 1 + Images_spDB{i}.offset : Images_spDB{i}.offset + Images_spDB{i}.SpNum;
new_imsp_idx = new_offset + 1 : new_offset + Images_spDB{i}.SpNum;
Images_spDB{i}.offset = new_offset;
new_offset = new_offset + Images_spDB{i}.SpNum;
remix(new_imsp_idx) = cur_imsp_idx;
end
Features = Features(remix,:);
OP_mtx = OP_mtx(remix,:);
%OP = OP(remix);
Labels = Labels(remix);
tr_end = Images_spDB{length(train_idx)+1}.offset;
Dataset.labelsTrainFile = [prefix 'labels_train' suffix];
Dataset.labelsFile = [prefix 'labels_test' suffix];
save(Dataset.labelsFile, 'Labels');
Labels = Labels(1:tr_end);
save(Dataset.labelsTrainFile, 'Labels');
Dataset.featuresTrainFile = [prefix 'features_train' suffix];
Dataset.featuresFile = [prefix 'features_test' suffix];
save(Dataset.featuresFile, 'Features');
Features = Features(1:tr_end,:);
save(Dataset.featuresTrainFile, 'Features');
Dataset.objectnessTrainFile = [prefix 'objectness_train' suffix];
Dataset.objectnessFile = [prefix 'objectness_test' suffix];
save(Dataset.objectnessFile, 'OP_mtx');%, 'OP');
OP_mtx = OP_mtx(1:tr_end,:);
OP = OP(1:tr_end);
save(Dataset.objectnessTrainFile, 'OP_mtx');%, 'OP');
Dataset.SpIndexFile = [prefix 'sp_db' suffix];
save(Dataset.SpIndexFile, 'Images_spDB', 'TotalSP');
Dataset.ImageIndexFile = [prefix 'images_db' suffix];
save(Dataset.ImageIndexFile, 'ImagesDB');