This repository contains code for pelvis segmentation using supervised and semi-supervised deep learning techniques. The project leverages MONAI and PyTorch to train 3D U-Net models for medical image segmentation on T2-weighted MRI scans.
This project was developed as coursework for UCL's Machine Learning for Medical Imaging module.
- Preprocessing – MRI scans are loaded and preprocessed using MONAI, including normalization and augmentation.
- Supervised Training – The model is trained with ground truth labels to learn segmentation patterns.
- Semi-Supervised Training – A combination of labeled and unlabeled data is used to improve model generalization.
- Inference & Evaluation – The trained model is evaluated on a test set, with performance metrics computed.
This project uses the Cross-institution Male Pelvic Structures dataset, which includes T2-weighted MRI images with annotations for eight anatomical structures. The data was collected from multiple institutions, and the segmentations were manually annotated by biomedical imaging researchers.
You can download the dataset here:
The following Python packages are required for running the project:
- PyTorch (Deep learning framework)
- Nibabel (Medical imaging file handling)
- MONAI (Medical image processing and augmentation)
- Einops (Tensor manipulation)
- scikit-image (Image processing)
- Matplotlib (Visualization)
- Requests (HTTP requests handling)
Create a Conda environment and install dependencies:
conda create -n mphy0041-cw2-pt -c conda-forge pytorch=2.4 torchvision=0.14 nibabel=5.3
conda activate mphy0041-cw2-pt
pip install monai[einops,skimage,matplotlib]
pip install requests- Set up the environment (see installation steps)
- Ensure the dataset is placed inside cw2/data/
- Run the training script:
cd path/to/cw2 # Replace with actual path
python main.pyUse the provided SLURM batch script:
sbatch ML_RUN_CPU.sh
ML_RUN_CPU.sh:
#!/bin/bash -l
#SBATCH --partition COMPUTE
#SBATCH --nodes 1
#SBATCH -n12
#SBATCH --mem-per-cpu 40G
#SBATCH --time 24:00:00
#SBATCH --job-name ML_RUN_CPU
#SBATCH --output ML_RUN_CPU.log
XDG_RUNTIME_DIR=""
export port=$(shuf -i8000-9999 -n1)
export node=$(hostname -s)
export user=$(whoami)
export cluster=$(hostname -f | awk -F"." '{print $2}')
# Load Conda and activate environment
eval "$(/share/apps/anaconda/3-2022.05/bin/conda shell.bash hook)"
conda create -n mphy0041-cw2-pt -c conda-forge pytorch=2.4 torchvision=0.14 nibabel=5.3
conda activate mphy0041-cw2-pt
pip install monai[einops,skimage,matplotlib]
pip install requests
cd /home/xzcapbel/MedicalPhysics/cw2
python main.pyThis project is a coursework submission and is for display purposes only. It is not intended for commercial or production use. For research or development purposes, please refer to the official dataset page for proper usage and licensing.
This project was developed by:
