/
Evaluate.py
671 lines (545 loc) · 34.2 KB
/
Evaluate.py
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
#!/usr/bin/env python
# Copyright 2016-2021 Biomedical Imaging Group Rotterdam, Departments of
# Medical Informatics and Radiology, Erasmus MC, Rotterdam, The Netherlands
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import WORC.addexceptions as WORCexceptions
import fastr
from fastr.api import ResourceLimit
import os
import graphviz
class Evaluate(object):
"""Build a network that evaluates the performance of an estimator."""
def __init__(self, label_type, modus='binary_classification',
scores='percentages',
ensemble_method='top_N',
ensemble_size=100,
parent=None, features=None,
fastr_plugin='LinearExecution',
name='Example'):
"""
Initialize object.
Parameters
----------
network: fastr network, default None
If you input a network, the evaluate network is added
to the existing network.
"""
if parent is not None:
self.parent = parent
self.network = parent.network
self.mode = 'WORC'
self.name = parent.network.id
else:
self.mode = 'StandAlone'
self.fastr_plugin = fastr_plugin
self.name = 'WORC_Evaluate_' + name
self.network = fastr.create_network(id=self.name)
self.fastr_tmpdir = os.path.join(fastr.config.mounts['tmp'], self.name)
self.ensemble_method = ensemble_method
self.ensemble_size = ensemble_size
if features is None and self.mode == 'StandAlone':
raise WORCexceptions.WORCIOError('Either features as input or a WORC network is required for the Evaluate network.')
self.modus = modus
self.features = features
self.label_type = label_type
self.create_network()
def create_network(self):
"""Add evaluate components to network."""
# Create all nodes
if self.modus == 'binary_classification':
self.node_ROC =\
self.network.create_node('worc/PlotROC:1.0', tool_version='1.0',
id='plot_ROC',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
if self.mode == 'StandAlone':
self.node_Estimator =\
self.network.create_node('worc/PlotEstimator:1.0', tool_version='1.0',
id='plot_Estimator',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
self.node_Barchart =\
self.network.create_node('worc/PlotBarchart:1.0',
tool_version='1.0', id='plot_Barchart',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
self.node_Hyperparameters =\
self.network.create_node('worc/PlotHyperparameters:1.0',
tool_version='1.0', id='plot_Hyperparameters',
resources=ResourceLimit(memory='6G'),
step_id='Evaluation')
if 'classification' in self.modus:
self.node_STest =\
self.network.create_node('worc/StatisticalTestFeatures:1.0',
tool_version='1.0',
id='statistical_test_features',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
self.node_decomposition =\
self.network.create_node('worc/Decomposition:1.0',
tool_version='1.0',
id='decomposition',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
self.node_Ranked_Percentages =\
self.network.create_node('worc/PlotRankedScores:1.0',
tool_version='1.0',
id='plot_ranked_percentages',
resources=ResourceLimit(memory='20G'),
step_id='Evaluation')
self.node_Ranked_Posteriors =\
self.network.create_node('worc/PlotRankedScores:1.0',
tool_version='1.0',
id='plot_ranked_posteriors',
resources=ResourceLimit(memory='20G'),
step_id='Evaluation')
self.node_Boxplots_Features =\
self.network.create_node('worc/PlotBoxplotFeatures:1.0',
tool_version='1.0',
id='plot_boxplot_features',
resources=ResourceLimit(memory='12G'),
step_id='Evaluation')
# Create sinks
if self.modus == 'binary_classification':
self.sink_ROC_PNG =\
self.network.create_sink('PNGFile', id='ROC_PNG',
step_id='general_sinks')
self.sink_ROC_Tex =\
self.network.create_sink('TexFile', id='ROC_Tex',
step_id='general_sinks')
self.sink_ROC_CSV =\
self.network.create_sink('CSVFile', id='ROC_CSV',
step_id='general_sinks')
self.sink_PRC_PNG =\
self.network.create_sink('PNGFile', id='PRC_PNG',
step_id='general_sinks')
self.sink_PRC_Tex =\
self.network.create_sink('TexFile', id='PRC_Tex',
step_id='general_sinks')
self.sink_PRC_CSV =\
self.network.create_sink('CSVFile', id='PRC_CSV',
step_id='general_sinks')
if self.mode == 'StandAlone':
self.sink_Estimator_Json =\
self.network.create_sink('JsonFile', id='Estimator_Json',
step_id='general_sinks')
self.sink_Barchart_PNG =\
self.network.create_sink('PNGFile', id='Barchart_PNG',
step_id='general_sinks')
self.sink_Barchart_Tex =\
self.network.create_sink('TexFile',
id='Barchart_Tex',
step_id='general_sinks')
self.sink_Hyperparameters_CSV =\
self.network.create_sink('CSVFile', id='Hyperparameters_CSV',
step_id='general_sinks')
if 'classification' in self.modus:
self.sink_STest_CSV =\
self.network.create_sink('CSVFile',
id='StatisticalTestFeatures_CSV',
step_id='general_sinks')
self.sink_STest_PNG =\
self.network.create_sink('PNGFile',
id='StatisticalTestFeatures_PNG',
step_id='general_sinks')
self.sink_STest_Tex =\
self.network.create_sink('TexFile',
id='StatisticalTestFeatures_Tex',
step_id='general_sinks')
self.sink_decomposition_PNG =\
self.network.create_sink('PNGFile', id='Decomposition_PNG',
step_id='general_sinks')
self.sink_Ranked_Percentages_Zip =\
self.network.create_sink('ZipFile', id='RankedPercentages_Zip',
step_id='general_sinks')
self.sink_Ranked_Percentages_CSV =\
self.network.create_sink('CSVFile', id='RankedPercentages_CSV',
step_id='general_sinks')
self.sink_Ranked_Posteriors_Zip =\
self.network.create_sink('ZipFile', id='RankedPosteriors_Zip',
step_id='general_sinks')
self.sink_Ranked_Posteriors_CSV =\
self.network.create_sink('CSVFile', id='RankedPosteriors_CSV',
step_id='general_sinks')
self.sink_Boxplots_Features_Zip =\
self.network.create_sink('ZipFile', id='BoxplotsFeatures_Zip',
step_id='general_sinks')
# Create links to sinks
if self.modus == 'binary_classification':
self.sink_ROC_PNG.input = self.node_ROC.outputs['ROC_png']
self.sink_ROC_Tex.input = self.node_ROC.outputs['ROC_tex']
self.sink_ROC_CSV.input = self.node_ROC.outputs['ROC_csv']
self.sink_PRC_PNG.input = self.node_ROC.outputs['PRC_png']
self.sink_PRC_Tex.input = self.node_ROC.outputs['PRC_tex']
self.sink_PRC_CSV.input = self.node_ROC.outputs['PRC_csv']
if self.mode == 'StandAlone':
self.sink_Estimator_Json.input = self.node_Estimator.outputs['output_json']
self.sink_Barchart_PNG.input = self.node_Barchart.outputs['output_png']
self.sink_Barchart_Tex.input = self.node_Barchart.outputs['output_tex']
self.sink_Hyperparameters_CSV.input = self.node_Hyperparameters.outputs['output_csv']
if 'classification' in self.modus:
self.sink_STest_CSV.input = self.node_STest.outputs['output_csv']
self.sink_STest_PNG.input = self.node_STest.outputs['output_png']
self.sink_STest_Tex.input = self.node_STest.outputs['output_tex']
self.sink_decomposition_PNG.input = self.node_decomposition.outputs['output']
self.sink_Ranked_Percentages_Zip.input =\
self.node_Ranked_Percentages.outputs['output_zip']
self.sink_Ranked_Percentages_CSV.input =\
self.node_Ranked_Percentages.outputs['output_csv']
# Create constant node
self.node_Ranked_Percentages.inputs['scores'] = ['percentages']
self.sink_Ranked_Posteriors_Zip.input =\
self.node_Ranked_Posteriors.outputs['output_zip']
self.sink_Ranked_Posteriors_CSV.input =\
self.node_Ranked_Posteriors.outputs['output_csv']
self.sink_Boxplots_Features_Zip.input =\
self.node_Boxplots_Features.outputs['output_zip']
# Create constant node
self.node_Ranked_Posteriors.inputs['scores'] = ['posteriors']
if self.mode == 'StandAlone':
self.source_LabelType =\
self.network.create_constant('String', [self.label_type],
id='LabelType',
step_id='Evaluation')
self.source_ensemble_method =\
self.network.create_constant('String', [self.ensemble_method],
id='ensemble_method',
step_id='Evaluation')
self.source_ensemble_size =\
self.network.create_constant('String', [self.ensemble_size],
id='ensemble_size',
step_id='Evaluation')
# Create sources if not supplied by a WORC network
if self.mode == 'StandAlone':
self.source_Estimator =\
self.network.create_source('HDF5', id='Estimator')
self.source_PatientInfo =\
self.network.create_source('PatientInfoFile', id='PatientInfo')
self.source_Images =\
self.network.create_source('ITKImageFile', id='Images',
node_group='patients')
self.source_Segmentations =\
self.network.create_source('ITKImageFile', id='Segmentations',
node_group='patients')
self.source_Config =\
self.network.create_source('ParameterFile', id='Config')
self.labels = list()
self.source_Features = list()
for idx in range(0, len(self.features)):
label = 'Features_' + str(idx)
self.labels.append(label)
self.source_Features.append(self.network.create_source('HDF5', id=label, node_group='features'))
# Create links to the sources that could be in a WORC network
if self.mode == 'StandAlone':
self.create_links_Standalone()
else:
self.create_links_Addon()
def create_links_Standalone(self):
"""Create links in network between nodes when using standalone."""
# Sources from the Evaluate network are used
if self.modus == 'binary_classification':
self.node_ROC.inputs['prediction'] = self.source_Estimator.output
self.node_ROC.inputs['pinfo'] = self.source_PatientInfo.output
self.node_Estimator.inputs['prediction'] = self.source_Estimator.output
self.node_Estimator.inputs['pinfo'] = self.source_PatientInfo.output
self.node_Barchart.inputs['prediction'] = self.source_Estimator.output
self.node_Hyperparameters.inputs['prediction'] = self.source_Estimator.output
if 'classification' in self.modus:
self.links_STest_Features = list()
self.links_decomposition_Features = list()
self.links_Boxplots_Features = list()
for idx, label in enumerate(self.labels):
if 'classification' in self.modus:
self.links_STest_Features.append(self.node_STest.inputs['features'][str(label)] << self.source_Features[idx].output)
self.links_STest_Features[idx].collapse = 'features'
self.links_decomposition_Features.append(self.node_decomposition.inputs['features'][str(label)] << self.source_Features[idx].output)
self.links_decomposition_Features[idx].collapse = 'features'
self.links_Boxplots_Features.append(self.node_Boxplots_Features.inputs['features'][str(label)] << self.source_Features[idx].output)
self.links_Boxplots_Features[idx].collapse = 'features'
if 'classification' in self.modus:
self.node_STest.inputs['patientclass'] = self.source_PatientInfo.output
self.node_STest.inputs['config'] = self.source_Config.output
self.node_decomposition.inputs['patientclass'] = self.source_PatientInfo.output
self.node_decomposition.inputs['config'] = self.source_Config.output
self.node_Ranked_Percentages.inputs['estimator'] = self.source_Estimator.output
self.node_Ranked_Percentages.inputs['pinfo'] = self.source_PatientInfo.output
self.link_images_perc = self.network.create_link(self.source_Images.output, self.node_Ranked_Percentages.inputs['images'])
self.link_images_perc.collapse = 'patients'
self.link_segmentations_perc = self.network.create_link(self.source_Segmentations.output, self.node_Ranked_Percentages.inputs['segmentations'])
self.link_segmentations_perc.collapse = 'patients'
self.node_Boxplots_Features.inputs['patientclass'] = self.source_PatientInfo.output
self.node_Boxplots_Features.inputs['config'] = self.source_Config.output
self.node_Ranked_Posteriors.inputs['estimator'] = self.source_Estimator.output
self.node_Ranked_Posteriors.inputs['pinfo'] = self.source_PatientInfo.output
self.link_images_post = self.network.create_link(self.source_Images.output, self.node_Ranked_Posteriors.inputs['images'])
self.link_images_post.collapse = 'patients'
self.link_segmentations_post = self.network.create_link(self.source_Segmentations.output, self.node_Ranked_Posteriors.inputs['segmentations'])
self.link_segmentations_post.collapse = 'patients'
if self.modus == 'binary_classification':
self.node_ROC.inputs['ensemble_method'] = self.source_ensemble_method.output
self.node_ROC.inputs['ensemble_size'] = self.source_ensemble_size.output
self.node_ROC.inputs['label_type'] = self.source_LabelType.output
if 'classification' in self.modus:
self.node_Ranked_Percentages.inputs['ensemble_method'] =\
self.source_ensemble_method.output
self.node_Ranked_Percentages.inputs['ensemble_size'] =\
self.source_ensemble_size.output
self.node_Ranked_Percentages.inputs['label_type'] =\
self.source_LabelType.output
self.node_Estimator.inputs['ensemble_method'] = self.source_ensemble_method.output
self.node_Estimator.inputs['ensemble_size'] = self.source_ensemble_size.output
self.node_Estimator.inputs['label_type'] = self.source_LabelType.output
self.node_Barchart.inputs['estimators'] = self.source_ensemble_size.output
self.node_Barchart.inputs['label_type'] = self.source_LabelType.output
self.node_Hyperparameters.inputs['estimators'] = self.source_ensemble_size.output
self.node_Hyperparameters.inputs['label_type'] = self.source_LabelType.output
self.node_Ranked_Posteriors.inputs['ensemble_method'] =\
self.source_ensemble_method.output
self.node_Ranked_Posteriors.inputs['ensemble_size'] =\
self.source_ensemble_size.output
self.node_Ranked_Posteriors.inputs['label_type'] =\
self.source_LabelType.output
def create_links_Addon(self):
"""Create links in network between nodes when adding Evaluate to WORC."""
# Sources from the WORC network are used
if self.parent.OnlyTest:
prediction = self.parent.source_trained_model.output
else:
prediction = self.parent.classify.outputs['classification']
if hasattr(self.parent, 'source_patientclass_test'):
pinfo = self.parent.source_patientclass_test.output
else:
pinfo = self.parent.source_patientclass_train.output
if self.parent.configs[0]['General']['Fingerprint'] == 'True':
config = self.parent.node_fingerprinters['classification'].outputs['config']
else:
config = self.parent.source_class_config.output
if hasattr(self.parent, 'sources_images_train'):
if self.parent.sources_images_train:
# NOTE: Use images of first modality to depict tumor
label = self.parent.modlabels[0]
images = self.parent.sources_images_train[label].output
segmentations =\
self.parent.sources_segmentations_train[label].output
if self.modus == 'binary_classification':
self.node_ROC.inputs['ensemble_method'] = self.parent.source_ensemble_method.output
self.node_ROC.inputs['ensemble_size'] = self.parent.source_ensemble_size.output
self.node_ROC.inputs['label_type'] = self.parent.source_LabelType.output
if 'classification' in self.modus:
self.node_Ranked_Percentages.inputs['ensemble_method'] =\
self.parent.source_ensemble_method.output
self.node_Ranked_Percentages.inputs['ensemble_size'] =\
self.parent.source_ensemble_size.output
self.node_Ranked_Percentages.inputs['label_type'] =\
self.parent.source_LabelType.output
self.node_Barchart.inputs['estimators'] = self.parent.source_ensemble_size.output
self.node_Barchart.inputs['label_type'] = self.parent.source_LabelType.output
self.node_Hyperparameters.inputs['estimators'] = self.parent.source_ensemble_size.output
self.node_Hyperparameters.inputs['label_type'] = self.parent.source_LabelType.output
self.node_Ranked_Posteriors.inputs['ensemble_method'] =\
self.parent.source_ensemble_method.output
self.node_Ranked_Posteriors.inputs['ensemble_size'] =\
self.parent.source_ensemble_size.output
self.node_Ranked_Posteriors.inputs['label_type'] =\
self.parent.source_LabelType.output
if self.modus == 'binary_classification':
self.node_ROC.inputs['prediction'] = prediction
self.node_ROC.inputs['pinfo'] = pinfo
self.node_Barchart.inputs['prediction'] = prediction
self.node_Hyperparameters.inputs['prediction'] = prediction
if 'classification' in self.modus:
self.links_STest_Features = dict()
self.links_decomposition_Features = dict()
self.links_Boxplots_Features = dict()
# Check if we have ComBat features
if self.parent.configs[0]['General']['ComBat'] == 'True':
name = 'ComBat'
# Take features from ComBat
if 'classification' in self.modus:
self.links_STest_Features[name] =\
self.network.create_link(self.parent.ComBat.outputs['features_train_out'], self.node_STest.inputs['features'])
self.links_decomposition_Features[name] =\
self.network.create_link(self.parent.ComBat.outputs['features_train_out'], self.node_decomposition.inputs['features'])
self.links_Boxplots_Features[name] =\
self.network.create_link(self.parent.ComBat.outputs['features_train_out'], self.node_Boxplots_Features.inputs['features'])
# All features should be input at once
if 'classification' in self.modus:
self.links_STest_Features[name].collapse = 'ComBat'
self.links_decomposition_Features[name].collapse = 'ComBat'
self.links_Boxplots_Features[name].collapse = 'ComBat'
else:
for idx, label in enumerate(self.parent.modlabels):
# NOTE: Currently statistical testing is only done within the training set
if hasattr(self.parent, 'sources_images_train'):
if self.parent.sources_images_train:
# Take features directly from feature computation toolboxes
for node in self.parent.featureconverter_train[label]:
name = node.id
if 'classification' in self.modus:
self.links_STest_Features[name] =\
self.node_STest.inputs['features'][name] << node.outputs['feat_out']
self.links_decomposition_Features[name] =\
self.node_decomposition.inputs['features'][name] << node.outputs['feat_out']
self.links_Boxplots_Features[name] =\
self.node_Boxplots_Features.inputs['features'][name] << node.outputs['feat_out']
# All features should be input at once
if 'classification' in self.modus:
self.links_STest_Features[name].collapse = 'train'
self.links_decomposition_Features[name].collapse = 'train'
self.links_Boxplots_Features[name].collapse = 'train'
else:
# Feature are precomputed and given as sources
for node in self.parent.sources_features_train.values():
name = node.id
if 'classification' in self.modus:
self.links_STest_Features[name] =\
self.node_STest.inputs['features'][name] << node.output
self.links_decomposition_Features[name] =\
self.node_decomposition.inputs['features'][name] << node.output
self.links_Boxplots_Features[name] =\
self.node_Boxplots_Features.inputs['features'][name] << node.output
# All features should be input at once
if 'classification' in self.modus:
self.links_STest_Features[name].collapse = 'train'
self.links_decomposition_Features[name].collapse = 'train'
self.links_Boxplots_Features[name].collapse = 'train'
else:
# Feature are precomputed and given as sources
for node in self.parent.sources_features_train.values():
name = node.id
if 'classification' in self.modus:
self.links_STest_Features[name] =\
self.node_STest.inputs['features'][name] << node.output
self.links_decomposition_Features[name] =\
self.node_decomposition.inputs['features'][name] << node.output
self.links_Boxplots_Features[name] =\
self.node_Boxplots_Features.inputs['features'][name] << node.output
# All features should be input at once
if 'classification' in self.modus:
self.links_STest_Features[name].collapse = 'train'
self.links_decomposition_Features[name].collapse = 'train'
self.links_Boxplots_Features[name].collapse = 'train'
if 'classification' in self.modus:
self.node_STest.inputs['patientclass'] = pinfo
self.node_STest.inputs['config'] = config
self.node_decomposition.inputs['patientclass'] = pinfo
self.node_decomposition.inputs['config'] = config
self.node_Ranked_Percentages.inputs['estimator'] = prediction
self.node_Ranked_Percentages.inputs['pinfo'] = pinfo
self.node_Boxplots_Features.inputs['patientclass'] = pinfo
self.node_Boxplots_Features.inputs['config'] = config
self.node_Ranked_Posteriors.inputs['estimator'] = prediction
self.node_Ranked_Posteriors.inputs['pinfo'] = pinfo
if hasattr(self.parent, 'sources_images_test'):
images = self.parent.sources_images_test[label].output
segmentations =\
self.parent.sources_segmentations_test[label].output
if 'classification' in self.modus:
self.link_images_perc =\
self.network.create_link(images, self.node_Ranked_Percentages.inputs['images'])
self.link_images_perc.collapse = 'test'
self.link_segmentations_perc =\
self.network.create_link(segmentations, self.node_Ranked_Percentages.inputs['segmentations'])
self.link_segmentations_perc.collapse = 'test'
self.link_images_post =\
self.network.create_link(images, self.node_Ranked_Posteriors.inputs['images'])
self.link_images_post.collapse = 'test'
self.link_segmentations_post =\
self.network.create_link(segmentations, self.node_Ranked_Posteriors.inputs['segmentations'])
self.link_segmentations_post.collapse = 'test'
elif hasattr(self.parent, 'sources_images_train'):
if self.parent.sources_images_train:
if 'classification' in self.modus:
self.link_images_perc =\
self.network.create_link(images, self.node_Ranked_Percentages.inputs['images'])
self.link_images_perc.collapse = 'train'
self.link_segmentations_perc =\
self.network.create_link(segmentations, self.node_Ranked_Percentages.inputs['segmentations'])
self.link_segmentations_perc.collapse = 'train'
self.link_images_post =\
self.network.create_link(images, self.node_Ranked_Posteriors.inputs['images'])
self.link_images_post.collapse = 'train'
self.link_segmentations_post =\
self.network.create_link(segmentations, self.node_Ranked_Posteriors.inputs['segmentations'])
self.link_segmentations_post.collapse = 'train'
def set(self, estimator=None, pinfo=None, images=None,
segmentations=None, config=None, features=None,
sink_data={}):
"""Set the sources and sinks based on the provided attributes."""
if self.mode == 'StandAlone':
self.source_data = dict()
self.sink_data = dict()
self.source_data['Estimator'] = estimator
self.source_data['PatientInfo'] = pinfo
self.source_data['Images'] = images
self.source_data['Segmentations'] = segmentations
self.source_data['Config'] = config
self.source_data['LabelType'] = self.label_type
self.source_data['ensemble_method'] = self.ensemble_method
self.source_data['ensemble_size'] = self.ensemble_size
for feature, label in zip(features, self.labels):
self.source_data[label] = feature
else:
self.sink_data = self.parent.sink_data
if self.modus == 'binary_classification':
if 'ROC_PNG' not in sink_data.keys():
self.sink_data['ROC_PNG'] = ("vfs://output/{}/Evaluation/ROC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'ROC_Tex' not in sink_data.keys():
self.sink_data['ROC_Tex'] = ("vfs://output/{}/Evaluation/ROC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'ROC_CSV' not in sink_data.keys():
self.sink_data['ROC_CSV'] = ("vfs://output/{}/Evaluation/ROC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'PRC_PNG' not in sink_data.keys():
self.sink_data['PRC_PNG'] = ("vfs://output/{}/Evaluation/PRC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'PRC_Tex' not in sink_data.keys():
self.sink_data['PRC_Tex'] = ("vfs://output/{}/Evaluation/PRC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'PRC_CSV' not in sink_data.keys():
self.sink_data['PRC_CSV'] = ("vfs://output/{}/Evaluation/PRC_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'Estimator_Json' not in sink_data.keys():
self.sink_data['Estimator_Json'] = ("vfs://output/{}/Evaluation/performance_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'Barchart_PNG' not in sink_data.keys():
self.sink_data['Barchart_PNG'] = ("vfs://output/{}/Evaluation/Barchart_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'Barchart_Tex' not in sink_data.keys():
self.sink_data['Barchart_Tex'] = ("vfs://output/{}/Evaluation/Barchart_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'Hyperparameters_CSV' not in sink_data.keys():
self.sink_data['Hyperparameters_CSV'] = ("vfs://output/{}/Evaluation/Hyperparameters_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'classification' in self.modus:
if 'StatisticalTestFeatures_CSV' not in sink_data.keys():
self.sink_data['StatisticalTestFeatures_CSV'] = ("vfs://output/{}/Evaluation/StatisticalTestFeatures_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'StatisticalTestFeatures_PNG' not in sink_data.keys():
self.sink_data['StatisticalTestFeatures_PNG'] = ("vfs://output/{}/Evaluation/StatisticalTestFeatures_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'StatisticalTestFeatures_Tex' not in sink_data.keys():
self.sink_data['StatisticalTestFeatures_Tex'] = ("vfs://output/{}/Evaluation/StatisticalTestFeatures_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'Decomposition_PNG' not in sink_data.keys():
self.sink_data['Decomposition_PNG'] = ("vfs://output/{}/Evaluation/Decomposition_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'RankedPercentages_Zip' not in sink_data.keys():
self.sink_data['RankedPercentages_Zip'] = ("vfs://output/{}/Evaluation/RankedPercentages_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'RankedPercentages_CSV' not in sink_data.keys():
self.sink_data['RankedPercentages_CSV'] = ("vfs://output/{}/Evaluation/RankedPercentages_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'RankedPosteriors_Zip' not in sink_data.keys():
self.sink_data['RankedPosteriors_Zip'] = ("vfs://output/{}/Evaluation/RankedPosteriors_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'RankedPosteriors_CSV' not in sink_data.keys():
self.sink_data['RankedPosteriors_CSV'] = ("vfs://output/{}/Evaluation/RankedPosteriors_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
if 'BoxplotsFeatures_Zip' not in sink_data.keys():
self.sink_data['BoxplotsFeatures_Zip'] = ("vfs://output/{}/Evaluation/BoxplotsFeatures_{{sample_id}}_{{cardinality}}{{ext}}").format(self.name)
def execute(self):
"""Execute the network through the fastr.network.execute command."""
# Draw and execute nwtwork
try:
self.network.draw(file_path=self.network.id + '.svg',
draw_dimensions=True)
except graphviz.backend.ExecutableNotFound:
print('[WORC WARNING] Graphviz executable not found: not drawing network diagram. MAke sure the Graphviz executables are on your systems PATH.')
self.network.execute(self.source_data, self.sink_data,
execution_plugin=self.fastr_plugin,
tmpdir=self.fastr_tmpdir)