|
16 | 16 | "See the License for the specific language governing permissions and \n", |
17 | 17 | "limitations under the License.\n", |
18 | 18 | "\n", |
19 | | - "# MONAI 101 tutorial\n", |
| 19 | + "# MONAI 101 Tutorial\n", |
20 | 20 | "\n", |
21 | | - "In this tutorial, we will introduce how simple it can be to run an end-to-end classification pipeline with MONAI.\n", |
| 21 | + "Welcome to MONAI 101! This tutorial introduces beginners to the basics of building an end-to-end medical image classification pipeline with MONAI.\n", |
22 | 22 | "\n", |
23 | | - "These steps will be included in this tutorial, and each of them will take only a few lines of code:\n", |
24 | | - "- Dataset download\n", |
25 | | - "- Data pre-processing\n", |
26 | | - "- Define a DenseNet-121 and run training\n", |
27 | | - "- Check the results on test dataset\n", |
| 23 | + "## What You'll Learn\n", |
28 | 24 | "\n", |
29 | | - "This tutorial will use about 7GB of GPU memory and 10 minutes to run.\n", |
| 25 | + "In this tutorial, you'll discover how simple it can be to create a complete medical image classification system. We'll cover each step with just a few lines of code:\n", |
30 | 26 | "\n", |
31 | | - "[](https://colab.research.google.com/github/Project-MONAI/tutorials/blob/main/2d_classification/monai_101.ipynb)" |
| 27 | + "- **Dataset Download**: Automatically retrieve and set up the MedNIST dataset\n", |
| 28 | + "- **Data Preprocessing**: Transform medical images for training\n", |
| 29 | + "- **Model Definition**: Set up a DenseNet-121 neural network for classification\n", |
| 30 | + "- **Training**: Train your model with medical imaging data\n", |
| 31 | + "- **Evaluation**: Test your trained model's performance\n", |
| 32 | + "\n", |
| 33 | + "## Requirements\n", |
| 34 | + "\n", |
| 35 | + "- **GPU Memory**: Approximately 7GB\n", |
| 36 | + "- **Runtime**: About 10 minutes\n", |
| 37 | + "- **Level**: Beginner (no prior MONAI experience required)\n", |
| 38 | + "\n", |
| 39 | + "## Quick Start Options\n", |
| 40 | + "\n", |
| 41 | + "[](https://colab.research.google.com/github/Project-MONAI/tutorials/blob/main/2d_classification/monai_101.ipynb)\n", |
| 42 | + "\n", |
| 43 | + "*Click the badge above to run this tutorial in Google Colab without any local setup.*" |
32 | 44 | ] |
33 | 45 | }, |
34 | 46 | { |
|
130 | 142 | "cell_type": "markdown", |
131 | 143 | "metadata": {}, |
132 | 144 | "source": [ |
133 | | - "## Setup data directory\n", |
| 145 | + "## Setup Data Directory\n", |
134 | 146 | "\n", |
135 | | - "You can specify a directory with the `MONAI_DATA_DIRECTORY` environment variable. \n", |
136 | | - "This allows you to save results and reuse downloads. \n", |
137 | | - "If not specified a temporary directory will be used." |
| 147 | + "You can specify a directory for storing datasets and results using the `MONAI_DATA_DIRECTORY` environment variable. \n", |
| 148 | + "This allows you to:\n", |
| 149 | + "- Save results permanently\n", |
| 150 | + "- Reuse downloaded datasets across different sessions\n", |
| 151 | + "- Avoid re-downloading large datasets\n", |
| 152 | + "\n", |
| 153 | + "If not specified, a temporary directory will be used (data will be lost after the session ends)." |
138 | 154 | ] |
139 | 155 | }, |
140 | 156 | { |
|
163 | 179 | "cell_type": "markdown", |
164 | 180 | "metadata": {}, |
165 | 181 | "source": [ |
166 | | - "## Use MONAI transforms to preprocess data\n", |
| 182 | + "## Use MONAI Transforms to Preprocess Data\n", |
| 183 | + "\n", |
| 184 | + "Medical images require specialized methods for input/output (I/O), preprocessing, and augmentation. Unlike natural images, medical images often:\n", |
| 185 | + "- Follow specific formats (DICOM, NIfTI, etc.)\n", |
| 186 | + "- Are handled with specific protocols\n", |
| 187 | + "- Have high-dimensional data arrays\n", |
| 188 | + "- Require domain-specific preprocessing\n", |
167 | 189 | "\n", |
168 | | - "Medical images require specialized methods for I/O, preprocessing, and augmentation.\n", |
169 | | - "They often follow specific formats, are handled with specific protocols, and the data arrays are often high-dimensional.\n", |
| 190 | + "In this example, we'll create a preprocessing pipeline using three MONAI transforms:\n", |
170 | 191 | "\n", |
171 | | - "In this example, we will perform image loading, data format verification, and intensity scaling with three `monai.transforms` listed below, and compose a pipeline ready to be used in next steps." |
| 192 | + "1. **`LoadImageD`**: Loads medical images from various formats\n", |
| 193 | + "2. **`EnsureChannelFirstD`**: Ensures the image has the correct channel dimension\n", |
| 194 | + "3. **`ScaleIntensityD`**: Normalizes pixel intensities to a standard range\n", |
| 195 | + "\n", |
| 196 | + "These transforms are combined into a pipeline that will be applied to our data." |
172 | 197 | ] |
173 | 198 | }, |
174 | 199 | { |
|
191 | 216 | "cell_type": "markdown", |
192 | 217 | "metadata": {}, |
193 | 218 | "source": [ |
194 | | - "## Prepare datasets using MONAI Apps\n", |
| 219 | + "## Prepare Dataset Using MONAI Apps\n", |
| 220 | + "\n", |
| 221 | + "We'll use the `MedNISTDataset` from MONAI Apps to automatically download and set up our dataset. This convenience class will:\n", |
| 222 | + "- Download the dataset to your specified directory\n", |
| 223 | + "- Apply the preprocessing transforms we defined above\n", |
| 224 | + "- Split the data into training, validation, and test sets\n", |
195 | 225 | "\n", |
196 | | - "We use `MedNISTDataset` in MONAI Apps to download a dataset to the specified directory and perform the pre-processing steps in the `monai.transforms` compose.\n", |
| 226 | + "### About the MedNIST Dataset\n", |
197 | 227 | "\n", |
198 | | - "The MedNIST dataset was gathered from several sets from [TCIA](https://wiki.cancerimagingarchive.net/display/Public/Data+Usage+Policies+and+Restrictions),\n", |
199 | | - "[the RSNA Bone Age Challenge](http://rsnachallenges.cloudapp.net/competitions/4),\n", |
200 | | - "and [the NIH Chest X-ray dataset](https://cloud.google.com/healthcare/docs/resources/public-datasets/nih-chest).\n", |
| 228 | + "The MedNIST dataset is a collection of medical images from multiple sources:\n", |
| 229 | + "- [TCIA](https://wiki.cancerimagingarchive.net/display/Public/Data+Usage+Policies+and+Restrictions) (The Cancer Imaging Archive)\n", |
| 230 | + "- [RSNA Bone Age Challenge](http://rsnachallenges.cloudapp.net/competitions/4)\n", |
| 231 | + "- [NIH Chest X-ray Dataset](https://cloud.google.com/healthcare/docs/resources/public-datasets/nih-chest)\n", |
201 | 232 | "\n", |
202 | | - "The dataset is kindly made available by [Dr. Bradley J. Erickson M.D., Ph.D.](https://www.mayo.edu/research/labs/radiology-informatics/overview) (Department of Radiology, Mayo Clinic)\n", |
203 | | - "under the Creative Commons [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/).\n", |
| 233 | + "### Dataset Information\n", |
| 234 | + "- **Size**: 58,954 images\n", |
| 235 | + "- **Classes**: 6 medical image types (AbdomenCT, BreastMRI, CXR, ChestCT, Hand, HeadCT)\n", |
| 236 | + "- **Format**: 2D grayscale images\n", |
| 237 | + "- **License**: Creative Commons [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\n", |
204 | 238 | "\n", |
205 | | - "If you use the MedNIST dataset, please acknowledge the source. " |
| 239 | + "The dataset is kindly made available by [Dr. Bradley J. Erickson M.D., Ph.D.](https://www.mayo.edu/research/labs/radiology-informatics/overview) (Department of Radiology, Mayo Clinic).\n", |
| 240 | + "\n", |
| 241 | + "*If you use the MedNIST dataset in your research, please acknowledge the source.*" |
206 | 242 | ] |
207 | 243 | }, |
208 | 244 | { |
|
236 | 272 | "cell_type": "markdown", |
237 | 273 | "metadata": {}, |
238 | 274 | "source": [ |
239 | | - "## Define a network and a supervised trainer\n", |
| 275 | + "## Define Network and Supervised Trainer\n", |
| 276 | + "\n", |
| 277 | + "Now we'll set up our machine learning model and training configuration.\n", |
| 278 | + "\n", |
| 279 | + "### Model Selection: DenseNet-121\n", |
| 280 | + "\n", |
| 281 | + "We'll use DenseNet-121, a proven convolutional neural network architecture that:\n", |
| 282 | + "- Has shown excellent performance on ImageNet and medical imaging tasks\n", |
| 283 | + "- Features dense connections between layers for better gradient flow\n", |
| 284 | + "- Is computationally efficient for medical image classification\n", |
240 | 285 | "\n", |
241 | | - "To train a model that can perform the classification task, we will use the DenseNet-121 which is known for its performance on the ImageNet dataset.\n", |
| 286 | + "### Training Configuration\n", |
242 | 287 | "\n", |
243 | | - "For a typical supervised training workflow, MONAI provides `SupervisedTrainer` to define the hyper-parameters." |
| 288 | + "MONAI provides `SupervisedTrainer` to simplify the training process. This high-level API handles:\n", |
| 289 | + "- Training loops and optimization\n", |
| 290 | + "- Loss computation and backpropagation \n", |
| 291 | + "- Metric tracking and logging\n", |
| 292 | + "- Device management (CPU/GPU)" |
244 | 293 | ] |
245 | 294 | }, |
246 | 295 | { |
|
270 | 319 | "cell_type": "markdown", |
271 | 320 | "metadata": {}, |
272 | 321 | "source": [ |
273 | | - "## Run the training" |
| 322 | + "## Run the Training\n", |
| 323 | + "\n", |
| 324 | + "Now let's start the training process! The trainer will:\n", |
| 325 | + "- Load batches of medical images\n", |
| 326 | + "- Forward them through the DenseNet-121 model\n", |
| 327 | + "- Calculate the loss and update model weights\n", |
| 328 | + "- Track training progress\n", |
| 329 | + "\n", |
| 330 | + "This should take about 10 minutes on a GPU." |
274 | 331 | ] |
275 | 332 | }, |
276 | 333 | { |
|
287 | 344 | "cell_type": "markdown", |
288 | 345 | "metadata": {}, |
289 | 346 | "source": [ |
290 | | - "## Check the prediction on the test dataset" |
| 347 | + "## Evaluate Model Performance on Test Dataset\n", |
| 348 | + "\n", |
| 349 | + "Let's see how well our trained model performs! We'll:\n", |
| 350 | + "- Load the test dataset (images the model has never seen)\n", |
| 351 | + "- Run predictions on these images\n", |
| 352 | + "- Compare predictions with ground truth labels\n", |
| 353 | + "- Display the results to see classification accuracy\n", |
| 354 | + "\n", |
| 355 | + "This evaluation helps us understand if our model can generalize to new medical images." |
291 | 356 | ] |
292 | 357 | }, |
293 | 358 | { |
|
0 commit comments