Skip to content

Dataset Setup

motazalqaoud edited this page Jun 28, 2026 · 2 revisions

Dataset Setup

The project uses the Kaggle Brain Tumor 12K MRI Dataset — 12,643 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_/
    ├── Gliomas/
    │   ├── T1/
    │   │   └── [subtype]/
    │   │       ├── image.jpg
    │   │       ├── image_mask_consensus.png
    │   │       ├── image_bbox.png
    │   │       └── image_meta.json
    │   ├── T1C+/
    │   └── T2/
    ├── Meningothelial Tumors/
    ├── Nerve Sheath Tumors/
    ├── Embryonic Tumors/
    ├── Mixed Neuronal and Neuronal-Glial Tumors/
    ├── Mesenchymal (Non-Meningothelial Tumors)/
    ├── Germ Cell Tumors/
    └── Normal/

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, 64, 64])
Mask shape: torch.Size([64, 64])
Model output shape: torch.Size([4, 8, 64, 64])
Forward pass OK

Dataset Details

Property Value
Total images 12,643
Tumor categories 7 WHO categories + Normal (see class mapping below)
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

Class Mapping

Folder Class ID Description
Normal 0 Background only — no tumor pixels
Gliomas 1 Astrocytoma, Glioblastoma, Oligodendroglioma
Meningothelial Tumors 2 Meningioma subtypes
Nerve Sheath Tumors 3 Schwannoma, Neurocytoma
Embryonic Tumors 4 Medulloblastoma, DNET
Mixed Neuronal and Neuronal-Glial Tumors 5 Ependymoma, Ganglioglioma
Mesenchymal (Non-Meningothelial Tumors) 6 Hemangiopericytoma
Germ Cell Tumors 7 Germinoma

Pseudo-labels are assigned at the folder level: all tumor pixels in an image from the Gliomas/ folder receive class ID 1. This is weakly-supervised segmentation — we leverage binary masks and folder-level category labels together.

Clone this wiki locally