-
Notifications
You must be signed in to change notification settings - Fork 737
[WIP] 486 Add example model package #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fefa39a
[DLMED] add folder structure
Nic-Ma 97ebc38
[DLMED] add more components
Nic-Ma 1c56a47
[DLMED] add changelog
Nic-Ma 607c817
[DLMED] add export logic
Nic-Ma e87bc37
[DLMED] add inference logic
Nic-Ma a6e282d
[DLMED] update to pre / post processing according to Wenqi's comments
Nic-Ma 60aa6ab
Merge branch 'master' into 486-add-model-package
Nic-Ma 21e415f
Merge branch 'master' into 486-add-model-package
Nic-Ma 0a88da1
[DLMED] update according to comments
Nic-Ma 88b13ec
Merge branch 'master' into 486-add-model-package
Nic-Ma 1b01dad
[DLMED] add more features
Nic-Ma fab729f
[DLMED] add more materials
Nic-Ma fa5dbf0
[DLMED] update according to discussion
Nic-Ma d7eb155
Merge branch 'master' into 486-add-model-package
Nic-Ma 918a4bd
[DLMED] update according to Eric's suggestion
Nic-Ma c385605
[DLMED] add config schema example
Nic-Ma a6e9280
Merge branch 'master' into 486-add-model-package
Nic-Ma 826192e
[DLMED] network verification example
Nic-Ma 0890d38
[DLMED] change the "override" example to a separate MMAR example
Nic-Ma 1ccb783
[DLMED] update according to comments
Nic-Ma 0171768
[DLMED] refine override example
Nic-Ma c5dc8be
[DLMED] add image data type
Nic-Ma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
python -m monai.apps.mmar.export | ||
--weights ../models/model.pt | ||
--config ../configs/inference.json | ||
--meta ../configs/metadata.json |
3 changes: 3 additions & 0 deletions
3
modules/model_package/spleen_segmentation/commands/inference.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
python -m monai.apps.mmar.inference.py | ||
--config ../configs/inference.json | ||
--meta ../configs/metadata.json |
3 changes: 3 additions & 0 deletions
3
modules/model_package/spleen_segmentation/commands/schema_check.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
python -m monai.apps.mmar.verify_json.py | ||
--schema_id metadata | ||
--config ../configs/metadata.json |
3 changes: 3 additions & 0 deletions
3
modules/model_package/spleen_segmentation/commands/verify_network.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
python -m monai.apps.mmar.verify_network.py | ||
--config ../configs/inference.json | ||
--meta ../configs/metadata.json |
162 changes: 162 additions & 0 deletions
162
modules/model_package/spleen_segmentation/configs/inference.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"multi_gpu": false, | ||
"amp": true, | ||
"model": "$monai.data.load_net_with_metadata('../models/model.ts')[0]", | ||
"network": { | ||
"<name>": "UNet", | ||
"<args>": { | ||
"spatial_dims": 3, | ||
"in_channels": "@network_data_format#inputs#image#num_channels", | ||
"out_channels": "@network_data_format#outputs#pred#num_channels", | ||
"channels": [16, 32, 64, 128, 256], | ||
"strides": [2, 2, 2, 2], | ||
"num_res_units": 2, | ||
"norm": "batch" | ||
} | ||
}, | ||
"preprocessing": [ | ||
{ | ||
"<name>": "LoadImaged", | ||
"<args>": { | ||
"keys": "image" | ||
} | ||
}, | ||
{ | ||
"<name>": "Spacingd", | ||
"<args>": { | ||
"keys": "image", | ||
"pixdim": [1.5, 1.5, 2], | ||
"mode": "bilinear" | ||
} | ||
}, | ||
{ | ||
"<name>": "Orientationd", | ||
"<args>": { | ||
"keys": "image", | ||
"axcodes": "RAS" | ||
} | ||
}, | ||
{ | ||
"<name>": "EnsureChannelFirstd", | ||
"<args>": { | ||
"keys": "image" | ||
} | ||
}, | ||
{ | ||
"<name>": "ScaleIntensityRanged", | ||
"<args>": { | ||
"keys": "image", | ||
"a_min": -57, | ||
"a_max": 164, | ||
"b_min": 0, | ||
"b_max": 1, | ||
"clip": true | ||
} | ||
}, | ||
{ | ||
"<name>": "CropForegroundd", | ||
"<args>": { | ||
"keys": "image", | ||
"source_key": "image" | ||
} | ||
}, | ||
{ | ||
"<name>": "ToTensord", | ||
"<args>": { | ||
"keys": "image" | ||
} | ||
} | ||
], | ||
"datalist": { | ||
"<name>": "DatasetFunc", | ||
"<args>": { | ||
"data": "$@dataset_dir + '/dataset.json'", | ||
"func": "monai.data.load_decathlon_datalist", | ||
"is_segmentation": true, | ||
"data_list_key": "test", | ||
"base_dir": "@dataset_dir" | ||
} | ||
}, | ||
"dataset": { | ||
"<name>": "Dataset", | ||
"<args>": { | ||
"data": "@datalist", | ||
"transform": "@preprocessing" | ||
} | ||
}, | ||
"dataloader": { | ||
"<name>": "DataLoader", | ||
"<args>": { | ||
"dataset": "@dataset", | ||
"batch_size": 1, | ||
"shuffle": false, | ||
"num_workers": 4 | ||
} | ||
}, | ||
"inferer": { | ||
"<name>": "SlidingWindowInferer", | ||
"<args>": { | ||
"roi_size": "@network_data_format#inputs#image#spatial_shape", | ||
"sw_batch_size": 4, | ||
"overlap": 0.5 | ||
} | ||
}, | ||
"postprocessing": [ | ||
{ | ||
"<name>": "Activationsd", | ||
"<args>": { | ||
"keys": "pred", | ||
"softmax": true | ||
} | ||
}, | ||
{ | ||
"<name>": "Invertd", | ||
"<args>": { | ||
"keys": "pred", | ||
"transform": "@preprocessing", | ||
"orig_keys": "image", | ||
"meta_keys": "pred_meta_dict", | ||
"nearest_interp": false, | ||
"to_tensor": true, | ||
"device": "cuda" | ||
} | ||
}, | ||
{ | ||
"<name>": "AsDiscreted", | ||
"<args>": { | ||
"keys": "pred", | ||
"argmax": true | ||
} | ||
}, | ||
{ | ||
"<name>": "SaveImaged", | ||
"<args>": { | ||
"keys": "pred", | ||
"meta_keys": "pred_meta_dict", | ||
"output_dir": "{MMAR_EVAL_OUTPUT_PATH}", | ||
"resample": false, | ||
"squeeze_end_dims": true | ||
} | ||
} | ||
], | ||
"handlers": [ | ||
{ | ||
"<name>": "StatsHandler", | ||
"<args>": { | ||
"output_transform": "lambda x: None" | ||
} | ||
} | ||
], | ||
"evaluator": { | ||
"<name>": "SupervisedEvaluator", | ||
"<args>": { | ||
"device": "cuda", | ||
"val_data_loader": "@dataloader", | ||
"network": "@model", | ||
"inferer": "@inferer", | ||
"postprocessing": "@postprocessing", | ||
"val_handlers": "@handlers", | ||
"amp": "@amp" | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
modules/model_package/spleen_segmentation/configs/metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"version": "0.1.0", | ||
"changelog": { | ||
"0.1.0": "complete the model package", | ||
"0.0.1": "initialize the model package structure" | ||
}, | ||
"monai_version": "0.8.0", | ||
"pytorch_version": "1.10.0", | ||
"numpy_version": "1.21.2", | ||
"optional_packages_version": {"nibabel": "3.2.1"}, | ||
"task": "Decathlon spleen segmentation", | ||
"description": "A pre-trained model for volumetric (3D) segmentation of the spleen from CT image", | ||
"authorship": "MONAI team", | ||
"copyright": "Copyright (c) MONAI Consortium", | ||
"data_source": "Task09_Spleen.tar from http://medicaldecathlon.com/", | ||
"data_type": "dicom", | ||
"dataset_dir": "/workspace/data/Task09_Spleen", | ||
"image_classes": "single channel data, intensity scaled to [0, 1]", | ||
Nic-Ma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"label_classes": "single channel data, 1 is spleen, 0 is everything else", | ||
"pred_classes": "2 channels OneHot data, channel 1 is spleen, channel 0 is background", | ||
"eval_metrics": { | ||
"mean_dice": 0.96 | ||
}, | ||
"intended_use": "This is an example, not to be used for diagnostic purposes", | ||
"references": [ | ||
"Xia, Yingda, et al. '3D Semi-Supervised Learning with Uncertainty-Aware Multi-View Co-Training.' arXiv preprint arXiv:1811.12506 (2018). https://arxiv.org/abs/1811.12506.", | ||
"Kerfoot E., Clough J., Oksuz I., Lee J., King A.P., Schnabel J.A. (2019) Left-Ventricle Quantification Using Residual U-Net. In: Pop M. et al. (eds) Statistical Atlases and Computational Models of the Heart. Atrial Segmentation and LV Quantification Challenges. STACOM 2018. Lecture Notes in Computer Science, vol 11395. Springer, Cham. https://doi.org/10.1007/978-3-030-12029-0_40" | ||
], | ||
"network_data_format":{ | ||
"inputs": { | ||
"image": { | ||
"type": "image", | ||
"format": "magnitude", | ||
"num_channels": 1, | ||
"spatial_shape": [160, 160, 160], | ||
"dtype": "float32", | ||
"value_range": [0, 1] | ||
}, | ||
"label": { | ||
"type": "label", | ||
"format": "segmentation", | ||
"num_channels": 1, | ||
"spatial_shape": [160, 160, 160], | ||
"dtype": "float32", | ||
"value_range": [0, 1] | ||
} | ||
}, | ||
"outputs":{ | ||
"pred": { | ||
"type": "image", | ||
"format": "segmentation", | ||
"num_channels": 2, | ||
"spatial_shape": [160, 160, 160], | ||
"dtype": "float32", | ||
"value_range": [0, 1] | ||
} | ||
}, | ||
"patch_inference": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Description | ||
A pre-trained model for volumetric (3D) segmentation of the spleen from CT image. | ||
|
||
# Model Overview | ||
This model is trained using the runnerup [1] awarded pipeline of the "Medical Segmentation Decathlon Challenge 2018" using the UNet architecture [2] with 32 training images and 9 validation images. | ||
|
||
## Data | ||
The training dataset is Task09_Spleen.tar from http://medicaldecathlon.com/. | ||
|
||
## Training configuration | ||
The training was performed with command train.sh, which required 12GB-memory GPUs. | ||
|
||
Actual Model Input: 96 x 96 x 96 | ||
|
||
## Input and output formats | ||
Input: 1 channel CT image | ||
|
||
Output: 2 channels: Label 1: spleen; Label 0: everything else | ||
|
||
## Scores | ||
This model achieve the following Dice score on the validation data (our own split from the training dataset): | ||
|
||
Mean dice = 0.96 | ||
|
||
# Disclaimer | ||
This is an example, not to be used for diagnostic purposes. | ||
|
||
# References | ||
[1] Xia, Yingda, et al. "3D Semi-Supervised Learning with Uncertainty-Aware Multi-View Co-Training." arXiv preprint arXiv:1811.12506 (2018). https://arxiv.org/abs/1811.12506. | ||
|
||
[2] Kerfoot E., Clough J., Oksuz I., Lee J., King A.P., Schnabel J.A. (2019) Left-Ventricle Quantification Using Residual U-Net. In: Pop M. et al. (eds) Statistical Atlases and Computational Models of the Heart. Atrial Segmentation and LV Quantification Challenges. STACOM 2018. Lecture Notes in Computer Science, vol 11395. Springer, Cham. https://doi.org/10.1007/978-3-030-12029-0_40 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Third Party Licenses | ||
----------------------------------------------------------------------- | ||
|
||
/*********************************************************************/ | ||
i. Medical Segmentation Decathlon | ||
http://medicaldecathlon.com/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions
4
modules/model_package/spleen_segmentation_a100/commands/inference.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
python -m monai.apps.mmar.inference.py | ||
--config ../../spleen_segmentation/configs/inference.json | ||
--meta ../configs/metadata.json | ||
--override ../configs/inference.json |
11 changes: 11 additions & 0 deletions
11
modules/model_package/spleen_segmentation_a100/configs/inference.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"preprocessing#1#<args>#pixdim": [1.0, 1.0, 1.0], | ||
"inferer": { | ||
"<path>": "custom_inferer.TensorRTInferer", | ||
"<args>": { | ||
"roi_size": [200, 200, 200], | ||
"sw_batch_size": 4, | ||
"overlap": 0.6 | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
modules/model_package/spleen_segmentation_a100/scripts/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
# Copyright 2020 - 2021 MONAI Consortium | ||
# 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. |
19 changes: 19 additions & 0 deletions
19
modules/model_package/spleen_segmentation_a100/scripts/custom_inferer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Copyright 2020 - 2021 MONAI Consortium | ||
# 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. | ||
|
||
from monai.inferers import SlidingWindowInferer | ||
|
||
|
||
class TensorRTInferer(SlidingWindowInferer): | ||
def __init__(self, **kwargs) -> None: | ||
print("fake code to show the customize logic.") | ||
super().__init__(**kwargs) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.