-
Notifications
You must be signed in to change notification settings - Fork 0
Training Guide
motazalqaoud edited this page Jun 26, 2026
·
3 revisions
git clone https://github.com/motazalqaoud/Brain-Tumor-Segmentation.git
cd Brain-Tumor-Segmentation
pip install -r requirements.txtDownload the dataset first — see Dataset Setup.
python scripts/train3d.py \
--epochs 100 \
--batch 4 \
--lr 1e-3 \
--data-root data/raw/Images_ \
--base-filters 32 \
--depth 3| Argument | Default | Description |
|---|---|---|
--epochs |
50 | Total training epochs |
--batch |
4 | Batch size |
--lr |
1e-3 | Initial learning rate |
--data-root |
data/raw/Images_/Images_ |
Path to dataset |
--base-filters |
32 | Filters in first encoder block (doubles each level) |
--depth |
3 | Encoder/decoder depth |
--num-classes |
4 | Output classes (4 = background + 3 tumor types) |
--device |
auto |
cuda or cpu
|
--num-workers |
0 | DataLoader workers (0 = safe for all environments) |
--resume |
None | Path to checkpoint to resume from |
Every epoch saves checkpoints/checkpoint_latest.pt. To resume after a shutdown:
python scripts/train3d.py \
--resume checkpoints/checkpoint_latest.pt \
--epochs 100To resume from the best checkpoint:
python scripts/train3d.py \
--resume checkpoints/best_model_dice_0.XXXX.pt \
--epochs 100| File | When | Contains |
|---|---|---|
checkpoints/best_model_dice_X.pt |
When val Dice improves | model, optimizer, epoch, metrics |
checkpoints/checkpoint_latest.pt |
Every epoch | model, optimizer, epoch, metrics |
checkpoints/checkpoint_epoch_N.pt |
Every 10 epochs | model, epoch, val Dice |
visualizations/epoch_NNN_sample_N.png |
Every 5 epochs | GT vs prediction comparison |
visualizations/training_curves.png |
End of training | Loss and Dice curves |
No dataset needed:
python scripts/generate_sample_data.py --n 50 --size 128
python scripts/train.py --epochs 30| Setup | Recommended config |
|---|---|
| CPU only | --batch 2 --base-filters 16 --depth 3 |
| 8GB GPU | --batch 4 --base-filters 32 --depth 3 |
| 16GB+ GPU | --batch 8 --base-filters 32 --depth 4 |
D_FRAMES = 4 (pseudo-3D depth) can be increased to 8 or 16 on GPUs with more VRAM — edit the constant at the top of scripts/train3d.py.
ReduceLROnPlateau with factor=0.5, patience=5 — halves the LR when validation loss stops improving for 5 epochs. Logged each time it fires.