a b/default_configs.py
1
#!/usr/bin/env python
2
# Copyright 2018 Division of Medical Image Computing, German Cancer Research Center (DKFZ).
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
# ==============================================================================
16
17
"""Default Configurations script. Avoids changing configs of all experiments if general settings are to be changed."""
18
19
import os
20
21
class DefaultConfigs:
22
23
    def __init__(self, model, server_env=False, dim=2):
24
        self.server_env = server_env
25
        #########################
26
        #         I/O           #
27
        #########################
28
29
        self.model = model
30
        self.dim = dim
31
        # int [0 < dataset_size]. select n patients from dataset for prototyping.
32
        self.select_prototype_subset = None
33
34
        # some default paths.
35
        self.backbone_path = 'models/backbone.py'
36
        self.source_dir = os.path.dirname(os.path.realpath(__file__)) #current dir.
37
        self.input_df_name = 'info_df.pickle'
38
        self.model_path = 'models/{}.py'.format(self.model)
39
40
        if server_env:
41
            self.source_dir = '/home/jaegerp/code/mamma_code/medicaldetectiontoolkit'
42
43
        #########################
44
        #      Data Loader      #
45
        #########################
46
47
        #random seed for fold_generator and batch_generator.
48
        self.seed = 0
49
50
        #number of threads for multithreaded batch generation.
51
        self.n_workers = 4 if server_env else os.cpu_count()-1
52
53
        # if True, segmentation losses learn all categories, else only foreground vs. background.
54
        self.class_specific_seg_flag = False
55
56
        #########################
57
        #      Architecture      #
58
        #########################
59
60
        self.weight_decay = 0.0
61
        # what weight or layer types to exclude from weight decay. options: ["bias", "norm"].
62
        self.exclude_from_wd = ("norm",)
63
64
        # nonlinearity to be applied after convs with nonlinearity. one of 'relu' or 'leaky_relu'
65
        self.relu = 'relu'
66
67
        # if True initializes weights as specified in model script. else use default Pytorch init.
68
        self.custom_init = False
69
70
        # if True adds high-res decoder levels to feature pyramid: P1 + P0. (e.g. set to true in retina_unet configs)
71
        self.operate_stride1 = False
72
73
        #########################
74
        #  Schedule             #
75
        #########################
76
77
        # number of folds in cross validation.
78
        self.n_cv_splits = 5
79
80
81
        # number of probabilistic samples in validation.
82
        self.n_probabilistic_samples = None
83
84
        #########################
85
        #   Testing / Plotting  #
86
        #########################
87
88
        # perform mirroring at test time. (only XY. Z not done to not blow up predictions times).
89
        self.test_aug = True
90
91
        # if True, test data lies in a separate folder and is not part of the cross validation.
92
        self.hold_out_test_set = True
93
94
        # if hold_out_test_set provided, ensemble predictions over models of all trained cv-folds.
95
        # implications for hold-out test sets: if True, evaluate folds separately on the test set, aggregate only the
96
        # evaluations. if False, aggregate the raw predictions across all folds, then evaluate.
97
        self.ensemble_folds = True
98
99
        # color specifications for all box_types in prediction_plot.
100
        self.box_color_palette = {'det': 'b', 'gt': 'r', 'neg_class': 'purple',
101
                                  'prop': 'w', 'pos_class': 'g', 'pos_anchor': 'c', 'neg_anchor': 'c'}
102
103
        # scan over confidence score in evaluation to optimize it on the validation set.
104
        self.scan_det_thresh = False
105
106
        # plots roc-curves / prc-curves in evaluation.
107
        self.plot_stat_curves = True
108
109
        # evaluates average precision per image and averages over images. instead computing one ap over data set.
110
        self.per_patient_ap = True
111
112
        # threshold for clustering 2D box predictions to 3D Cubes. Overlap is computed in XY.
113
        self.merge_3D_iou = 0.1
114
115
        # monitor any value from training.
116
        self.n_monitoring_figures = 1
117
        # dict to assign specific plot_values to monitor_figures > 0. {1: ['class_loss'], 2: ['kl_loss', 'kl_sigmas']}
118
        self.assign_values_to_extra_figure = {}
119
120
        # save predictions to csv file in experiment dir.
121
        self.save_preds_to_csv = True
122
123
        # select a maximum number of patient cases to test. number or "all" for all
124
        self.max_test_patients = "all"
125
126
127
128
        #########################
129
        #   MRCNN               #
130
        #########################
131
132
        # if True, mask loss is not applied. used for data sets, where no pixel-wise annotations are provided.
133
        self.frcnn_mode = True
134
135
        # if True, unmolds masks in Mask R-CNN to full-res for plotting/monitoring.
136
        self.return_masks_in_val = False
137
        self.return_masks_in_test = False # needed if doing instance segmentation. evaluation not yet implemented.
138
139
        # add P6 to Feature Pyramid Network.
140
        self.sixth_pooling = False
141
142
        # for probabilistic detection
143
        self.n_latent_dims = 0
144
145