Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 2d_classification/mednist_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
],
"source": [
"%pip install -qU \"monai[pillow]\""
"%pip install -q \"monai[pillow, tqdm]\""
]
},
{
Expand All @@ -60,7 +60,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/brats_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"outputs": [],
"source": [
"%pip install -qU \"monai[nibabel]\""
"%pip install -q \"monai[nibabel, tqdm]\""
]
},
{
Expand All @@ -64,7 +64,7 @@
},
"outputs": [],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/spleen_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}
],
"source": [
"%pip install -qU \"monai[gdown, nibabel]\""
"%pip install -q \"monai[gdown, nibabel, tqdm]\""
]
},
{
Expand All @@ -74,7 +74,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/spleen_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/unet_segmentation_3d_catalyst.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"outputs": [],
"source": [
"%pip install -qU \"monai[nibabel, tensorboard]\""
"%pip install -q \"monai[nibabel, tensorboard]\""
]
},
{
Expand All @@ -56,7 +56,7 @@
},
"outputs": [],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/unet_segmentation_3d_ignite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"outputs": [],
"source": [
"%pip install -qU \"monai[ignite, nibabel, tensorboard]\""
"%pip install -q \"monai[ignite, nibabel, tensorboard]\""
]
},
{
Expand Down
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,41 @@ Most of the examples and tutorials require
[matplotlib](https://matplotlib.org/) and [Jupyter Notebook](https://jupyter.org/).

These could be installed by:

```bash
python -m pip install -U pip
python -m pip install -U matplotlib
python -m pip install -U notebook
```

Some of the examples may require optional dependencies. In case of any optional import errors,
please install the relevant packages according to the error message.
please install the relevant packages according to MONAI's [installation guide](https://docs.monai.io/en/latest/installation.html).
Or install all optional requirements by:
```

```bash
pip install -r https://raw.githubusercontent.com/Project-MONAI/MONAI/master/requirements-dev.txt
```

#### Run the notebooks from Colab

Most of the Jupyter Notebooks have an "Open in Colab" button.
Please right-click on the button, and select "Open Link in New Tab" to start a Colab page with the corresponding notebook content.

To use GPU resources through Colab, please remember to change the runtime type to `GPU`:

1. From the `Runtime` menu select `Change runtime type`
1. Choose `GPU` from the drop-down menu
1. Click `SAVE`
This will reset the notebook and may ask you if you are a robot (these instructions assume you are not).

Running:

```bash
!nvidia-smi
```

in a cell will verify this has worked and show you what kind of hardware you have access to.

### 2. List of notebooks and examples
**2D classification**
#### [mednist_tutorial](./2d_classification/mednist_tutorial.ipynb)
Expand Down Expand Up @@ -74,8 +97,7 @@ The examples show how to execute distributed training and evaluation based on 3
- PyTorch ignite and MONAI workflows.

They can run on several distributed nodes with multiple GPU devices on every node.
#### [automatic_mixed_precision](./acceleration/accautomatic_mixed_precision.ipynb)
This tutorial shows how to apply the automatic mixed precision(AMP) feature of PyTorch into training and evaluation programs.
#### [automatic_mixed_precision](./acceleration/automatic_mixed_precision.ipynb)
And compares the training speed and memory usage with/without AMP.
#### [dataset_type_performance](./acceleration/dataset_type_performance.ipynb)
This notebook compares the performance of `Dataset`, `CacheDataset` and `PersistentDataset`. These classes differ in how data is stored (in memory or on disk), and at which moment transforms are applied.
Expand Down
17 changes: 5 additions & 12 deletions acceleration/automatic_mixed_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@
}
],
"source": [
"%pip install -qU \"monai[gdown, nibabel]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# temporarily need this, FIXME: remove when MONAI v0.3 released\n",
"%pip install -qU git+https://github.com/Project-MONAI/MONAI#egg=MONAI"
"%pip install -q \"monai[gdown, nibabel, tqdm]\""
]
},
{
Expand All @@ -67,7 +57,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down Expand Up @@ -115,6 +105,7 @@
"from monai.metrics import compute_meandice\n",
"from monai.utils import set_determinism\n",
"from monai.config import print_config\n",
"from monai.apps import download_and_extract\n",
"\n",
"print_config()\n",
"\n",
Expand Down Expand Up @@ -147,6 +138,8 @@
}
],
"source": [
"import tempfile\n",
"\n",
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
"print(f\"root dir is: {root_dir}\")"
Expand Down
10 changes: 5 additions & 5 deletions acceleration/dataset_type_performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"\n",
"`Dataset` provides the simplest model of data loading. Each time a dataset is needed, it is reloaded from the original datasources, and processed through the all non-random and random transforms to generate analyzable tensors. This mechanism has the smallest memory footprint, and the smallest temporary disk footprint.\n",
"\n",
"`CacheDataset` provides a mechanism to pre-load all original data and apply non-random transforms into analyzable tensors loaded in memory prior to starting analysis. The `CacheDataset` requires all tensor representations of data requested to be loaded into memory at once. The subset of random transforms are applied to the cached components before use. This is the highest performance dataset if all data fits in core memory.\n",
"`CacheDataset` provides a mechanism to pre-load all original data and apply non-random transforms into analyzable tensors loaded in memory prior to starting analysis. The `CacheDataset` requires all tensor representations of data requested to be loaded into memory at once. The subset of random transforms is applied to the cached components before use. This is the highest performance dataset if all data fit in core memory.\n",
"\n",
"`PersistentDataset` processes original data sources through the non-random transforms on first use, and stores these intermediate tensor values to an on-disk persistence representation. The intermediate processed tensors are loaded from disk on each use for processing by the random-transforms for each analysis request. The `PersistentDataset` has a similar memory footprint to the simple `Dataset`, with performance characterisics close to the `CacheDataset` at the expense of disk storage. Additially, the cost of first time processing of data is distributed across each first use.\n",
"`PersistentDataset` processes original data sources through the non-random transforms on first use, and stores these intermediate tensor values to an on-disk persistence representation. The intermediate processed tensors are loaded from disk on each use for processing by the random-transforms for each analysis request. The `PersistentDataset` has a similar memory footprint to the simple `Dataset`, with performance characteristics close to the `CacheDataset` at the expense of disk storage. Additionally, the cost of first time processing of data is distributed across each first use.\n",
"\n",
"It's modified from the [Spleen 3D segmentation tutorial notebook](https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/spleen_segmentation_3d.ipynb).\n",
"\n",
Expand All @@ -35,7 +35,7 @@
},
"outputs": [],
"source": [
"%pip install -qU \"monai[gdown, nibabel]\""
"%pip install -q \"monai[gdown, nibabel, tqdm]\""
]
},
{
Expand All @@ -46,7 +46,7 @@
},
"outputs": [],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down Expand Up @@ -270,7 +270,7 @@
" f\"current epoch: {epoch + 1} current mean dice: {metric:.4f}\"\n",
" f\" best mean dice: {best_metric:.4f} at epoch: {best_metric_epoch}\"\n",
" )\n",
" print(f\"time consuming of epoch {epoch + 1} is: {(time.time() - epoch_start):.4f}\")\n",
" print(f\"time of epoch {epoch + 1} is: {(time.time() - epoch_start):.4f}\")\n",
" epoch_times.append(time.time() - epoch_start)\n",
"\n",
" print(\n",
Expand Down
27 changes: 10 additions & 17 deletions acceleration/fast_training_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,7 @@
}
],
"source": [
"%pip install -qU \"monai[nibabel]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# temporarily need this, FIXME: remove when MONAI v0.3 released\n",
"%pip install -qU git+https://github.com/Project-MONAI/MONAI#egg=MONAI"
"%pip install -q \"monai[nibabel, tqdm]\""
]
},
{
Expand All @@ -69,7 +59,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down Expand Up @@ -143,6 +133,7 @@
"from monai.metrics import compute_meandice\n",
"from monai.utils import set_determinism\n",
"from monai.config import print_config\n",
"from monai.apps import download_and_extract\n",
"\n",
"print_config()\n",
"\n",
Expand Down Expand Up @@ -175,6 +166,8 @@
}
],
"source": [
"import tempfile\n",
"\n",
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
"print(f\"root dir is: {root_dir}\")"
Expand Down Expand Up @@ -271,12 +264,12 @@
"metadata": {},
"source": [
"## Define the training progress\n",
"For typical PyTorch regular training progress, use regular `Dataset`, `Adam` optimizer, and train the model.\n",
"For a typical PyTorch regular training procedure, use regular `Dataset`, `Adam` optimizer, and train the model.\n",
"\n",
"For MONAI fast training progress, we mainly introduce below features:\n",
"1. `CacheDataset`: Dataset with cache mechanism that can load data and cache deterministic transforms' result during training.\n",
"2. `Novograd` optimizer: Novograd is based on paper \"Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks\" `<https://arxiv.org/pdf/1905.11286.pdf>`.\n",
"3. `AMP` (auto mixed precision): AMP is an important feature released in PyTorch v1.6, NVIDIA CUDA 11 added strong support for AMP and obviously improved training speed."
"For MONAI fast training progress, we mainly introduce the following features:\n",
"1. `CacheDataset`: Dataset with the cache mechanism that can load data and cache deterministic transforms' result during training.\n",
"2. `Novograd` optimizer: Novograd is based on the paper \"Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks\" `<https://arxiv.org/pdf/1905.11286.pdf>`.\n",
"3. `AMP` (auto mixed precision): AMP is an important feature released in PyTorch v1.6, NVIDIA CUDA 11 added strong support for AMP and significantly improved training speed."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion acceleration/multi_gpu_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
],
"source": [
"%pip install -qU \"monai[ignite]\""
"%pip install -q \"monai[ignite]\""
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions acceleration/transform_speed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
],
"source": [
"%pip install -qU \"monai[nibabel]\""
"%pip install -q \"monai[nibabel]\""
]
},
{
Expand Down Expand Up @@ -164,8 +164,6 @@
"metadata": {},
"outputs": [],
"source": [
"root_dir = tempfile.mkdtemp()\n",
"\n",
"for i in range(5):\n",
" im, seg = create_test_image_3d(256, 256, 256)\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions modules/3d_image_transforms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
],
"source": [
"%pip install -qU \"monai[gdown, nibabel]\""
"%pip install -q \"monai[gdown, nibabel]\""
]
},
{
Expand All @@ -53,7 +53,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
16 changes: 3 additions & 13 deletions modules/dynunet_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU \"monai[itk, ignite]\""
"%pip install -q \"monai[itk, ignite, tqdm]\""
]
},
{
Expand All @@ -38,17 +38,7 @@
"metadata": {},
"outputs": [],
"source": [
"# temporarily need this, FIXME: remove when MONAI v0.3 released\n",
"%pip install -qU git+https://github.com/Project-MONAI/MONAI#egg=MONAI"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down Expand Up @@ -454,7 +444,7 @@
" out_channels=n_class,\n",
" kernel_size=kernels,\n",
" strides=strides,\n",
" upsamle_kernel_size=strides[1:],\n",
" upsample_kernel_size=strides[1:],\n",
" norm_name=\"instance\",\n",
" deep_supervision=True,\n",
" deep_supr_num=2,\n",
Expand Down
4 changes: 2 additions & 2 deletions modules/integrate_3rd_party_transforms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
],
"source": [
"%pip install -qU \"monai[gdown]\""
"%pip install -q \"monai[gdown]\""
]
},
{
Expand All @@ -54,7 +54,7 @@
}
],
"source": [
"%pip install -qU matplotlib\n",
"%pip install -q matplotlib\n",
"%matplotlib inline"
]
},
Expand Down
Loading