unet.py: completed PyTorch U-Net baselinetrain.py: CLI training scriptevaluate.py: CLI evaluation / visualization scriptablation_registry.py: ablation experiment definitionsrun_experiments.py: batch runner for baseline, ablations, and combined improvementsrun_experiments.sh: shell wrapper aroundrun_experiments.pysummarize_experiments.py: build ablation tables and training-curve plotsoutputs/: default output directory
Install PyTorch with the CUDA command from the official PyTorch site first, then install the remaining packages:
pip install medpy scikit-image pillow tqdm matplotlib tensorboardtorchvision is not required by the current scripts.
The scripts expect the raw patient folders under a path like:
/path/to/BrainMRI/kaggle_3m
If your server path is different, pass it with --images or IMAGES_DIR=....
From Project_1_0506/brain-seg/pytorch:
bash run_experiments.shThe default runner now executes:
baselinebnbilineardropoutbce_diceadamwcosinestrong_augimproved
The shared default configuration is aligned with train.ipynb baseline:
IMAGE_SIZE=256EPOCHS=100STEPS_PER_EPOCH=0for full epochsBATCH_SIZE=16EVAL_BATCH_SIZE=16INIT_FEATURES=32VALIDATION_CASES=10VIS_IMAGES=200VIS_FREQ=10
All of them can be overridden with environment variables:
IMAGE_SIZE=256 BATCH_SIZE=8 EPOCHS=30 WORKERS=8 bash run_experiments.shYou can also run only a subset of experiments:
EXPERIMENTS=baseline,bn,bilinear,improved bash run_experiments.shIf you need to resume after partial completion:
SKIP_EXISTING=1 bash run_experiments.shBaseline:
python train.py \
--images /path/to/BrainMRI/kaggle_3m \
--output-root ./outputs \
--experiment-name baseline \
--epochs 100 \
--batch-size 16 \
--eval-batch-size 16 \
--image-size 256 \
--validation-cases 10 \
--init-features 32 \
--optimizer adam \
--loss dice \
--lr 3e-4 \
--vis-images 200 \
--vis-freq 10 \
--workers 4Single ablation example:
python train.py \
--images /path/to/BrainMRI/kaggle_3m \
--output-root ./outputs \
--experiment-name bn \
--epochs 100 \
--batch-size 16 \
--eval-batch-size 16 \
--image-size 256 \
--validation-cases 10 \
--init-features 32 \
--optimizer adam \
--loss dice \
--lr 3e-4 \
--batch-norm \
--vis-images 200 \
--vis-freq 10 \
--workers 4Combined improved:
python train.py \
--images /path/to/BrainMRI/kaggle_3m \
--output-root ./outputs \
--experiment-name improved \
--epochs 100 \
--batch-size 16 \
--eval-batch-size 16 \
--image-size 256 \
--validation-cases 10 \
--init-features 32 \
--optimizer adamw \
--loss bce_dice \
--bce-weight 0.4 \
--lr 1e-3 \
--weight-decay 1e-4 \
--scheduler cosine \
--batch-norm \
--bilinear \
--dropout 0.1 \
--aug-scale 0.10 \
--aug-angle 20 \
--vis-images 200 \
--vis-freq 10 \
--workers 4Evaluation:
python evaluate.py \
--images /path/to/BrainMRI/kaggle_3m \
--experiment-dir ./outputs/baseline \
--batch-size 16 \
--workers 4For each experiment directory:
config.json: training configurationhistory.csv: epoch metricsmetrics.json: best validation summaryweights/best.pt: best checkpointevaluation/metrics.json: final evaluation summaryevaluation/dsc_distribution.png: patient-level DSC plotevaluation/best_*.png,median_*.png,worst_*.png: overlay examples
After all experiments finish, the runner also creates:
outputs/summary/ablation_results.csvoutputs/summary/ablation_results.mdoutputs/summary/ablation_results.jsonoutputs/summary/train_loss_curves.pngoutputs/summary/valid_loss_curves.pngoutputs/summary/valid_dsc_curves.pngoutputs/summary/best_dsc_bar.png
- Run
bash run_experiments.sh. - Read the ablation table from
outputs/summary/ablation_results.csv. - Insert the training curves from
outputs/summary/*.png. - Use representative overlays from each experiment's
evaluation/directory when needed.
Reduce one or more of these:
BATCH_SIZEIMAGE_SIZEINIT_FEATURES
Example:
IMAGE_SIZE=96 BATCH_SIZE=4 INIT_FEATURES=16 bash run_experiments.sh