Skip to content

Commit

Permalink
1090-enhance-tutorials (Project-MONAI#1100)
Browse files Browse the repository at this point in the history
Signed-off-by: binliu <[email protected]>

Fixes Project-MONAI#1090  .

### Description
Fix some basic problems occured during test.

### Checks
- [x] Reconstruction tutorial:
    - [x] some typo and grammar problems in the readme file. 
    - [x] `fastmri_ssim.py` absents in `varnet_demo` folder.
- [x] the checkpoint device directly map to 'cpu' in
[unet_demo/inference.ipynb](https://github.com/binliunls/tutorials/blob/1014-mlflow-handler-tutorial/reconstruction/MRI_reconstruction/unet_demo/inference.ipynb).
   

- [x] Detection tutorial:
     - [x] some typo, link and grammar problems in the readme file. 
  
- [x] CAI tutorial:
- [x] add explanation for opencv codec error in the `video_seg`
tutorial.
- [x] use `EnsureChannelFirst` instead of `AsChannelFirst` in
`endoscopic inbody classification tutorial`.
- [x] accuracy in endoscopic inbody classfication tutorial should be a
number instead of tensor.
   
- [x] Pathology tutorial:
    - [x] some useless cell output in nuclick tutorial.
 
- [x] Add license to above tutorials
- [x] Check license in other tutorials

Signed-off-by: binliu <[email protected]>
Signed-off-by: Bin Liu (SW-GPU) <[email protected]>
Signed-off-by: Mingxin Zheng <[email protected]>
Signed-off-by: mingxin-zheng <[email protected]>
Signed-off-by: Mingxin Zheng <[email protected]>
Co-authored-by: mingxin-zheng <[email protected]>
Co-authored-by: Mingxin Zheng <[email protected]>
Co-authored-by: Mingxin Zheng <[email protected]>
  • Loading branch information
4 people authored Jan 17, 2023
1 parent 57a9508 commit a2652fb
Show file tree
Hide file tree
Showing 77 changed files with 1,292 additions and 2,033 deletions.
676 changes: 2 additions & 674 deletions 2d_classification/mednist_tutorial.ipynb

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions 2d_registration/registration_mednist.ipynb

Large diffs are not rendered by default.

399 changes: 157 additions & 242 deletions 3d_registration/paired_lung_ct.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions 3d_segmentation/brats_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Copyright (c) MONAI Consortium \n",
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
"you may not use this file except in compliance with the License. \n",
"You may obtain a copy of the License at \n",
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
"Unless required by applicable law or agreed to in writing, software \n",
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
"See the License for the specific language governing permissions and \n",
"limitations under the License.\n",
"\n",
"# Brain tumor 3D segmentation with MONAI\n",
"\n",
"This tutorial shows how to construct a training workflow of multi-labels segmentation task.\n",
Expand Down Expand Up @@ -107,17 +118,6 @@
}
],
"source": [
"# Copyright 2020 MONAI Consortium\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"# http://www.apache.org/licenses/LICENSE-2.0\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License.\n",
"\n",
"import os\n",
"import shutil\n",
"import tempfile\n",
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/challenge_baseline/run_net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright (c) 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
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_evaluation_array.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright (c) 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
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_evaluation_dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright (c) 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
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_training_array.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright (c) 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
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_training_dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright (c) 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
Expand Down
128 changes: 63 additions & 65 deletions 3d_segmentation/spleen_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Copyright (c) MONAI Consortium \n",
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
"you may not use this file except in compliance with the License. \n",
"You may obtain a copy of the License at \n",
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
"Unless required by applicable law or agreed to in writing, software \n",
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
"See the License for the specific language governing permissions and \n",
"limitations under the License.\n",
"\n",
"# Spleen 3D segmentation with MONAI\n",
"\n",
"This tutorial shows how to integrate MONAI into an existing PyTorch medical DL program.\n",
Expand All @@ -21,7 +32,7 @@
"\n",
"The Spleen dataset can be downloaded from http://medicaldecathlon.com/.\n",
"\n",
"![spleen](http://medicaldecathlon.com/img/spleen0.png)\n",
"![spleen](../figures/spleen0.png)\n",
"\n",
"Target: Spleen \n",
"Modality: CT \n",
Expand Down Expand Up @@ -50,13 +61,62 @@
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup imports"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"MONAI version: 1.1.0+2.g97918e46\n",
"Numpy version: 1.22.2\n",
"Pytorch version: 1.13.0a0+d0d6b1f\n",
"MONAI flags: HAS_EXT = True, USE_COMPILED = False, USE_META_DICT = False\n",
"MONAI rev id: 97918e46e0d2700c050e678d72e3edb35afbd737\n",
"MONAI __file__: /opt/monai/monai/__init__.py\n",
"\n",
"Optional dependencies:\n",
"Pytorch Ignite version: 0.4.10\n",
"Nibabel version: 4.0.2\n",
"scikit-image version: 0.19.3\n",
"Pillow version: 9.0.1\n",
"Tensorboard version: 2.10.1\n",
"gdown version: 4.6.0\n",
"TorchVision version: 0.14.0a0\n",
"tqdm version: 4.64.1\n",
"lmdb version: 1.3.0\n",
"psutil version: 5.9.2\n",
"pandas version: 1.4.4\n",
"einops version: 0.6.0\n",
"transformers version: 4.21.3\n",
"mlflow version: 2.0.1\n",
"pynrrd version: 1.0.0\n",
"\n",
"For details about installing the optional dependencies, please visit:\n",
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
"\n"
]
}
],
"source": [
"from monai.utils import first, set_determinism\n",
"from monai.transforms import (\n",
Expand Down Expand Up @@ -87,69 +147,7 @@
"import tempfile\n",
"import shutil\n",
"import os\n",
"import glob"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup imports"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MONAI version: 0.9.1\n",
"Numpy version: 1.22.4\n",
"Pytorch version: 1.13.0a0+340c412\n",
"MONAI flags: HAS_EXT = True, USE_COMPILED = False, USE_META_DICT = False\n",
"MONAI rev id: 356d2d2f41b473f588899d705bbc682308cee52c\n",
"MONAI __file__: /opt/monai/monai/__init__.py\n",
"\n",
"Optional dependencies:\n",
"Pytorch Ignite version: 0.4.9\n",
"Nibabel version: 4.0.1\n",
"scikit-image version: 0.19.3\n",
"Pillow version: 9.0.1\n",
"Tensorboard version: 2.9.1\n",
"gdown version: 4.5.1\n",
"TorchVision version: 0.13.0a0\n",
"tqdm version: 4.64.0\n",
"lmdb version: 1.3.0\n",
"psutil version: 5.9.1\n",
"pandas version: 1.3.5\n",
"einops version: 0.4.1\n",
"transformers version: 4.20.1\n",
"mlflow version: 1.27.0\n",
"pynrrd version: 0.4.3\n",
"\n",
"For details about installing the optional dependencies, please visit:\n",
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
"\n"
]
}
],
"source": [
"# Copyright 2020 MONAI Consortium\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"# http://www.apache.org/licenses/LICENSE-2.0\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License.\n",
"\n",
"import glob\n",
"\n",
"print_config()"
]
Expand Down
26 changes: 13 additions & 13 deletions 3d_segmentation/spleen_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Copyright (c) MONAI Consortium \n",
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
"you may not use this file except in compliance with the License. \n",
"You may obtain a copy of the License at \n",
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
"Unless required by applicable law or agreed to in writing, software \n",
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
"See the License for the specific language governing permissions and \n",
"limitations under the License. \n",
"\n",
"# Spleen 3D segmentation with MONAI"
]
},
Expand Down Expand Up @@ -105,17 +116,6 @@
}
],
"source": [
"# Copyright 2020 MONAI Consortium\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"# http://www.apache.org/licenses/LICENSE-2.0\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License.\n",
"\n",
"import pytorch_lightning\n",
"from monai.utils import set_determinism\n",
"from monai.transforms import (\n",
Expand Down Expand Up @@ -683,7 +683,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 64-bit",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -697,7 +697,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.13"
},
"vscode": {
"interpreter": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
"you may not use this file except in compliance with the License. \n",
"You may obtain a copy of the License at \n",
" http://www.apache.org/licenses/LICENSE-2.0 \n",
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
"Unless required by applicable law or agreed to in writing, software \n",
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
"See the License for the specific language governing permissions and \n",
"limitations under the License. \n",
"limitations under the License.\n",
"\n",
"# Spleen 3D segmentation with MONAI\n",
"\n",
Expand Down
48 changes: 36 additions & 12 deletions 3d_segmentation/swin_unetr_brats21_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3D Brain Tumor Segmentation with Swin UNETR (BraTS 21 Challenge)\n",
"Copyright (c) MONAI Consortium \n",
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
"you may not use this file except in compliance with the License. \n",
"You may obtain a copy of the License at \n",
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
"Unless required by applicable law or agreed to in writing, software \n",
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
"See the License for the specific language governing permissions and \n",
"limitations under the License. \n",
"\n",
"# 3D Brain Tumor Segmentation with Swin UNETR (BraTS 21 Challenge)\n",
"\n",
"\n",
"This tutorial uses the [Swin UNETR](https://arxiv.org/pdf/2201.01266.pdf/) [1,2] model for the task of brain tumor segmentation using the [BraTS 21](http://braintumorsegmentation.org/) challenge dataset [3,4,5,6]. Swin UNETR ranked among top-performing models in BraTS 21 validation phase. The architecture of Swin UNETR is demonstrated as below\n",
"![image](https://lh3.googleusercontent.com/pw/AM-JKLXBhxHcB6fGG6OoWnx1-_uwhfg9J-5HamVpDbmUTc395EbkiIwA7p2y1piZz5-uz1J9dcOhHwrhT_mpPJzDqfvSEM_qFIieE0_FC_5i5YQLm23QJjkSyIydjQ4gSX3TdpibUgDXxaWJkfOHKMW7rJD-=w1388-h523-no?authuser=2)\n",
"\n",
"![swin_brats](../figures/swin_brats21.png)\n",
"\n",
"The following features are included in this tutorial:\n",
"1. Transforms for dictionary format data.\n",
"1. Define a new transform according to MONAI transform API.\n",
"1. Load Nifti image with metadata, load a list of images and stack them.\n",
"1. Randomly rotate across each axes for data augmentation.\n",
"1. Randomly adjust intensity for data augmentation.\n",
"1. Randomly adjust the intensity for data augmentation.\n",
"1. Cache IO and transforms to accelerate training and validation.\n",
"1. Swin UNETR model, Dice loss function, Mean Dice metric for brain tumor segmentation task.\n",
"\n",
Expand All @@ -33,15 +45,15 @@
"\n",
"https://www.synapse.org/#!Synapse:syn27046444/wiki/616992\n",
"\n",
"The json file containing training and validation sets (internal split) needs to be downloaded from this [link](https://drive.google.com/file/d/1i-BXYe-wZ8R9Vp3GXoajGyqaJ65Jybg1/view?usp=sharing) and placed in the same folder as the dataset. As discussed in the following, this tutorial uses fold 1 for training a Swin UNETR model on BraTS 21 challenge.\n",
"The JSON file containing training and validation sets (internal split) needs to be downloaded from this [link](https://drive.google.com/file/d/1i-BXYe-wZ8R9Vp3GXoajGyqaJ65Jybg1/view?usp=sharing) and placed in the same folder as the dataset. As discussed in the following, this tutorial uses fold 1 for training a Swin UNETR model on the BraTS 21 challenge.\n",
"\n",
"### Tumor Characteristics\n",
"\n",
"The sub-regions considered for evaluation in BraTS 21 challenge are the \"enhancing tumor\" (ET), the \"tumor core\" (TC), and the \"whole tumor\" (WT). The ET is described by areas that show hyper-intensity in T1Gd when compared to T1, but also when compared to “healthy” white matter in T1Gd. The TC describes the bulk of the tumor, which is what is typically resected. The TC entails the ET, as well as the necrotic (NCR) parts of the tumor. The appearance of NCR is typically hypo-intense in T1-Gd when compared to T1. The WT describes the complete extent of the disease, as it entails the TC and the peritumoral edematous/invaded tissue (ED), which is typically depicted by hyper-intense signal in FLAIR [[BraTS 21]](http://braintumorsegmentation.org/).\n",
"The sub-regions considered for evaluation in the BraTS 21 challenge are the \"enhancing tumor\" (ET), the \"tumor core\" (TC), and the \"whole tumor\" (WT). The ET is described by areas that show hyper-intensity in T1Gd when compared to T1, but also when compared to “healthy” white matter in T1Gd. The TC describes the bulk of the tumor, which is what is typically resected. The TC entails the ET, as well as the necrotic (NCR) parts of the tumor. The appearance of NCR is typically hypo-intense in T1-Gd when compared to T1. The WT describes the complete extent of the disease, as it entails the TC and the peritumoral edematous/invaded tissue (ED), which is typically depicted by the hyper-intense signal in FLAIR [[BraTS 21]](http://braintumorsegmentation.org/).\n",
"\n",
"The provided segmentation labels have values of 1 for NCR, 2 for ED, 4 for ET, and 0 for everything else.\n",
"\n",
"![image](https://lh3.googleusercontent.com/pw/AM-JKLWJu7l7W3UKfGiWRFkqC-F9FY26f_GH-81N2cp0sMhnDN5k0s709dTFGxkJv-QQN6poOSvaCJ9chP7_M9QrrjpyMvoZozs6eWCMCeBG97jpilq8jvZdqqevVs6jp-FpFKdHZxzXGXfnZdbvmgh8kN9O=w830-h399-no?authuser=2)\n",
"![image](../figures/fig_brats21.png)\n",
"\n",
"Figure from [Baid et al.](https://arxiv.org/pdf/2107.02314v1.pdf) [3]\n",
"\n",
Expand Down Expand Up @@ -74,22 +86,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Swin UNETR Model\n",
"## Swin UNETR Model\n",
"\n",
"The inputs to [Swin UNETR](https://arxiv.org/pdf/2201.01266.pdf/) are 3D multi-modal MRI images with 4 channels. The patch partition block creates non-overlapping patches of the input data and projects them into embedding tokens with resolution of 128x128x128. The projected tokens are then encoded by using a 3D [Swin Transformer](https://openaccess.thecvf.com/content/ICCV2021/papers/Liu_Swin_Transformer_Hierarchical_Vision_Transformer_Using_Shifted_Windows_ICCV_2021_paper.pdf/) in which the self-attention is computed within local windows. The interaction between different windows are obtained by using 3D window shifting as illustrated below. \n",
"The inputs to [Swin UNETR](https://arxiv.org/pdf/2201.01266.pdf) are 3D multi-modal MRI images with 4 channels.\n",
"The patch partition block creates non-overlapping patches of the input data and projects them into embedding tokens with a resolution of 128x128x128.\n",
"The projected tokens are then encoded by using a 3D [Swin Transformer](https://openaccess.thecvf.com/content/ICCV2021/papers/Liu_Swin_Transformer_Hierarchical_Vision_Transformer_Using_Shifted_Windows_ICCV_2021_paper.pdf) in which the self-attention is computed within local windows.\n",
"The interaction between different windows is obtained by using 3D window shifting as illustrated below. \n",
"\n",
"![image](https://lh3.googleusercontent.com/pw/AM-JKLULHyJ1YW_QWRgR2bViIOdnz9ppOpBWFpGhoxe-tmbXug0IdvV2WUUYH__EJt4iGwgD_aKm6GO4QbJZqkITr6_WXNuYRiugp-3Ir162J6XdCHv8xV2w2xIHQ7ZVWyx9ALqLG0LfmdcUQce5m8pWVfIS=w908-h379-no?authuser=2)\n",
"![image](../figures/shift_patch.png)\n",
"\n",
"The transformer-based encoder is connected to a CNN-decoder via skip connection at multiple resolutions. The segmentation output consists of 3 output channels corresponding to ET,WT and TC sub-regions and is computed by using a 1x1x1 convolutional layer followed by Sigmoid activation function.\n"
"The transformer-based encoder is connected to a CNN-decoder via skip connection at multiple resolutions.\n",
"The segmentation output consists of 3 output channels corresponding to ET, WT, and TC sub-regions and is computed by using a 1x1x1 convolutional layer followed by Sigmoid activation function.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" # Download dataset and json file\n",
" ## Download dataset and json file\n",
"\n",
"- Register and download the official BraTS 21 dataset from the link below and place then into \"TrainingData\" in the dataset folder:\n",
"- Register and download the official BraTS 21 dataset from the link below and place them into \"TrainingData\" in the dataset folder:\n",
"\n",
" https://www.synapse.org/#!Synapse:syn27046444/wiki/616992\n",
" \n",
Expand Down Expand Up @@ -119,6 +135,14 @@
"%matplotlib inline"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup imports"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down
Loading

0 comments on commit a2652fb

Please sign in to comment.