katielink commited on
Commit
5961189
1 Parent(s): 7d08a41

complete the model package

Browse files
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2023] [Chernenkiy Ivan Michailovich]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - monai
4
+ - medical
5
+ library_name: monai
6
+ license: apache-2.0
7
+ ---
8
+ # Model Title
9
+ Renal structures CECT segmentation
10
+
11
+ ### **Authors**
12
+ Ivan Chernenkiy, Michael Chernenkiy, Dmitry Fiev, Evgeny Sirota, Center for Neural Network Technologies / Institute of Urology and Human Reproductive Systems / Sechenov First Moscow State Medical University
13
+
14
+ ### **Tags**
15
+ Segmentation, CT, CECT, Kidney, Renal, Supervised
16
+
17
+ ## **Model Description**
18
+ The model is the SegResNet architecture[1] for volumetric (3D) renal structures segmentation. Input is artery, vein, excretory phases after mutual registration and concatenated to 3 channel 3D tensor.
19
+
20
+
21
+ ## **Data**
22
+ DICOM data from 41 patients with kidney neoplasms were used [2]. The images and segmentation data are available under a CC BY-NC-SA 4.0 license. Data included all phases of contrast-enhanced multispiral computed tomography. We split the data: 32 observations for the training set and 9 – for the validation set. At the labeling stage, the arterial, venous, and excretory phases were taken, affine registration was performed to jointly match the location of the kidneys, and noise was removed using a median filter and a non-local means filter. Validation set ip published to Yandex.Disk. You can download via [link](https://disk.yandex.ru/d/pWEKt6D3qi3-aw) or use following command:
23
+ ```bash
24
+ python -m monai.bundle run download_data --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
25
+ ```
26
+
27
+ **NB**: underlying data is in LPS orientation. IF! you want to test model on your own data, reorient it from RAS to LPS with `Orientation` transform. You can see example of preprocessing pipeline in `inference.json` file of this bundle.
28
+
29
+ #### **Preprocessing**
30
+ Images are (1) croped to kidney region, all (artery,vein,excret) phases are (2) [registered](https://simpleitk.readthedocs.io/en/master/registrationOverview.html#lbl-registration-overview) with affine transform, noise removed with (3) median and (4) non-local means filter. After that, images are (5) resampled to (0.8,0.8,0.8) density and intesities are (6) scaled from [-1000,1000] to [0,1] range.
31
+
32
+ ## **Performance**
33
+ On the validation subset, the values of the Dice score of the SegResNet architecture were: 0.89 for the normal parenchyma of the kidney, 0.58 for the kidney neoplasms, 0.86 for arteries, 0.80 for veins, 0.80 for ureters.
34
+
35
+ When compared with the nnU-Net model, which was trained on KiTS 21 dataset, the Dice score was greater for the kidney parenchyma in SegResNet – 0.89 compared to three model variants: lowres – 0.69, fullres – 0.70, cascade – 0.69. At the same time, for the neoplasms of the parenchyma of the kidney, the Dice score was comparable: for SegResNet – 0.58, for nnU-Net fullres – 0.59; lowres and cascade had lower Dice score of 0.37 and 0.45, respectively. To reproduce, visit - https://github.com/blacky-i/nephro-segmentation
36
+
37
+
38
+ ## **Additional Usage Steps**
39
+
40
+ #### Execute training:
41
+
42
+ ```bash
43
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json
44
+ ```
45
+ Expected result: finished, Training process started
46
+
47
+
48
+ #### Execute training with finetuning
49
+ ```bash
50
+ python -m monai.bundle run training --dont_finetune false --meta_file configs/metadata.json --config_file configs/train.json
51
+ ```
52
+ Expected result: finished, Training process started, model variables are restored
53
+
54
+ #### Execute validation:
55
+
56
+ Download validation data (described in [Data](#data) section).
57
+
58
+ With provided model weights mean dice score is expected to be ~0.78446.
59
+
60
+ ##### Run validation script:
61
+ ```bash
62
+ python -m monai.bundle run evaluate --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
63
+ ```
64
+ Expected result: finished, `Key metric: val_mean_dice best value: ...` is printed.
65
+
66
+ ## **System Configuration**
67
+ The model was trained for 10000 epochs on 2 RTX2080Ti GPUs with [SmartCacheDataset](https://docs.monai.io/en/stable/data.html#smartcachedataset). This takes 1 days and 2 hours, with 4 images per GPU.
68
+ Training progress is available on [tensorboard.dev](https://tensorboard.dev/experiment/VlEMjLdURH6SyFp216dFBg)
69
+
70
+ To perform training in minimal settings, at least one 12GB-memory GPU is required.
71
+ Actual Model Input: 96 x 96 x 96
72
+
73
+ ## **Limitations**
74
+ For developmental purposes only and cannot be used directly for clinical procedures.
75
+
76
+ ## **Citation Info**
77
+ ```
78
+ @article{chernenkiy2023segmentation,
79
+ title={Segmentation of renal structures based on contrast computed tomography scans using a convolutional neural network},
80
+ author={Chernenkiy, IМ and Chernenkiy, MM and Fiev, DN and Sirota, ES},
81
+ journal={Sechenov Medical Journal},
82
+ volume={14},
83
+ number={1},
84
+ pages={39--49},
85
+ year={2023}
86
+ }
87
+ ```
88
+
89
+ ## **References**
90
+
91
+ [1] Myronenko, A. (2019). 3D MRI Brain Tumor Segmentation Using Autoencoder Regularization. In: Crimi, A., Bakas, S., Kuijf, H., Keyvan, F., Reyes, M., van Walsum, T. (eds) Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries. BrainLes 2018. Lecture Notes in Computer Science(), vol 11384. Springer, Cham. https://doi.org/10.1007/978-3-030-11726-9_28
92
+
93
+ [2] Chernenkiy, I. М., et al. "Segmentation of renal structures based on contrast computed tomography scans using a convolutional neural network." Sechenov Medical Journal 14.1 (2023): 39-49.https://doi.org/10.47093/2218-7332.2023.14.1.39-49
94
+
95
+ #### **Tests used for bundle checking**
96
+
97
+ Checking with ci script file
98
+ ```bash
99
+ python ci/verify_bundle.py -b renalStructures_CECT_segmentation -p models
100
+ ```
101
+ Expected result: passed, model.pt file downloaded
102
+
103
+
104
+ Checking downloading validation data file
105
+ ```bash
106
+ cd models/renalStructures_CECT_segmentation
107
+ python -m monai.bundle run download_data --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
108
+ ```
109
+ Expected result: finished, `data/` folder is created and filled with images.
110
+
111
+
112
+ Checking evaluation script
113
+ ```bash
114
+ python -m monai.bundle run evaluate --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
115
+ ```
116
+ Expected result: finished, `Key metric: val_mean_dice best value: ...` is printed.
117
+
118
+
119
+ Checking train script
120
+ ```bash
121
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json
122
+ ```
123
+ Expected result: finished, Training process started
124
+
125
+
126
+ Checking train script with finetuning
127
+ ```bash
128
+ python -m monai.bundle run training --dont_finetune false --meta_file configs/metadata.json --config_file configs/train.json
129
+ ```
130
+ Expected result: finished, Training process started, model variables are restored
131
+
132
+ Checking inference script
133
+ ```bash
134
+ python -m monai.bundle run inference --meta_file configs/metadata.json --config_file configs/inference.json
135
+ ```
136
+ Expected result: finished, in `eval` folder masks are created
137
+
138
+ Check unit test with script:
139
+ ```bash
140
+ python ci/unit_tests/runner.py --b renalStructures_CECT_segmentation
141
+ ```
configs/evaluate.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "imports": [
3
+ "$import glob",
4
+ "$import os",
5
+ "$import ignite",
6
+ "$import json",
7
+ "$import urllib"
8
+ ],
9
+ "validate#handlers": [
10
+ {
11
+ "_target_": "StatsHandler",
12
+ "iteration_log": false
13
+ },
14
+ {
15
+ "_target_": "CheckpointLoader",
16
+ "load_path": "$@ckpt_dir + '/model.pt'",
17
+ "load_dict": {
18
+ "model": "@network"
19
+ }
20
+ },
21
+ {
22
+ "_target_": "MetricsSaver",
23
+ "save_dir": "@output_dir",
24
+ "metrics": [
25
+ "val_mean_dice",
26
+ "ar/dice",
27
+ "ve/dice",
28
+ "ur/dice",
29
+ "ki/dice",
30
+ "tu/dice",
31
+ "tu/haunsdorff",
32
+ "tu/surface"
33
+ ],
34
+ "metric_details": [
35
+ "val_mean_dice"
36
+ ],
37
+ "batch_transform": "$monai.handlers.from_engine(['image_meta_dict'])",
38
+ "summary_ops": "*"
39
+ }
40
+ ],
41
+ "download_data": [
42
+ "$import logging",
43
+ "$import zipfile",
44
+ "$import os",
45
+ "$logging.info('Downloading 298Mb data zip archive, please wait... (To see progress bar, download manually from https://disk.yandex.ru/d/pWEKt6D3qi3-aw , and extract data to bundle_root - ' + @bundle_root + ')')",
46
+ "$urllib.request.urlretrieve(json.loads(urllib.request.urlopen('https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key=https%3A%2F%2Fdisk.yandex.ru%2Fd%2FpWEKt6D3qi3-aw').read())['href'], @bundle_root + '/AVUCTK_cases.zip')",
47
+ "$zipfile.ZipFile(os.path.join(@bundle_root, 'AVUCTK_cases.zip'), 'r').extractall(@bundle_root)",
48
+ "$os.remove(os.path.join(@bundle_root, 'AVUCTK_cases.zip'))",
49
+ "$logging.info('Data extracted to ' + @bundle_root)"
50
+ ],
51
+ "evaluate": [
52
+ "$monai.utils.set_determinism(seed=42)",
53
+ "$setattr(torch.backends.cudnn, 'benchmark', True)",
54
+ "$@validate#evaluator.run()"
55
+ ]
56
+ }
configs/inference.json ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "imports": [
3
+ "$import glob",
4
+ "$import os"
5
+ ],
6
+ "bundle_root": ".",
7
+ "ckpt_dir": "$@bundle_root + '/models'",
8
+ "output_dir": "$@bundle_root + '/eval'",
9
+ "dataset_dir": "$@bundle_root + '/data'",
10
+ "images": "$[{'artery':a, 'vein':b, 'excret':c }for a,b,c in zip(glob.glob(@dataset_dir + '/*/12.nii.gz'), glob.glob(@dataset_dir + '/*/22-.nii.gz'), glob.glob(@dataset_dir + '/*/32-.nii.gz'))]",
11
+ "labels": "$list(glob.glob(@dataset_dir + '/*/merged.nii.gz'))",
12
+ "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
13
+ "network_def": {
14
+ "_target_": "SegResNet",
15
+ "in_channels": 3,
16
+ "out_channels": 6,
17
+ "init_filters": 32,
18
+ "upsample_mode": "deconv",
19
+ "dropout_prob": 0.2,
20
+ "norm_name": "group",
21
+ "blocks_down": [
22
+ 1,
23
+ 2,
24
+ 2,
25
+ 4
26
+ ],
27
+ "blocks_up": [
28
+ 1,
29
+ 1,
30
+ 1
31
+ ]
32
+ },
33
+ "network": "$@network_def.to(@device)",
34
+ "preprocessing": {
35
+ "_target_": "Compose",
36
+ "transforms": [
37
+ {
38
+ "_target_": "LoadImaged",
39
+ "keys": [
40
+ "artery",
41
+ "vein",
42
+ "excret",
43
+ "label"
44
+ ]
45
+ },
46
+ {
47
+ "_target_": "EnsureChannelFirstd",
48
+ "keys": [
49
+ "artery",
50
+ "vein",
51
+ "excret"
52
+ ]
53
+ },
54
+ {
55
+ "_target_": "Orientationd",
56
+ "keys": [
57
+ "artery",
58
+ "vein",
59
+ "excret"
60
+ ],
61
+ "axcodes": "LPS"
62
+ },
63
+ {
64
+ "_target_": "Spacingd",
65
+ "keys": [
66
+ "artery",
67
+ "vein",
68
+ "excret"
69
+ ],
70
+ "pixdim": [
71
+ 0.8,
72
+ 0.8,
73
+ 0.8
74
+ ],
75
+ "mode": "bilinear"
76
+ },
77
+ {
78
+ "_target_": "scripts.my_transforms.ConcatImages",
79
+ "keys_merge": [
80
+ "artery",
81
+ "vein",
82
+ "excret"
83
+ ],
84
+ "keys_out": "image"
85
+ },
86
+ {
87
+ "_target_": "ScaleIntensityRanged",
88
+ "keys": "image",
89
+ "a_min": -1000,
90
+ "a_max": 1000,
91
+ "b_min": 0.0,
92
+ "b_max": 1.0,
93
+ "clip": true
94
+ },
95
+ {
96
+ "_target_": "EnsureTyped",
97
+ "keys": "image"
98
+ }
99
+ ]
100
+ },
101
+ "dataset": {
102
+ "_target_": "Dataset",
103
+ "data": "$[{'label': l, **i} for i, l in zip(@images, @labels)]",
104
+ "transform": "@preprocessing"
105
+ },
106
+ "dataloader": {
107
+ "_target_": "DataLoader",
108
+ "dataset": "@dataset",
109
+ "batch_size": 1,
110
+ "shuffle": false,
111
+ "num_workers": 4
112
+ },
113
+ "inferer": {
114
+ "_target_": "SlidingWindowInferer",
115
+ "roi_size": [
116
+ 96,
117
+ 96,
118
+ 96
119
+ ],
120
+ "sw_batch_size": 4,
121
+ "overlap": 0.25
122
+ },
123
+ "postprocessing": {
124
+ "_target_": "Compose",
125
+ "transforms": [
126
+ {
127
+ "_target_": "Invertd",
128
+ "transform": "$@preprocessing",
129
+ "device": "@device",
130
+ "keys": "pred",
131
+ "orig_keys": "artery",
132
+ "meta_keys": "pred_meta_dict",
133
+ "nearest_interp": false,
134
+ "to_tensor": true
135
+ },
136
+ {
137
+ "_target_": "Activationsd",
138
+ "keys": "pred",
139
+ "softmax": false,
140
+ "sigmoid": true
141
+ },
142
+ {
143
+ "_target_": "AsDiscreted",
144
+ "keys": "pred",
145
+ "threshold": 0.5
146
+ },
147
+ {
148
+ "_target_": "scripts.my_transforms.MergeClassesd",
149
+ "keys": "pred"
150
+ },
151
+ {
152
+ "_target_": "SaveImaged",
153
+ "keys": "pred",
154
+ "meta_keys": "pred_meta_dict",
155
+ "data_root_dir": "@dataset_dir",
156
+ "output_dir": "@output_dir"
157
+ },
158
+ {
159
+ "_target_": "SaveImaged",
160
+ "keys": "label",
161
+ "data_root_dir": "@dataset_dir",
162
+ "output_dir": "@output_dir"
163
+ }
164
+ ]
165
+ },
166
+ "handlers": [
167
+ {
168
+ "_target_": "CheckpointLoader",
169
+ "load_path": "$@ckpt_dir + '/model.pt'",
170
+ "load_dict": {
171
+ "model": "@network"
172
+ },
173
+ "strict": "True"
174
+ },
175
+ {
176
+ "_target_": "StatsHandler",
177
+ "iteration_log": false
178
+ }
179
+ ],
180
+ "evaluator": {
181
+ "_target_": "SupervisedEvaluator",
182
+ "device": "@device",
183
+ "val_data_loader": "@dataloader",
184
+ "network": "@network",
185
+ "inferer": "@inferer",
186
+ "postprocessing": "@postprocessing",
187
+ "val_handlers": "@handlers",
188
+ "amp": false
189
+ },
190
+ "inference": [
191
+ "$setattr(torch.backends.cudnn, 'benchmark', True)",
192
+ "$@evaluator.run()"
193
+ ]
194
+ }
configs/logging.conf ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [loggers]
2
+ keys=root
3
+
4
+ [handlers]
5
+ keys=consoleHandler
6
+
7
+ [formatters]
8
+ keys=fullFormatter
9
+
10
+ [logger_root]
11
+ level=INFO
12
+ handlers=consoleHandler
13
+
14
+ [handler_consoleHandler]
15
+ class=StreamHandler
16
+ level=INFO
17
+ formatter=fullFormatter
18
+ args=(sys.stdout,)
19
+
20
+ [formatter_fullFormatter]
21
+ format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
configs/metadata.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
3
+ "version": "0.1.0",
4
+ "changelog": {
5
+ "0.1.0": "complete the model package"
6
+ },
7
+ "monai_version": "1.2.0",
8
+ "pytorch_version": "1.13.1",
9
+ "numpy_version": "1.24.3",
10
+ "optional_packages_version": {
11
+ "nibabel": "5.1.0",
12
+ "pytorch-ignite": "0.4.11",
13
+ "einops": "0.6.1",
14
+ "fire": "0.5.0",
15
+ "torchvision": "0.14.1"
16
+ },
17
+ "name": "Segmentation of renal structures based on contrast computed tomography scans",
18
+ "task": "Renal structures segmentation",
19
+ "description": "A UNET-based model for renal segmentation from contrast enhanced CT image",
20
+ "authors": "Sechenov university",
21
+ "copyright": "Copyright (c) Sechenov university",
22
+ "data_source": "AVUCTK_cases.zip",
23
+ "data_type": "nibabel",
24
+ "image_classes": "three channel data, intensity scaled to [0, 1]",
25
+ "label_classes": "1: artery, 2: vein, 3: ureter, 4: cyst, 5: tumor, 6: parenchyma",
26
+ "pred_classes": "1: artery, 2: vein, 3: ureter, 4: neoplasm, 5: parenchyma",
27
+ "eval_metrics": {
28
+ "mean_dice": 0.79
29
+ },
30
+ "intended_use": "This is PoC, not to be used for diagnostic purposes",
31
+ "references": [
32
+ "Chernenkiy I. M. et al. Segmentation of renal structures based on contrast computed tomography scans using a convolutional neural network //Sechenov Medical Journal. \u2013 2023. \u2013 \u0422. 14. \u2013 \u2116. 1. \u2013 \u0421. 39-49. URL - https://www.sechenovmedj.com/jour/article/view/899"
33
+ ],
34
+ "network_data_format": {
35
+ "inputs": {
36
+ "image": {
37
+ "type": "image",
38
+ "format": "hounsfield",
39
+ "modality": "CT",
40
+ "num_channels": 3,
41
+ "spatial_shape": [
42
+ 96,
43
+ 96,
44
+ 96
45
+ ],
46
+ "dtype": "float32",
47
+ "value_range": [
48
+ 0,
49
+ 1
50
+ ],
51
+ "is_patch_data": true,
52
+ "channel_def": {
53
+ "0": "image"
54
+ }
55
+ }
56
+ },
57
+ "outputs": {
58
+ "pred": {
59
+ "type": "image",
60
+ "format": "segmentation",
61
+ "num_channels": 6,
62
+ "spatial_shape": [
63
+ 96,
64
+ 96,
65
+ 96
66
+ ],
67
+ "dtype": "float32",
68
+ "value_range": [
69
+ 0,
70
+ 1
71
+ ],
72
+ "is_patch_data": true,
73
+ "channel_def": {
74
+ "0": "background",
75
+ "1": "artery",
76
+ "2": "vein",
77
+ "3": "ureter",
78
+ "4": "neoplasm",
79
+ "5": "parenchyma"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
configs/train.json ADDED
@@ -0,0 +1,500 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "imports": [
3
+ "$import glob",
4
+ "$import os",
5
+ "$import ignite"
6
+ ],
7
+ "bundle_root": ".",
8
+ "ckpt_dir": "$@bundle_root + '/models'",
9
+ "output_dir": "$@bundle_root + '/eval'",
10
+ "dataset_dir": "$@bundle_root + '/data'",
11
+ "images": "$[{'artery':a, 'vein':b, 'excret':c }for a,b,c in zip(glob.glob(@dataset_dir + '/*/12.nii.gz'), glob.glob(@dataset_dir + '/*/22-.nii.gz'), glob.glob(@dataset_dir + '/*/32-.nii.gz'))]",
12
+ "labels": "$list(glob.glob(@dataset_dir + '/*/merged.nii.gz'))",
13
+ "val_interval": 50,
14
+ "dont_finetune": true,
15
+ "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
16
+ "network_def": {
17
+ "_target_": "SegResNet",
18
+ "in_channels": 3,
19
+ "out_channels": 6,
20
+ "init_filters": 32,
21
+ "upsample_mode": "deconv",
22
+ "dropout_prob": 0.2,
23
+ "norm_name": "group",
24
+ "blocks_down": [
25
+ 1,
26
+ 2,
27
+ 2,
28
+ 4
29
+ ],
30
+ "blocks_up": [
31
+ 1,
32
+ 1,
33
+ 1
34
+ ]
35
+ },
36
+ "network": "$@network_def.to(@device)",
37
+ "loss": {
38
+ "_target_": "DiceLoss",
39
+ "include_background": false,
40
+ "to_onehot_y": true,
41
+ "sigmoid": true,
42
+ "softmax": false,
43
+ "squared_pred": false,
44
+ "jaccard": false,
45
+ "reduction": "mean",
46
+ "smooth_nr": 0.0,
47
+ "smooth_dr": 1e-05,
48
+ "batch": false
49
+ },
50
+ "optimizer": {
51
+ "_target_": "Novograd",
52
+ "params": "$@network.parameters()",
53
+ "lr": 0.001,
54
+ "betas": [
55
+ 0.9,
56
+ 0.98
57
+ ],
58
+ "eps": 1e-08,
59
+ "weight_decay": 0,
60
+ "grad_averaging": false,
61
+ "amsgrad": false
62
+ },
63
+ "train": {
64
+ "deterministic_transforms": [
65
+ {
66
+ "_target_": "LoadImaged",
67
+ "keys": [
68
+ "artery",
69
+ "vein",
70
+ "excret",
71
+ "label"
72
+ ],
73
+ "reader": null,
74
+ "overwriting": false,
75
+ "dtype": "float32",
76
+ "as_closest_canonical": true
77
+ },
78
+ {
79
+ "_target_": "EnsureChannelFirstd",
80
+ "keys": [
81
+ "artery",
82
+ "vein",
83
+ "excret",
84
+ "label"
85
+ ]
86
+ },
87
+ {
88
+ "_target_": "MapLabelValued",
89
+ "keys": "label",
90
+ "orig_labels": [
91
+ 0,
92
+ 1,
93
+ 2,
94
+ 3,
95
+ 4,
96
+ 5,
97
+ 6
98
+ ],
99
+ "target_labels": [
100
+ 0,
101
+ 1,
102
+ 2,
103
+ 3,
104
+ 4,
105
+ 4,
106
+ 5
107
+ ]
108
+ },
109
+ {
110
+ "_target_": "ToTensord",
111
+ "keys": [
112
+ "artery",
113
+ "vein",
114
+ "excret",
115
+ "label"
116
+ ]
117
+ },
118
+ {
119
+ "_target_": "Spacingd",
120
+ "keys": [
121
+ "artery",
122
+ "vein",
123
+ "excret",
124
+ "label"
125
+ ],
126
+ "pixdim": [
127
+ 0.8,
128
+ 0.8,
129
+ 0.8
130
+ ],
131
+ "mode": [
132
+ "bilinear",
133
+ "bilinear",
134
+ "bilinear",
135
+ "nearest"
136
+ ]
137
+ },
138
+ {
139
+ "_target_": "ScaleIntensityRanged",
140
+ "keys": [
141
+ "artery",
142
+ "vein",
143
+ "excret"
144
+ ],
145
+ "a_min": -1000,
146
+ "a_max": 1000,
147
+ "b_min": 0.0,
148
+ "b_max": 1.0,
149
+ "clip": true
150
+ },
151
+ {
152
+ "_target_": "scripts.my_transforms.ConcatImages",
153
+ "keys_merge": [
154
+ "artery",
155
+ "vein",
156
+ "excret"
157
+ ],
158
+ "keys_out": "image"
159
+ },
160
+ {
161
+ "_target_": "ToTensord",
162
+ "keys": [
163
+ "image"
164
+ ]
165
+ }
166
+ ],
167
+ "random_transforms": [
168
+ {
169
+ "_target_": "RandZoomd",
170
+ "keys": [
171
+ "image",
172
+ "label"
173
+ ],
174
+ "prob": 0.3
175
+ },
176
+ {
177
+ "_target_": "RandAxisFlipd",
178
+ "keys": [
179
+ "image",
180
+ "label"
181
+ ],
182
+ "prob": 0.3
183
+ },
184
+ {
185
+ "_target_": "RandRotate90d",
186
+ "keys": [
187
+ "image",
188
+ "label"
189
+ ],
190
+ "prob": 0.3
191
+ },
192
+ {
193
+ "_target_": "RandAdjustContrastd",
194
+ "keys": [
195
+ "image"
196
+ ],
197
+ "prob": 0.5
198
+ },
199
+ {
200
+ "_target_": "RandHistogramShiftd",
201
+ "keys": "image",
202
+ "num_control_points": 10,
203
+ "prob": 0.3
204
+ },
205
+ {
206
+ "_target_": "DivisiblePadd",
207
+ "keys": [
208
+ "image",
209
+ "label"
210
+ ],
211
+ "k": 32
212
+ },
213
+ {
214
+ "_target_": "RandCropByLabelClassesd",
215
+ "keys": [
216
+ "image",
217
+ "label"
218
+ ],
219
+ "label_key": "label",
220
+ "num_classes": 6,
221
+ "spatial_size": [
222
+ 96,
223
+ 96,
224
+ 96
225
+ ],
226
+ "ratios": [
227
+ 1,
228
+ 2,
229
+ 2,
230
+ 3,
231
+ 3,
232
+ 1
233
+ ],
234
+ "num_samples": 4
235
+ }
236
+ ],
237
+ "preprocessing": {
238
+ "_target_": "Compose",
239
+ "transforms": "$@train#deterministic_transforms + @train#random_transforms"
240
+ },
241
+ "dataset": {
242
+ "_target_": "CacheDataset",
243
+ "data": "$[{'label': l, **i} for i, l in zip(@images, @labels)]",
244
+ "transform": "@train#preprocessing",
245
+ "cache_rate": 1.0,
246
+ "num_workers": 4
247
+ },
248
+ "dataloader": {
249
+ "_target_": "DataLoader",
250
+ "dataset": "@train#dataset",
251
+ "batch_size": 1,
252
+ "shuffle": true,
253
+ "num_workers": 2
254
+ },
255
+ "inferer": {
256
+ "_target_": "SimpleInferer"
257
+ },
258
+ "postprocessing": {
259
+ "_target_": "Compose",
260
+ "transforms": [
261
+ {
262
+ "_target_": "Activationsd",
263
+ "keys": "pred",
264
+ "softmax": false,
265
+ "sigmoid": true
266
+ },
267
+ {
268
+ "_target_": "AsDiscreted",
269
+ "keys": [
270
+ "pred",
271
+ "label"
272
+ ],
273
+ "argmax": [
274
+ false,
275
+ false
276
+ ],
277
+ "to_onehot": [
278
+ null,
279
+ 6
280
+ ],
281
+ "threshold": [
282
+ 0.5,
283
+ null
284
+ ]
285
+ },
286
+ {
287
+ "_target_": "SplitChanneld",
288
+ "keys": [
289
+ "pred",
290
+ "label"
291
+ ],
292
+ "output_postfixes": [
293
+ "bck",
294
+ "ar",
295
+ "ve",
296
+ "ur",
297
+ "tu",
298
+ "ki"
299
+ ]
300
+ }
301
+ ]
302
+ },
303
+ "handlers": [
304
+ {
305
+ "_target_": "CheckpointLoader",
306
+ "_disabled_": "@dont_finetune",
307
+ "load_path": "$@ckpt_dir + '/model.pt'",
308
+ "load_dict": {
309
+ "model": "@network"
310
+ }
311
+ },
312
+ {
313
+ "_target_": "ValidationHandler",
314
+ "validator": "@validate#evaluator",
315
+ "epoch_level": true,
316
+ "interval": "@val_interval"
317
+ },
318
+ {
319
+ "_target_": "StatsHandler",
320
+ "tag_name": "train_loss",
321
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
322
+ },
323
+ {
324
+ "_target_": "TensorBoardStatsHandler",
325
+ "log_dir": "@output_dir",
326
+ "tag_name": "train_loss",
327
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
328
+ }
329
+ ],
330
+ "key_metric": {
331
+ "train/mean_dice": {
332
+ "_target_": "MeanDice",
333
+ "include_background": false,
334
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
335
+ }
336
+ },
337
+ "additional_metrics": {
338
+ "train/tu_dice": {
339
+ "_target_": "MeanDice",
340
+ "include_background": true,
341
+ "output_transform": "$monai.handlers.from_engine(['pred_tu', 'label_tu'])"
342
+ }
343
+ },
344
+ "trainer": {
345
+ "_target_": "SupervisedTrainer",
346
+ "max_epochs": 10000,
347
+ "device": "@device",
348
+ "train_data_loader": "@train#dataloader",
349
+ "network": "@network",
350
+ "loss_function": "@loss",
351
+ "optimizer": "@optimizer",
352
+ "inferer": "@train#inferer",
353
+ "postprocessing": "@train#postprocessing",
354
+ "key_train_metric": "@train#key_metric",
355
+ "train_handlers": "@train#handlers",
356
+ "additional_metrics": "@train#additional_metrics",
357
+ "amp": true
358
+ }
359
+ },
360
+ "validate": {
361
+ "preprocessing": {
362
+ "_target_": "Compose",
363
+ "transforms": "$@train#deterministic_transforms"
364
+ },
365
+ "dataset": {
366
+ "_target_": "CacheDataset",
367
+ "data": "$[{'label': l, **i} for i, l in zip(@images, @labels)]",
368
+ "transform": "@validate#preprocessing",
369
+ "cache_rate": 1.0
370
+ },
371
+ "dataloader": {
372
+ "_target_": "DataLoader",
373
+ "dataset": "@validate#dataset",
374
+ "batch_size": 1,
375
+ "shuffle": false,
376
+ "num_workers": 4
377
+ },
378
+ "inferer": {
379
+ "_target_": "SlidingWindowInferer",
380
+ "roi_size": [
381
+ 96,
382
+ 96,
383
+ 96
384
+ ],
385
+ "sw_batch_size": 4,
386
+ "overlap": 0.25
387
+ },
388
+ "postprocessing": {
389
+ "_target_": "Compose",
390
+ "transforms": [
391
+ {
392
+ "_target_": "Invertd",
393
+ "transform": "%validate#preprocessing",
394
+ "device": "@device",
395
+ "keys": [
396
+ "pred",
397
+ "label"
398
+ ],
399
+ "orig_keys": [
400
+ "artery",
401
+ "label"
402
+ ],
403
+ "meta_keys": [
404
+ "pred_meta_dict",
405
+ "label_meta_dict"
406
+ ],
407
+ "nearest_interp": [
408
+ false,
409
+ true
410
+ ],
411
+ "to_tensor": true
412
+ },
413
+ "%train#postprocessing#transforms#0",
414
+ "%train#postprocessing#transforms#1",
415
+ "%train#postprocessing#transforms#2"
416
+ ]
417
+ },
418
+ "handlers": [
419
+ {
420
+ "_target_": "StatsHandler",
421
+ "iteration_log": false
422
+ },
423
+ {
424
+ "_target_": "TensorBoardStatsHandler",
425
+ "log_dir": "@output_dir",
426
+ "iteration_log": false
427
+ },
428
+ {
429
+ "_target_": "CheckpointSaver",
430
+ "save_dir": "@ckpt_dir",
431
+ "save_dict": {
432
+ "model": "@network"
433
+ },
434
+ "save_key_metric": true,
435
+ "key_metric_filename": "model.pt"
436
+ }
437
+ ],
438
+ "key_metric": {
439
+ "val_mean_dice": {
440
+ "_target_": "MeanDice",
441
+ "include_background": false,
442
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
443
+ }
444
+ },
445
+ "additional_metrics": {
446
+ "ar/dice": {
447
+ "_target_": "MeanDice",
448
+ "include_background": false,
449
+ "output_transform": "$monai.handlers.from_engine(['pred_ar', 'label_ar'])"
450
+ },
451
+ "ve/dice": {
452
+ "_target_": "MeanDice",
453
+ "include_background": false,
454
+ "output_transform": "$monai.handlers.from_engine(['pred_ve', 'label_ve'])"
455
+ },
456
+ "ur/dice": {
457
+ "_target_": "MeanDice",
458
+ "include_background": false,
459
+ "output_transform": "$monai.handlers.from_engine(['pred_ur', 'label_ur'])"
460
+ },
461
+ "ki/dice": {
462
+ "_target_": "MeanDice",
463
+ "include_background": false,
464
+ "output_transform": "$monai.handlers.from_engine(['pred_ki', 'label_ki'])"
465
+ },
466
+ "tu/dice": {
467
+ "_target_": "MeanDice",
468
+ "include_background": false,
469
+ "output_transform": "$monai.handlers.from_engine(['pred_tu', 'label_tu'])"
470
+ },
471
+ "tu/haunsdorff": {
472
+ "_target_": "HausdorffDistance",
473
+ "include_background": false,
474
+ "output_transform": "$monai.handlers.from_engine(['pred_tu', 'label_tu'])"
475
+ },
476
+ "tu/surface": {
477
+ "_target_": "SurfaceDistance",
478
+ "include_background": false,
479
+ "output_transform": "$monai.handlers.from_engine(['pred_tu', 'label_tu'])"
480
+ }
481
+ },
482
+ "evaluator": {
483
+ "_target_": "SupervisedEvaluator",
484
+ "device": "@device",
485
+ "val_data_loader": "@validate#dataloader",
486
+ "network": "@network",
487
+ "inferer": "@validate#inferer",
488
+ "postprocessing": "@validate#postprocessing",
489
+ "key_val_metric": "@validate#key_metric",
490
+ "additional_metrics": "@validate#additional_metrics",
491
+ "val_handlers": "@validate#handlers",
492
+ "amp": true
493
+ }
494
+ },
495
+ "training": [
496
+ "$monai.utils.set_determinism(seed=42)",
497
+ "$setattr(torch.backends.cudnn, 'benchmark', True)",
498
+ "$@train#trainer.run()"
499
+ ]
500
+ }
docs/README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Model Title
2
+ Renal structures CECT segmentation
3
+
4
+ ### **Authors**
5
+ Ivan Chernenkiy, Michael Chernenkiy, Dmitry Fiev, Evgeny Sirota, Center for Neural Network Technologies / Institute of Urology and Human Reproductive Systems / Sechenov First Moscow State Medical University
6
+
7
+ ### **Tags**
8
+ Segmentation, CT, CECT, Kidney, Renal, Supervised
9
+
10
+ ## **Model Description**
11
+ The model is the SegResNet architecture[1] for volumetric (3D) renal structures segmentation. Input is artery, vein, excretory phases after mutual registration and concatenated to 3 channel 3D tensor.
12
+
13
+
14
+ ## **Data**
15
+ DICOM data from 41 patients with kidney neoplasms were used [2]. The images and segmentation data are available under a CC BY-NC-SA 4.0 license. Data included all phases of contrast-enhanced multispiral computed tomography. We split the data: 32 observations for the training set and 9 – for the validation set. At the labeling stage, the arterial, venous, and excretory phases were taken, affine registration was performed to jointly match the location of the kidneys, and noise was removed using a median filter and a non-local means filter. Validation set ip published to Yandex.Disk. You can download via [link](https://disk.yandex.ru/d/pWEKt6D3qi3-aw) or use following command:
16
+ ```bash
17
+ python -m monai.bundle run download_data --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
18
+ ```
19
+
20
+ **NB**: underlying data is in LPS orientation. IF! you want to test model on your own data, reorient it from RAS to LPS with `Orientation` transform. You can see example of preprocessing pipeline in `inference.json` file of this bundle.
21
+
22
+ #### **Preprocessing**
23
+ Images are (1) croped to kidney region, all (artery,vein,excret) phases are (2) [registered](https://simpleitk.readthedocs.io/en/master/registrationOverview.html#lbl-registration-overview) with affine transform, noise removed with (3) median and (4) non-local means filter. After that, images are (5) resampled to (0.8,0.8,0.8) density and intesities are (6) scaled from [-1000,1000] to [0,1] range.
24
+
25
+ ## **Performance**
26
+ On the validation subset, the values of the Dice score of the SegResNet architecture were: 0.89 for the normal parenchyma of the kidney, 0.58 for the kidney neoplasms, 0.86 for arteries, 0.80 for veins, 0.80 for ureters.
27
+
28
+ When compared with the nnU-Net model, which was trained on KiTS 21 dataset, the Dice score was greater for the kidney parenchyma in SegResNet – 0.89 compared to three model variants: lowres – 0.69, fullres – 0.70, cascade – 0.69. At the same time, for the neoplasms of the parenchyma of the kidney, the Dice score was comparable: for SegResNet – 0.58, for nnU-Net fullres – 0.59; lowres and cascade had lower Dice score of 0.37 and 0.45, respectively. To reproduce, visit - https://github.com/blacky-i/nephro-segmentation
29
+
30
+
31
+ ## **Additional Usage Steps**
32
+
33
+ #### Execute training:
34
+
35
+ ```bash
36
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json
37
+ ```
38
+ Expected result: finished, Training process started
39
+
40
+
41
+ #### Execute training with finetuning
42
+ ```bash
43
+ python -m monai.bundle run training --dont_finetune false --meta_file configs/metadata.json --config_file configs/train.json
44
+ ```
45
+ Expected result: finished, Training process started, model variables are restored
46
+
47
+ #### Execute validation:
48
+
49
+ Download validation data (described in [Data](#data) section).
50
+
51
+ With provided model weights mean dice score is expected to be ~0.78446.
52
+
53
+ ##### Run validation script:
54
+ ```bash
55
+ python -m monai.bundle run evaluate --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
56
+ ```
57
+ Expected result: finished, `Key metric: val_mean_dice best value: ...` is printed.
58
+
59
+ ## **System Configuration**
60
+ The model was trained for 10000 epochs on 2 RTX2080Ti GPUs with [SmartCacheDataset](https://docs.monai.io/en/stable/data.html#smartcachedataset). This takes 1 days and 2 hours, with 4 images per GPU.
61
+ Training progress is available on [tensorboard.dev](https://tensorboard.dev/experiment/VlEMjLdURH6SyFp216dFBg)
62
+
63
+ To perform training in minimal settings, at least one 12GB-memory GPU is required.
64
+ Actual Model Input: 96 x 96 x 96
65
+
66
+ ## **Limitations**
67
+ For developmental purposes only and cannot be used directly for clinical procedures.
68
+
69
+ ## **Citation Info**
70
+ ```
71
+ @article{chernenkiy2023segmentation,
72
+ title={Segmentation of renal structures based on contrast computed tomography scans using a convolutional neural network},
73
+ author={Chernenkiy, IМ and Chernenkiy, MM and Fiev, DN and Sirota, ES},
74
+ journal={Sechenov Medical Journal},
75
+ volume={14},
76
+ number={1},
77
+ pages={39--49},
78
+ year={2023}
79
+ }
80
+ ```
81
+
82
+ ## **References**
83
+
84
+ [1] Myronenko, A. (2019). 3D MRI Brain Tumor Segmentation Using Autoencoder Regularization. In: Crimi, A., Bakas, S., Kuijf, H., Keyvan, F., Reyes, M., van Walsum, T. (eds) Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries. BrainLes 2018. Lecture Notes in Computer Science(), vol 11384. Springer, Cham. https://doi.org/10.1007/978-3-030-11726-9_28
85
+
86
+ [2] Chernenkiy, I. М., et al. "Segmentation of renal structures based on contrast computed tomography scans using a convolutional neural network." Sechenov Medical Journal 14.1 (2023): 39-49.https://doi.org/10.47093/2218-7332.2023.14.1.39-49
87
+
88
+ #### **Tests used for bundle checking**
89
+
90
+ Checking with ci script file
91
+ ```bash
92
+ python ci/verify_bundle.py -b renalStructures_CECT_segmentation -p models
93
+ ```
94
+ Expected result: passed, model.pt file downloaded
95
+
96
+
97
+ Checking downloading validation data file
98
+ ```bash
99
+ cd models/renalStructures_CECT_segmentation
100
+ python -m monai.bundle run download_data --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
101
+ ```
102
+ Expected result: finished, `data/` folder is created and filled with images.
103
+
104
+
105
+ Checking evaluation script
106
+ ```bash
107
+ python -m monai.bundle run evaluate --meta_file configs/metadata.json --config_file "['configs/train.json', 'configs/evaluate.json']"
108
+ ```
109
+ Expected result: finished, `Key metric: val_mean_dice best value: ...` is printed.
110
+
111
+
112
+ Checking train script
113
+ ```bash
114
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json
115
+ ```
116
+ Expected result: finished, Training process started
117
+
118
+
119
+ Checking train script with finetuning
120
+ ```bash
121
+ python -m monai.bundle run training --dont_finetune false --meta_file configs/metadata.json --config_file configs/train.json
122
+ ```
123
+ Expected result: finished, Training process started, model variables are restored
124
+
125
+ Checking inference script
126
+ ```bash
127
+ python -m monai.bundle run inference --meta_file configs/metadata.json --config_file configs/inference.json
128
+ ```
129
+ Expected result: finished, in `eval` folder masks are created
130
+
131
+ Check unit test with script:
132
+ ```bash
133
+ python ci/unit_tests/runner.py --b renalStructures_CECT_segmentation
134
+ ```
docs/data_license.txt ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Third Party Licenses
2
+ -----------------------------------------------------------------------
3
+
4
+ /*********************************************************************/
5
+ i. Validation dataset of renal structures
6
+ https://www.med.upenn.edu/sbia/brats2018/data.html
7
+ /*********************************************************************/
8
+
9
+ Data Usage Agreement / Citations
10
+ The data is under a CC BY-NC-SA (Attribution-NonCommercial-ShareAlike)
11
+ license.
12
+ You are free to use and/or refer in your own research, provided that
13
+ you always cite the following manuscript:
14
+
15
+ [1] Chernenkiy, I. М., Chernenkiy, M. M., Fiev, D. N., & Sirota, E. S.
16
+ "Segmentation of renal structures based on contrast computed tomography
17
+ scans using a convolutional neural network." Sechenov Medical Journal
18
+ 14.1 (2023): 39-49.
19
+ DOI: https://doi.org/10.47093/2218-7332.2023.14.1.39-49
20
+
21
+ /*********************************************************************/
22
+ i.License text
23
+ /*********************************************************************/
24
+
25
+ =======================================================================
26
+
27
+ Attribution-NonCommercial-ShareAlike 4.0 International
28
+
29
+ =======================================================================
30
+
31
+ Creative Commons Corporation ("Creative Commons") is not a law firm and
32
+ does not provide legal services or legal advice. Distribution of
33
+ Creative Commons public licenses does not create a lawyer-client or
34
+ other relationship. Creative Commons makes its licenses and related
35
+ information available on an "as-is" basis. Creative Commons gives no
36
+ warranties regarding its licenses, any material licensed under their
37
+ terms and conditions, or any related information. Creative Commons
38
+ disclaims all liability for damages resulting from their use to the
39
+ fullest extent possible.
40
+
41
+ Using Creative Commons Public Licenses
42
+
43
+ Creative Commons public licenses provide a standard set of terms and
44
+ conditions that creators and other rights holders may use to share
45
+ original works of authorship and other material subject to copyright
46
+ and certain other rights specified in the public license below. The
47
+ following considerations are for informational purposes only, are not
48
+ exhaustive, and do not form part of our licenses.
49
+
50
+ Considerations for licensors: Our public licenses are
51
+ intended for use by those authorized to give the public
52
+ permission to use material in ways otherwise restricted by
53
+ copyright and certain other rights. Our licenses are
54
+ irrevocable. Licensors should read and understand the terms
55
+ and conditions of the license they choose before applying it.
56
+ Licensors should also secure all rights necessary before
57
+ applying our licenses so that the public can reuse the
58
+ material as expected. Licensors should clearly mark any
59
+ material not subject to the license. This includes other CC-
60
+ licensed material, or material used under an exception or
61
+ limitation to copyright. More considerations for licensors:
62
+ wiki.creativecommons.org/Considerations_for_licensors
63
+
64
+ Considerations for the public: By using one of our public
65
+ licenses, a licensor grants the public permission to use the
66
+ licensed material under specified terms and conditions. If
67
+ the licensor's permission is not necessary for any reason--for
68
+ example, because of any applicable exception or limitation to
69
+ copyright--then that use is not regulated by the license. Our
70
+ licenses grant only permissions under copyright and certain
71
+ other rights that a licensor has authority to grant. Use of
72
+ the licensed material may still be restricted for other
73
+ reasons, including because others have copyright or other
74
+ rights in the material. A licensor may make special requests,
75
+ such as asking that all changes be marked or described.
76
+ Although not required by our licenses, you are encouraged to
77
+ respect those requests where reasonable. More considerations
78
+ for the public:
79
+ wiki.creativecommons.org/Considerations_for_licensees
80
+
81
+ =======================================================================
82
+
83
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
84
+ Public License
85
+
86
+ By exercising the Licensed Rights (defined below), You accept and agree
87
+ to be bound by the terms and conditions of this Creative Commons
88
+ Attribution-NonCommercial-ShareAlike 4.0 International Public License
89
+ ("Public License"). To the extent this Public License may be
90
+ interpreted as a contract, You are granted the Licensed Rights in
91
+ consideration of Your acceptance of these terms and conditions, and the
92
+ Licensor grants You such rights in consideration of benefits the
93
+ Licensor receives from making the Licensed Material available under
94
+ these terms and conditions.
95
+
96
+
97
+ Section 1 -- Definitions.
98
+
99
+ a. Adapted Material means material subject to Copyright and Similar
100
+ Rights that is derived from or based upon the Licensed Material
101
+ and in which the Licensed Material is translated, altered,
102
+ arranged, transformed, or otherwise modified in a manner requiring
103
+ permission under the Copyright and Similar Rights held by the
104
+ Licensor. For purposes of this Public License, where the Licensed
105
+ Material is a musical work, performance, or sound recording,
106
+ Adapted Material is always produced where the Licensed Material is
107
+ synched in timed relation with a moving image.
108
+
109
+ b. Adapter's License means the license You apply to Your Copyright
110
+ and Similar Rights in Your contributions to Adapted Material in
111
+ accordance with the terms and conditions of this Public License.
112
+
113
+ c. BY-NC-SA Compatible License means a license listed at
114
+ creativecommons.org/compatiblelicenses, approved by Creative
115
+ Commons as essentially the equivalent of this Public License.
116
+
117
+ d. Copyright and Similar Rights means copyright and/or similar rights
118
+ closely related to copyright including, without limitation,
119
+ performance, broadcast, sound recording, and Sui Generis Database
120
+ Rights, without regard to how the rights are labeled or
121
+ categorized. For purposes of this Public License, the rights
122
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
123
+ Rights.
124
+
125
+ e. Effective Technological Measures means those measures that, in the
126
+ absence of proper authority, may not be circumvented under laws
127
+ fulfilling obligations under Article 11 of the WIPO Copyright
128
+ Treaty adopted on December 20, 1996, and/or similar international
129
+ agreements.
130
+
131
+ f. Exceptions and Limitations means fair use, fair dealing, and/or
132
+ any other exception or limitation to Copyright and Similar Rights
133
+ that applies to Your use of the Licensed Material.
134
+
135
+ g. License Elements means the license attributes listed in the name
136
+ of a Creative Commons Public License. The License Elements of this
137
+ Public License are Attribution, NonCommercial, and ShareAlike.
138
+
139
+ h. Licensed Material means the artistic or literary work, database,
140
+ or other material to which the Licensor applied this Public
141
+ License.
142
+
143
+ i. Licensed Rights means the rights granted to You subject to the
144
+ terms and conditions of this Public License, which are limited to
145
+ all Copyright and Similar Rights that apply to Your use of the
146
+ Licensed Material and that the Licensor has authority to license.
147
+
148
+ j. Licensor means the individual(s) or entity(ies) granting rights
149
+ under this Public License.
150
+
151
+ k. NonCommercial means not primarily intended for or directed towards
152
+ commercial advantage or monetary compensation. For purposes of
153
+ this Public License, the exchange of the Licensed Material for
154
+ other material subject to Copyright and Similar Rights by digital
155
+ file-sharing or similar means is NonCommercial provided there is
156
+ no payment of monetary compensation in connection with the
157
+ exchange.
158
+
159
+ l. Share means to provide material to the public by any means or
160
+ process that requires permission under the Licensed Rights, such
161
+ as reproduction, public display, public performance, distribution,
162
+ dissemination, communication, or importation, and to make material
163
+ available to the public including in ways that members of the
164
+ public may access the material from a place and at a time
165
+ individually chosen by them.
166
+
167
+ m. Sui Generis Database Rights means rights other than copyright
168
+ resulting from Directive 96/9/EC of the European Parliament and of
169
+ the Council of 11 March 1996 on the legal protection of databases,
170
+ as amended and/or succeeded, as well as other essentially
171
+ equivalent rights anywhere in the world.
172
+
173
+ n. You means the individual or entity exercising the Licensed Rights
174
+ under this Public License. Your has a corresponding meaning.
175
+
176
+
177
+ Section 2 -- Scope.
178
+
179
+ a. License grant.
180
+
181
+ 1. Subject to the terms and conditions of this Public License,
182
+ the Licensor hereby grants You a worldwide, royalty-free,
183
+ non-sublicensable, non-exclusive, irrevocable license to
184
+ exercise the Licensed Rights in the Licensed Material to:
185
+
186
+ a. reproduce and Share the Licensed Material, in whole or
187
+ in part, for NonCommercial purposes only; and
188
+
189
+ b. produce, reproduce, and Share Adapted Material for
190
+ NonCommercial purposes only.
191
+
192
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
193
+ Exceptions and Limitations apply to Your use, this Public
194
+ License does not apply, and You do not need to comply with
195
+ its terms and conditions.
196
+
197
+ 3. Term. The term of this Public License is specified in Section
198
+ 6(a).
199
+
200
+ 4. Media and formats; technical modifications allowed. The
201
+ Licensor authorizes You to exercise the Licensed Rights in
202
+ all media and formats whether now known or hereafter created,
203
+ and to make technical modifications necessary to do so. The
204
+ Licensor waives and/or agrees not to assert any right or
205
+ authority to forbid You from making technical modifications
206
+ necessary to exercise the Licensed Rights, including
207
+ technical modifications necessary to circumvent Effective
208
+ Technological Measures. For purposes of this Public License,
209
+ simply making modifications authorized by this Section 2(a)
210
+ (4) never produces Adapted Material.
211
+
212
+ 5. Downstream recipients.
213
+
214
+ a. Offer from the Licensor -- Licensed Material. Every
215
+ recipient of the Licensed Material automatically
216
+ receives an offer from the Licensor to exercise the
217
+ Licensed Rights under the terms and conditions of this
218
+ Public License.
219
+
220
+ b. Additional offer from the Licensor -- Adapted Material.
221
+ Every recipient of Adapted Material from You
222
+ automatically receives an offer from the Licensor to
223
+ exercise the Licensed Rights in the Adapted Material
224
+ under the conditions of the Adapter's License You apply.
225
+
226
+ c. No downstream restrictions. You may not offer or impose
227
+ any additional or different terms or conditions on, or
228
+ apply any Effective Technological Measures to, the
229
+ Licensed Material if doing so restricts exercise of the
230
+ Licensed Rights by any recipient of the Licensed
231
+ Material.
232
+
233
+ 6. No endorsement. Nothing in this Public License constitutes or
234
+ may be construed as permission to assert or imply that You
235
+ are, or that Your use of the Licensed Material is, connected
236
+ with, or sponsored, endorsed, or granted official status by,
237
+ the Licensor or others designated to receive attribution as
238
+ provided in Section 3(a)(1)(A)(i).
239
+
240
+ b. Other rights.
241
+
242
+ 1. Moral rights, such as the right of integrity, are not
243
+ licensed under this Public License, nor are publicity,
244
+ privacy, and/or other similar personality rights; however, to
245
+ the extent possible, the Licensor waives and/or agrees not to
246
+ assert any such rights held by the Licensor to the limited
247
+ extent necessary to allow You to exercise the Licensed
248
+ Rights, but not otherwise.
249
+
250
+ 2. Patent and trademark rights are not licensed under this
251
+ Public License.
252
+
253
+ 3. To the extent possible, the Licensor waives any right to
254
+ collect royalties from You for the exercise of the Licensed
255
+ Rights, whether directly or through a collecting society
256
+ under any voluntary or waivable statutory or compulsory
257
+ licensing scheme. In all other cases the Licensor expressly
258
+ reserves any right to collect such royalties, including when
259
+ the Licensed Material is used other than for NonCommercial
260
+ purposes.
261
+
262
+
263
+ Section 3 -- License Conditions.
264
+
265
+ Your exercise of the Licensed Rights is expressly made subject to the
266
+ following conditions.
267
+
268
+ a. Attribution.
269
+
270
+ 1. If You Share the Licensed Material (including in modified
271
+ form), You must:
272
+
273
+ a. retain the following if it is supplied by the Licensor
274
+ with the Licensed Material:
275
+
276
+ i. identification of the creator(s) of the Licensed
277
+ Material and any others designated to receive
278
+ attribution, in any reasonable manner requested by
279
+ the Licensor (including by pseudonym if
280
+ designated);
281
+
282
+ ii. a copyright notice;
283
+
284
+ iii. a notice that refers to this Public License;
285
+
286
+ iv. a notice that refers to the disclaimer of
287
+ warranties;
288
+
289
+ v. a URI or hyperlink to the Licensed Material to the
290
+ extent reasonably practicable;
291
+
292
+ b. indicate if You modified the Licensed Material and
293
+ retain an indication of any previous modifications; and
294
+
295
+ c. indicate the Licensed Material is licensed under this
296
+ Public License, and include the text of, or the URI or
297
+ hyperlink to, this Public License.
298
+
299
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
300
+ reasonable manner based on the medium, means, and context in
301
+ which You Share the Licensed Material. For example, it may be
302
+ reasonable to satisfy the conditions by providing a URI or
303
+ hyperlink to a resource that includes the required
304
+ information.
305
+ 3. If requested by the Licensor, You must remove any of the
306
+ information required by Section 3(a)(1)(A) to the extent
307
+ reasonably practicable.
308
+
309
+ b. ShareAlike.
310
+
311
+ In addition to the conditions in Section 3(a), if You Share
312
+ Adapted Material You produce, the following conditions also apply.
313
+
314
+ 1. The Adapter's License You apply must be a Creative Commons
315
+ license with the same License Elements, this version or
316
+ later, or a BY-NC-SA Compatible License.
317
+
318
+ 2. You must include the text of, or the URI or hyperlink to, the
319
+ Adapter's License You apply. You may satisfy this condition
320
+ in any reasonable manner based on the medium, means, and
321
+ context in which You Share Adapted Material.
322
+
323
+ 3. You may not offer or impose any additional or different terms
324
+ or conditions on, or apply any Effective Technological
325
+ Measures to, Adapted Material that restrict exercise of the
326
+ rights granted under the Adapter's License You apply.
327
+
328
+
329
+ Section 4 -- Sui Generis Database Rights.
330
+
331
+ Where the Licensed Rights include Sui Generis Database Rights that
332
+ apply to Your use of the Licensed Material:
333
+
334
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
335
+ to extract, reuse, reproduce, and Share all or a substantial
336
+ portion of the contents of the database for NonCommercial purposes
337
+ only;
338
+
339
+ b. if You include all or a substantial portion of the database
340
+ contents in a database in which You have Sui Generis Database
341
+ Rights, then the database in which You have Sui Generis Database
342
+ Rights (but not its individual contents) is Adapted Material,
343
+ including for purposes of Section 3(b); and
344
+
345
+ c. You must comply with the conditions in Section 3(a) if You Share
346
+ all or a substantial portion of the contents of the database.
347
+
348
+ For the avoidance of doubt, this Section 4 supplements and does not
349
+ replace Your obligations under this Public License where the Licensed
350
+ Rights include other Copyright and Similar Rights.
351
+
352
+
353
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
354
+
355
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
356
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
357
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
358
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
359
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
360
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
361
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
362
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
363
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
364
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
365
+
366
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
367
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
368
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
369
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
370
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
371
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
372
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
373
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
374
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
375
+
376
+ c. The disclaimer of warranties and limitation of liability provided
377
+ above shall be interpreted in a manner that, to the extent
378
+ possible, most closely approximates an absolute disclaimer and
379
+ waiver of all liability.
380
+
381
+
382
+ Section 6 -- Term and Termination.
383
+
384
+ a. This Public License applies for the term of the Copyright and
385
+ Similar Rights licensed here. However, if You fail to comply with
386
+ this Public License, then Your rights under this Public License
387
+ terminate automatically.
388
+
389
+ b. Where Your right to use the Licensed Material has terminated under
390
+ Section 6(a), it reinstates:
391
+
392
+ 1. automatically as of the date the violation is cured, provided
393
+ it is cured within 30 days of Your discovery of the
394
+ violation; or
395
+
396
+ 2. upon express reinstatement by the Licensor.
397
+
398
+ For the avoidance of doubt, this Section 6(b) does not affect any
399
+ right the Licensor may have to seek remedies for Your violations
400
+ of this Public License.
401
+
402
+ c. For the avoidance of doubt, the Licensor may also offer the
403
+ Licensed Material under separate terms or conditions or stop
404
+ distributing the Licensed Material at any time; however, doing so
405
+ will not terminate this Public License.
406
+
407
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
408
+ License.
409
+
410
+
411
+ Section 7 -- Other Terms and Conditions.
412
+
413
+ a. The Licensor shall not be bound by any additional or different
414
+ terms or conditions communicated by You unless expressly agreed.
415
+
416
+ b. Any arrangements, understandings, or agreements regarding the
417
+ Licensed Material not stated herein are separate from and
418
+ independent of the terms and conditions of this Public License.
419
+
420
+
421
+ Section 8 -- Interpretation.
422
+
423
+ a. For the avoidance of doubt, this Public License does not, and
424
+ shall not be interpreted to, reduce, limit, restrict, or impose
425
+ conditions on any use of the Licensed Material that could lawfully
426
+ be made without permission under this Public License.
427
+
428
+ b. To the extent possible, if any provision of this Public License is
429
+ deemed unenforceable, it shall be automatically reformed to the
430
+ minimum extent necessary to make it enforceable. If the provision
431
+ cannot be reformed, it shall be severed from this Public License
432
+ without affecting the enforceability of the remaining terms and
433
+ conditions.
434
+
435
+ c. No term or condition of this Public License will be waived and no
436
+ failure to comply consented to unless expressly agreed to by the
437
+ Licensor.
438
+
439
+ d. Nothing in this Public License constitutes or may be interpreted
440
+ as a limitation upon, or waiver of, any privileges and immunities
441
+ that apply to the Licensor or You, including from the legal
442
+ processes of any jurisdiction or authority.
443
+
444
+ =======================================================================
445
+
446
+ Creative Commons is not a party to its public
447
+ licenses. Notwithstanding, Creative Commons may elect to apply one of
448
+ its public licenses to material it publishes and in those instances
449
+ will be considered the “Licensor.” The text of the Creative Commons
450
+ public licenses is dedicated to the public domain under the CC0 Public
451
+ Domain Dedication. Except for the limited purpose of indicating that
452
+ material is shared under a Creative Commons public license or as
453
+ otherwise permitted by the Creative Commons policies published at
454
+ creativecommons.org/policies, Creative Commons does not authorize the
455
+ use of the trademark "Creative Commons" or any other trademark or logo
456
+ of Creative Commons without its prior written consent including,
457
+ without limitation, in connection with any unauthorized modifications
458
+ to any of its public licenses or any other arrangements,
459
+ understandings, or agreements concerning use of licensed material. For
460
+ the avoidance of doubt, this paragraph does not form part of the
461
+ public licenses.
462
+
463
+ Creative Commons may be contacted at creativecommons.org.
models/model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef934ae5b6fdf9a19b83ab9ec28b64d63dca43aea8ef3e177724c3076170a21f
3
+ size 75925274
scripts/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ from .download_data import download_cect_data
2
+ from .my_transforms import ConcatImages
scripts/download_data.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ import os
4
+ import sys
5
+ import threading
6
+ import time
7
+ import zipfile
8
+ from urllib.parse import urlencode
9
+ from urllib.request import urlopen, urlretrieve
10
+
11
+
12
+ # https://stackoverflow.com/a/39504463
13
+ class Spinner:
14
+ busy = False
15
+ delay = 0.1
16
+
17
+ @staticmethod
18
+ def spinning_cursor():
19
+ while 1:
20
+ for cursor in "|/-\\":
21
+ yield cursor
22
+
23
+ def __init__(self, delay=None):
24
+ self.spinner_generator = self.spinning_cursor()
25
+ if delay and float(delay):
26
+ self.delay = delay
27
+
28
+ def spinner_task(self):
29
+ while self.busy:
30
+ sys.stdout.write(next(self.spinner_generator))
31
+ sys.stdout.flush()
32
+ time.sleep(self.delay)
33
+ sys.stdout.write("\b")
34
+ sys.stdout.flush()
35
+
36
+ def __enter__(self):
37
+ self.busy = True
38
+ threading.Thread(target=self.spinner_task).start()
39
+
40
+ def __exit__(self, exception, value, tb):
41
+ self.busy = False
42
+ time.sleep(self.delay)
43
+ if exception is not None:
44
+ return False
45
+
46
+
47
+ def download_cect_data(bundle_root: str = "."):
48
+ base_url = "https://cloud-api.yandex.net/v1/disk/public/resources/download?"
49
+ public_key = "https://disk.yandex.ru/d/pWEKt6D3qi3-aw"
50
+
51
+ url = base_url + urlencode(dict(public_key=public_key))
52
+ response = urlopen(url)
53
+ filepath = "AVUCTK_cases.zip"
54
+ if not os.path.exists(os.path.join(bundle_root, filepath)):
55
+ with urlopen(url) as response:
56
+ code = response.getcode()
57
+ if code == 200:
58
+ download_url = json.loads(response.read())["href"]
59
+ print("Downloading file...")
60
+ with Spinner():
61
+ urlretrieve(download_url, filepath)
62
+ else:
63
+ raise RuntimeError(
64
+ f"Download of file from {url} to {filepath} failed due to network issue or denied permission."
65
+ )
66
+ else:
67
+ logging.info("zipfile exists, skipping download")
68
+ with zipfile.ZipFile(os.path.join(bundle_root, filepath), "r") as zip_ref:
69
+ zip_ref.extractall()
scripts/my_transforms.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import torch
3
+ from monai.transforms import InvertibleTransform
4
+ from monai.transforms.transform import MapTransform
5
+
6
+
7
+ class ConcatImages(MapTransform, InvertibleTransform):
8
+ def __init__(self, keys_merge, keys_out, allow_missing_keys=True):
9
+ self.keys_merge = keys_merge
10
+ self.keys_out = keys_out
11
+ self.key_target_meta = keys_merge[0] + "_meta_dict"
12
+ self.allow_missing_keys = allow_missing_keys
13
+
14
+ def __call__(self, data):
15
+ if isinstance(data, list):
16
+ for data_row in data:
17
+ data_row[self.keys_out] = np.concatenate([data_row[key] for key in self.keys_merge])
18
+ data_row[self.keys_out + "_meta_dict"] = data_row[self.key_target_meta]
19
+ else:
20
+ data[self.keys_out] = np.concatenate([data[key] for key in self.keys_merge])
21
+ data[self.keys_out + "_meta_dict"] = data[self.key_target_meta]
22
+ return data
23
+
24
+ def inverse(self, data):
25
+ return data
26
+
27
+
28
+ class MergeClassesd(MapTransform):
29
+ def __call__(self, data):
30
+ for key in self.keys:
31
+ if key in data:
32
+ num_classes = data[key].size(-4)
33
+ device = data[key].device
34
+ merged = None
35
+ for channel in data[key].squeeze() * torch.tensor(list(range(num_classes)), device=device).view(
36
+ -1, 1, 1, 1
37
+ ):
38
+ imgvol = channel
39
+ if merged is not None:
40
+ merged = merged + imgvol * ~((merged != 0) & (imgvol != 0))
41
+ else:
42
+ merged = imgvol
43
+ data[key] = merged.unsqueeze(0)
44
+ elif not self.allow_missing_keys:
45
+ raise KeyError(
46
+ f"Key `{key}` of transform `{self.__class__.__name__}` was missing in the data"
47
+ " and allow_missing_keys==False."
48
+ )
49
+ return data