Skip to content

Dataset Setup

motazalqaoud edited this page Jun 26, 2026 · 2 revisions

Dataset Setup

The project uses the Kaggle Brain Tumor 12K MRI Dataset — 12,000+ T1/T2 weighted MRI slices with consensus segmentation masks, bounding boxes, and JSON metadata.


Step 1 — Install the Kaggle CLI

pip install kaggle

Step 2 — Set Up Your Kaggle API Key

  1. Go to kaggle.com → Account → API → Create New Token
  2. This downloads kaggle.json
  3. Place it at ~/.kaggle/kaggle.json
  4. Set permissions: chmod 600 ~/.kaggle/kaggle.json

Step 3 — Download the Dataset

kaggle datasets download -d fernando2rad/brain-tumor-12k-mri-images-w-masks-meta-and-bbox
unzip brain-tumor-12k-mri-images-w-masks-meta-and-bbox.zip -d data/raw/

Step 4 — Verify the Folder Structure

After extraction, data/raw/ should look like this:

data/raw/
└── Images_/
    ├── Glioma/
    │   ├── T1/
    │   │   └── [subtype]/
    │   │       ├── image.jpg
    │   │       ├── image_mask_consensus.png
    │   │       ├── image_bbox.png
    │   │       └── image_meta.json
    │   ├── T1C+/
    │   └── T2/
    ├── Meningioma/
    │   ├── T1/
    │   ├── T1C+/
    │   └── T2/
    └── Pituitary/
        ├── T1/
        ├── T1C+/
        └── T2/

Step 5 — Verify the Loader

python scripts/test_model.py --data-root data/raw/Images_

Expected output:

Dataset size: XXXX
Image shape: torch.Size([1, 128, 128])
Mask shape: torch.Size([128, 128])
Model output shape: torch.Size([4, 4, 128, 128])
Forward pass OK

No Download? Use Synthetic Data

To test the pipeline without the dataset:

python scripts/generate_sample_data.py --n 20 --size 128
python scripts/train.py --epochs 5

This generates NIfTI volumes in data/samples/ and trains the 2D U-Net on them.


Dataset Details

Property Value
Total images 12,000+
Tumor classes Glioma, Meningioma, Pituitary
MRI modalities T1, T1C+ (contrast), T2
Mask format PNG (consensus segmentation)
Metadata JSON (bounding box, tumor subtype)
Image format JPG (MRI slices)
License CC BY-NC-SA 4.0

Clone this wiki locally