File size: 6,991 Bytes
7226a40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
    "whether_raw_luna16": false,
    "whether_resampled_luna16": "$(not @whether_raw_luna16)",
    "imports": [
        "$import glob",
        "$import numpy",
        "$import os"
    ],
    "bundle_root": ".",
    "image_key": "image",
    "ckpt_dir": "$@bundle_root + '/models'",
    "output_dir": "$@bundle_root + '/eval'",
    "output_filename": "result_luna16_fold0.json",
    "data_list_file_path": "$@bundle_root + '/LUNA16_datasplit/dataset_fold0.json'",
    "dataset_dir": "/datasets/LUNA16_Images_resample",
    "test_datalist": "$monai.data.load_decathlon_datalist(@data_list_file_path, is_segmentation=True, data_list_key='validation', base_dir=@dataset_dir)",
    "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
    "amp": true,
    "load_pretrain": true,
    "spatial_dims": 3,
    "num_classes": 1,
    "force_sliding_window": false,
    "size_divisible": [
        16,
        16,
        8
    ],
    "infer_patch_size": [
        512,
        512,
        192
    ],
    "anchor_generator": {
        "_target_": "monai.apps.detection.utils.anchor_utils.AnchorGeneratorWithAnchorShape",
        "feature_map_scales": [
            1,
            2,
            4
        ],
        "base_anchor_shapes": [
            [
                6,
                8,
                4
            ],
            [
                8,
                6,
                5
            ],
            [
                10,
                10,
                6
            ]
        ]
    },
    "backbone": "$monai.networks.nets.resnet.resnet50(spatial_dims=3,n_input_channels=1,conv1_t_stride=[2,2,1],conv1_t_size=[7,7,7])",
    "feature_extractor": "$monai.apps.detection.networks.retinanet_network.resnet_fpn_feature_extractor(@backbone,3,False,[1,2],None)",
    "network_def": {
        "_target_": "RetinaNet",
        "spatial_dims": "@spatial_dims",
        "num_classes": "@num_classes",
        "num_anchors": 3,
        "feature_extractor": "@feature_extractor",
        "size_divisible": "@size_divisible",
        "use_list_output": false
    },
    "network": "$@network_def.to(@device)",
    "detector": {
        "_target_": "RetinaNetDetector",
        "network": "@network",
        "anchor_generator": "@anchor_generator",
        "debug": false,
        "spatial_dims": "@spatial_dims",
        "num_classes": "@num_classes",
        "size_divisible": "@size_divisible"
    },
    "detector_ops": [
        "$@detector.set_target_keys(box_key='box', label_key='label')",
        "$@detector.set_box_selector_parameters(score_thresh=0.02,topk_candidates_per_level=1000,nms_thresh=0.22,detections_per_img=300)",
        "$@detector.set_sliding_window_inferer(roi_size=@infer_patch_size,overlap=0.25,sw_batch_size=1,mode='constant',device='cpu')"
    ],
    "preprocessing": {
        "_target_": "Compose",
        "transforms": [
            {
                "_target_": "LoadImaged",
                "keys": "@image_key",
                "_disabled_": "@whether_raw_luna16"
            },
            {
                "_target_": "LoadImaged",
                "keys": "@image_key",
                "reader": "itkreader",
                "affine_lps_to_ras": true,
                "_disabled_": "@whether_resampled_luna16"
            },
            {
                "_target_": "EnsureChannelFirstd",
                "keys": "@image_key"
            },
            {
                "_target_": "Orientationd",
                "keys": "@image_key",
                "axcodes": "RAS"
            },
            {
                "_target_": "Spacingd",
                "keys": "@image_key",
                "pixdim": [
                    0.703125,
                    0.703125,
                    1.25
                ],
                "_disabled_": "@whether_resampled_luna16"
            },
            {
                "_target_": "ScaleIntensityRanged",
                "keys": "@image_key",
                "a_min": -1024.0,
                "a_max": 300.0,
                "b_min": 0.0,
                "b_max": 1.0,
                "clip": true
            },
            {
                "_target_": "EnsureTyped",
                "keys": "@image_key"
            }
        ]
    },
    "dataset": {
        "_target_": "Dataset",
        "data": "$@test_datalist",
        "transform": "@preprocessing"
    },
    "dataloader": {
        "_target_": "DataLoader",
        "dataset": "@dataset",
        "batch_size": 1,
        "shuffle": false,
        "num_workers": 4,
        "collate_fn": "$monai.data.utils.no_collation"
    },
    "inferer": {
        "_target_": "scripts.detection_inferer.RetinaNetInferer",
        "detector": "@detector",
        "force_sliding_window": "@force_sliding_window"
    },
    "postprocessing": {
        "_target_": "Compose",
        "transforms": [
            {
                "_target_": "ClipBoxToImaged",
                "box_keys": "box",
                "label_keys": "label",
                "box_ref_image_keys": "@image_key",
                "remove_empty": true
            },
            {
                "_target_": "AffineBoxToWorldCoordinated",
                "box_keys": "box",
                "box_ref_image_keys": "@image_key",
                "affine_lps_to_ras": true
            },
            {
                "_target_": "ConvertBoxModed",
                "box_keys": "box",
                "src_mode": "xyzxyz",
                "dst_mode": "cccwhd"
            },
            {
                "_target_": "DeleteItemsd",
                "keys": [
                    "@image_key"
                ]
            }
        ]
    },
    "handlers": [
        {
            "_target_": "StatsHandler",
            "iteration_log": false
        },
        {
            "_target_": "scripts.detection_saver.DetectionSaver",
            "output_dir": "@output_dir",
            "filename": "@output_filename",
            "batch_transform": "$lambda x: [xx['image'].meta for xx in x]",
            "output_transform": "$lambda x: [@postprocessing({**xx['pred'],'image':xx['image']}) for xx in x]",
            "pred_box_key": "box",
            "pred_label_key": "label",
            "pred_score_key": "label_scores"
        }
    ],
    "evaluator": {
        "_target_": "scripts.evaluator.DetectionEvaluator",
        "_requires_": "@detector_ops",
        "device": "@device",
        "val_data_loader": "@dataloader",
        "network": "@network",
        "inferer": "@inferer",
        "val_handlers": "@handlers",
        "amp": "@amp"
    },
    "checkpointloader": {
        "_target_": "CheckpointLoader",
        "load_path": "$@bundle_root + '/models/model.pt'",
        "load_dict": {
            "model": "@network"
        }
    },
    "initialize": [
        "$setattr(torch.backends.cudnn, 'benchmark', True)",
        "$@checkpointloader(@evaluator) if @load_pretrain else None"
    ],
    "run": [
        "$@evaluator.run()"
    ]
}