-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscript_experiments_UNIX.m
165 lines (126 loc) · 7.58 KB
/
script_experiments_UNIX.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
153
154
155
156
157
158
159
160
161
162
163
164
165
warning('off','all');
% Datasets names
datasetsNames = {...
'DRIVE' ...
'STARE-A' ...
'STARE-B' ...
'CHASEDB1-B' ...
'CHASEDB1-A' ...
'HRF' ...
};
% Flag indicating if the value of C is going to be tuned according to the
% validation set
learnC = 1;
% CRF versions that are going to be evaluated
crfVersions = {'up','fully-connected'};
% C values
cValue = 10^2;
% Root dir where the data sets are located
rootDatasets = '/home/ignacioorlando/_tmi_experiments/';
% Root folder where the results are going to be stored
rootResults = '/home/ignacioorlando/results-last-all';
% Creating data set paths
datasetsPaths = cell(length(datasetsNames), 1);
for i = 1 : length(datasetsNames)
datasetsPaths{i} = strcat(rootDatasets, datasetsNames{i});
end
% Creating results paths
resultsPaths = cell(length(datasetsNames), 1);
for i = 1 : length(datasetsNames)
resultsPaths{i} = strcat(rootResults, filesep, datasetsNames{i});
end
for experiment = 1 : length(datasetsNames)
for crfver = 1 : length(crfVersions)
% Get the configuration
[config] = getConfiguration_GenericDataset_UNIX(datasetsNames{experiment}, datasetsPaths{experiment}, resultsPaths{experiment}, learnC, crfVersions{crfver}, cValue);
root = config.resultsPath;
% Code name of the expected files
pairwisedeviations = strcat(config.training_data_path, filesep, 'pairwisedeviations.mat');
% Open images, labels and masks on the training set
[trainingdata.images, trainingdata.labels, trainingdata.masks, trainingdata.numberOfPixels] = openLabeledData(config.training_data_path, config.preprocessing);
% Open images, labels and masks for the validation set
[validationdata.images, validationdata.labels, validationdata.masks, validationdata.numberOfPixels] = openLabeledData(config.validation_data_path, config.preprocessing);
% If the pairwise deviation file does not exist
if (exist(pairwisedeviations, 'file')~=2)
% Compute all possible features
[allfeatures, numberOfDeviations] = extractFeaturesFromImages(trainingdata.images, trainingdata.masks, config, ones(size(config.features.numberFeatures)), false);
% Compute pairwise deviations
pairwiseDeviations = getPairwiseDeviations(allfeatures, numberOfDeviations);
% Save pairwise deviations
save(pairwisedeviations, 'pairwiseDeviations');
else
% Load pairwise deviations
load(pairwisedeviations);
end
% Assign precomputed deviations to the param struct
config.features.pairwise.pairwiseDeviations = pairwiseDeviations;
clear 'pairwiseDeviations';
% Extract unary features
fprintf('Computing unary features\n');
% Compute unary features on training data
[trainingdata.unaryFeatures, config.features.unary.unaryDimensionality] = ...
extractFeaturesFromImages(trainingdata.images, ...
trainingdata.masks, ...
config, ...
config.features.unary.unaryFeatures, ...
true);
% Compute unary features on validation data
validationdata.unaryFeatures = extractFeaturesFromImages(validationdata.images, ...
validationdata.masks, ...
config, ...
config.features.unary.unaryFeatures, ...
true);
% Compute pairwise features on training data
% Extract pairwise features
fprintf('Computing pairwise features\n');
[pairwisefeatures, config.features.pairwise.pairwiseDimensionality] = ...
extractFeaturesFromImages(trainingdata.images, ...
trainingdata.masks, ...
config, ...
config.features.pairwise.pairwiseFeatures, ...
false);
config.features.pairwise.pairwiseDeviations = config.features.pairwise.pairwiseDeviations(generateFeatureFilter(config.features.pairwise.pairwiseFeatures, config.features.pairwise.pairwiseFeaturesDimensions));
trainingdata.pairwiseKernels = getPairwiseFeatures(pairwisefeatures, config.features.pairwise.pairwiseDeviations);
% Compute pairwise features on validation data
pairwisefeatures = extractFeaturesFromImages(validationdata.images, ...
validationdata.masks, ...
config, ...
config.features.pairwise.pairwiseFeatures, ...
false);
validationdata.pairwiseKernels = getPairwiseFeatures(pairwisefeatures, config.features.pairwise.pairwiseDeviations);
% Filter the value of theta_p
config.theta_p.finalValues = ...
config.theta_p.values(generateFeatureFilter(config.features.pairwise.pairwiseFeatures, config.features.pairwise.pairwiseFeaturesDimensions));
% Train with this configuration and return the model
[model, config.qualityOverValidation, config] = learnCRFPotentials(config, trainingdata, validationdata);
% Open test data
[testdata.images, testdata.labels, testdata.masks, testdata.numberOfPixels] = openLabeledData(config.test_data_path, config.preprocessing);
% Extract unary features
fprintf(strcat('Computing unary features\n'));
[testdata.unaryFeatures, config.features.unary.unaryDimensionality] = ...
extractFeaturesFromImages(testdata.images, ...
testdata.masks, ...
config, ...
config.features.unary.unaryFeatures, ...
true);
% Extract pairwise features
fprintf(strcat('Computing pairwise features\n'));
[pairwisefeatures, config.features.pairwise.pairwiseDimensionality] = ...
extractFeaturesFromImages(testdata.images, ...
testdata.masks, ...
config, ...
config.features.pairwise.pairwiseFeatures, ...
false);
% Compute the pairwise kernels
fprintf(strcat('Computing pairwise kernels\n'));
testdata.pairwiseKernels = getPairwiseFeatures(pairwisefeatures, config.features.pairwise.pairwiseDeviations);
% Segment test data to evaluate the model
[results.segmentations, results.qualityMeasures] = getBunchSegmentations2(config, testdata, model);
results.table = [results.qualityMeasures.se, results.qualityMeasures.sp, results.qualityMeasures.acc, results.qualityMeasures.precision, results.qualityMeasures.recall, results.qualityMeasures.fMeasure, results.qualityMeasures.matthews];
disp(strcat('Se = ', num2str(mean(results.qualityMeasures.se))));
disp(strcat('Sp = ', num2str(mean(results.qualityMeasures.sp))));
disp(strcat('fMeasure = ', num2str(mean(results.qualityMeasures.fMeasure))));
disp(strcat('matthews = ', num2str(mean(results.qualityMeasures.matthews))));
SaveSegmentations(root, config, results, model);
end
end