Skip to content

Commit 66c1813

Browse files
committed
fixes
1 parent cb4ff6a commit 66c1813

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

clustering/cross_validation/new/cross_validation.m

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
function [ varargout ] = cross_validation( segmentation_configs, labels_path, folds, clusters, output_path, options, graph)
1+
function [ varargout ] = cross_validation( segmentation_configs, labels_path, folds, clusters, output_path, options, graph, varargin)
22
%CROSS_VALIDATION Summary of this function goes here
33
% Detailed explanation goes here
44

5+
WAITBAR = 1;
6+
DISPLAY = 1;
7+
for i = 1:length(varargin)
8+
if isequal(varargin{i},'WAITBAR')
9+
WAITBAR = varargin{i+1};
10+
elseif isequal(varargin{i},'DISPLAY')
11+
DISPLAY = varargin{i+1};
12+
end
13+
end
14+
515
%% INITIALIZATION
616
min_num = clusters(1);
717
max_num = clusters(2);
@@ -48,7 +58,9 @@
4858

4959
idx = 1:classif.nlabels;
5060
%test_set = ones(1, inst.nlabels);
51-
h = waitbar(0,'Loading...','Name','Clustering');
61+
if WAITBAR
62+
h = waitbar(0,'Loading...','Name','Clustering');
63+
end
5264

5365
for i = min_num:step:max_num
5466
nclusters = i;
@@ -57,10 +69,14 @@
5769
% i) two-phase clustering (default)
5870
fn = fullfile(output_path, sprintf('clustering_%d_%s.mat',nclusters,a));
5971
if exist(fn ,'file')
60-
fprintf('\nData for %d number of clusters (two-phase clustering) found. Loading data...\n', nclusters);
72+
if DISPLAY
73+
fprintf('\nData for %d number of clusters (two-phase clustering) found. Loading data...\n', nclusters);
74+
end
6175
load(fn);
62-
else
63-
fprintf('\nData for %d number of clusters (two-phase clustering) not found. Computing...\n', nclusters);
76+
else
77+
if DISPLAY
78+
fprintf('\nData for %d number of clusters (two-phase clustering) not found. Computing...\n', nclusters);
79+
end
6480
[res, res1st] = cross_validation_exe( classif, segmentation_configs, idx, folds, labels_path, nclusters, options, features, LABELLING_MAP, CLASSIFICATION_TAGS, segments);
6581
save(fn, 'res', 'res1st');
6682
end
@@ -72,17 +88,23 @@
7288
% ii) clustering using all the constraints (compute coverate)
7389
fn = fullfile(output_path, sprintf('clustering_all_%d_%s.mat',nclusters,a));
7490
if exist(fn ,'file')
75-
fprintf('\nData for %d number of clusters (two-phase clustering) found. Loading data...\n', nclusters);
91+
if DISPLAY
92+
fprintf('\nData for %d number of clusters (two-phase clustering) found. Loading data...\n', nclusters);
93+
end
7694
load(fn);
7795
else
78-
fprintf('\nData for %d number of clusters (two-phase clustering) not found. Computing...\n', nclusters);
96+
if DISPLAY
97+
fprintf('\nData for %d number of clusters (two-phase clustering) not found. Computing...\n', nclusters);
98+
end
7999
res = classif.cluster(nclusters);
80100
save(fn, 'res');
81101
end
82102
res3 = [res3, res];
83103
covering = [covering, res.coverage(feature_length)];
84104

85-
waitbar(i/max_num);
105+
if WAITBAR
106+
waitbar(i/max_num);
107+
end
86108
end
87109

88110
% remap the classes as to not invalidate mixed clusters
@@ -108,7 +130,9 @@
108130
varargout{5} = res2;
109131
varargout{6} = res3;
110132
varargout{7} = covering;
111-
end
112-
delete(h);
133+
end
134+
if WAITBAR
135+
delete(h);
136+
end
113137

114138
end

demo.m

+23-9
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,37 @@ function demo(set,user_path,varargin)
318318

319319
%% Labelling Quality
320320
if LABELLING_QUALITY
321-
for i = 1:length(seg_overlap)
322-
load(fullfile(project_path,'segmentation',seg_name(i).name));
323-
p = strsplit(files(i).name,'.mat');
321+
labs = dir(fullfile(project_path,'labels','*.mat'));
322+
segs = dir(fullfile(project_path,'segmentation','*.mat'));
323+
for i = 1:length(labs)
324+
[~,len,ovl,~,~] = split_labels_name(labs(i).name);
325+
if isequal(len,'0') || isequal(ovl,'0')
326+
continue
327+
end
328+
p = strsplit(labs(i).name,'.mat');
324329
p = p{1};
325330
output_path = char(fullfile(project_path,'labels',strcat(p,'_check')));
326331
if ~exist(output_path,'dir')
327332
mkdir(output_path);
328333
end
329-
[nc,res1bare,res2bare,res1,res2,res3,covering] = results_clustering_parameters(segmentation_configs,fullfile(project_path,'labels',lab_name(i).name),0,output_path,10,100,10,'WAITBAR', WAITBAR, 'DISPLAY', DISPLAY);
334+
for s = 1:length(segs)
335+
seg = fullfile(project_path,'segmentation',segs(s).name);
336+
[~,~,sl,so] = split_segmentation_name(seg);
337+
if isequal(sl,len) && isequal(so,ovl)
338+
load(fullfile(project_path,'segmentation',segs(s).name));
339+
break;
340+
end
341+
end
342+
mkdir(output_path);
343+
[nc,res1bare,res2bare,res1,res2,res3,covering] = cross_validation(segmentation_configs,fullfile(project_path,'labels',labs(i).name),10,[10,100,10],output_path,'labels',0,'WAITBAR', WAITBAR, 'DISPLAY', DISPLAY);
344+
[nc,per_errors1,per_undefined1,coverage,per_errors1_true] = algorithm_statistics(1,1,nc,res1bare,res2bare,res1,res2,res3,covering);
345+
data = [nc', per_errors1', per_undefined1', coverage', per_errors1_true'];
346+
% export results to CSV file
347+
export_num_of_clusters(output_path,data);
330348
output_path = char(fullfile(project_path,'results',strcat(p,'_cross_validation')));
331-
if exist(output_path,'dir');
349+
if exist(output_path,'dir')
332350
rmdir(output_path,'s');
333351
end
334-
mkdir(output_path);
335-
[nc,per_errors1,per_undefined1,coverage] = algorithm_statistics(1,1,nc,res1bare,res2bare,res1,res2,res3,covering);
336-
data = [nc', per_errors1', per_undefined1', coverage'];
337-
% export results to CSV file
338352
export_num_of_clusters(output_path,data);
339353
% generate graphs
340354
results_clustering_parameters_graphs(output_path,nc,res1bare,res2bare,res1,res2,res3,covering);

0 commit comments

Comments
 (0)