Skip to content

Read it, then run it

This page is the read-only chapter intro. To actually execute the cells (load the dataset, train a model, render GradCAM heatmaps on your own images), open the Colab notebook in a free T4 runtime. The curriculum is designed to be executed, not read.

Chapter 1: Dataset Preparation

Learning objectives: - Load a medical image dataset using MONAI - Understand how images are represented as numerical arrays - Visualize medical images and explore class distributions - Split data into training, validation, and test sets

Clinical context: Just as you organize patient cases before a teaching session - selecting representative examples, checking image quality, and ensuring balanced coverage across pathologies - we need to prepare our dataset before training a model.

The MedNIST Dataset

MedNIST contains 58,954 medical images across 6 classes: AbdomenCT, BreastMRI, CXR (chest X-ray), ChestCT, Hand, and HeadCT. Each image is 64×64 pixels, grayscale.

This dataset serves as the "MNIST of medical imaging" - a simple, standardized benchmark that lets us focus on learning deep learning concepts without the complexity of full-resolution clinical images.


Attribution: The MedNIST dataset was gathered from several sets from TCIA, the RSNA Bone Age Challenge, and the NIH Chest X-ray dataset.

The dataset is kindly made available by Dr. Bradley J. Erickson M.D., Ph.D. (Department of Radiology, Mayo Clinic) under the Creative Commons CC BY-SA 4.0 license.

What does the computer "see"?

When you look at an X-ray, you perceive anatomical structures, densities, and patterns. But a computer sees only a grid of numbers - each pixel has an intensity value between 0 (black) and 255 (white), with shades of gray in between.

The entire image is stored as a matrix (a 2D array of numbers). All the "learning" a deep learning model does is finding mathematical patterns in these numbers that correlate with diagnostic categories.

In clinical practice, medical images are stored as DICOM files with 12–16 bit depth (up to 65,535 intensity levels), which preserves subtle density differences critical for diagnosis. For this tutorial, we use simplified 8-bit images (256 levels) to keep things manageable.

Splitting the Data: Train, Validation, and Test Sets

Before training a model, we divide our data into three non-overlapping sets:

Set Purpose Our Split
Training The model learns patterns from this data 80%
Validation We monitor performance during training to detect overfitting 10%
Test Final, one-time evaluation on data the model has never seen 10%

Why three sets? If we only had train and test, we'd have no way to tune our model without "peeking" at the test data. The validation set gives us a safe place to make adjustments.

We use stratified splitting - this ensures each set has the same proportion of each class as the full dataset. Without stratification, a small class could end up entirely missing from the validation set.

In clinical AI, the test set must be truly independent - ideally from a different institution or time period. This guards against the model simply memorizing institutional patterns (scanner type, positioning habits) rather than learning genuine diagnostic features.