Skip to content

2D UNet Image Segmentation for HipMRI dataset #269

Open
shans-cloud wants to merge 13 commits intoshakes76:topic-recognitionfrom
shans-cloud:topic-recognition
Open

2D UNet Image Segmentation for HipMRI dataset #269
shans-cloud wants to merge 13 commits intoshakes76:topic-recognitionfrom
shans-cloud:topic-recognition

Conversation

@shans-cloud
Copy link

This pull request introduces a finalised codebase for the 2D U-Net segmentation project on the HipMRI dataset. It includes full training, prediction, dataset handling, and utility modules.

Key components:

  • dataset.py - Loads and preprocesses 2D NIfTI slices
  • modules.py – Defines the U-Net architecture with DoubleConv blocks, encoder–decoder skip connections, and raw logits output for multi-class training
  • train.py – Implements the full training loop with Focal + Dice loss
  • predict.py – Performs model inference on test data, computes per-class and mean Dice coefficients, and generates visual prediction outputs
  • README.md - Provides project overview, model architecture summary, and evaluation results

Notes:

  • Outputs (plots, predictions, metrics) are stored in the visualisation folders

- `to_channels()` for one-hot encoding segmentation labels.
- `load_data_2D()` for loading and normalising 2D MRI slices.
- Code sourced from appendix reference of task sheet.
…slices

- Implemented PyTorch Dataset class to load HipMRI study 2D Nifti slice data
- Handles normalisation, and binary mask preprocessing for segmentation
- Added skimage.transform.resize for consistent 256x128 input size
- Denormalised images before showing sample visualisations
- Changed prostate mask to correctly identify prostate region (label 5)
- Added .permute(1, 2, 0) for (C, H, W) format
- Removed ImageNet normalisation to preserve grayscale MRI intensity
- Removed redundant tensor casts
- Cleaned imports and removed visualisation
- Replaced ImageNet based normalisation with min-max scaling for grayscale slices
- Added show_epoch_predictions() for visualising 3 model outputs per epoch
- Implemented plot_loss() to track training loss over epochs
- Added save_model_checkpoint() and load_model_checkpoint() to allow model states to be reloaded
- Removed unused function denormalise_image()
- Added DoubleConv class combining two 3x3 Conv2D layers with BatchNorm, ReLU and Dropout
- Implemented full UNet model for 2D prostate MRI segmentation. It includes:
	- Encoder (downsampling), bottleneck, and decoder (upsampling with skip connections)
	- Outputs sigmoid-activated probability maps in the [0, 1] range for binary segmentation
…d v2 transforms

- Added Image and Mask wrappers for transform
- Removed hardcoded prostate-only binary mask conversion
- Changed out_channels to 6 for multi-class prediction
- Removed final sigmoid activated to output logits for CrossEntropy/Focal compatibility
- Reduced feature depth for faster convergence
- Updated model docstrings
…ovements

- Updated to_channels() for fixed 6 class one hot encoding
- Rewrote show_epoch_predictions() for multi-class predictions and Dice per class 5
- Added validation loss plotting and per-class Dice curve visualisation
- Improved checkpointing functions
…e Loss

- Includes data loading, augmentation, training and validation loops
- Adds checkpointing, loss plotting and Dice per class visualisation
- Uses combined Focal Dice Loss for class imbalance handling
- Evaluates trained model on test dataset using Dice metric
- Outputs per-class Dice, Dice mean and Dice loss summary
- Saves qualitative prediction visualisations
@24msingh24
Copy link

24msingh24 commented Nov 20, 2025

This is an initial inspection, no action is required at this point

2D UNet – Prostate MRI Segmentation → Easy

Category   Marks Comments
Algorithm solves the problem 5 5 Proper 2D UNet implemented with encoder-decoder skip connections; Focal + Dice loss used; early stopping is done; training and test metrics are shown, visual predictions provided. Fully addresses segmentation task.
Implementation functions as intended 3 3 Code modular (dataset.py, modules.py, train.py, predict.py), data loading, augmentation, training loop, inference all seem to be functional.
Good design 1 1 Clear modular separation and clean encoder-decoder design.
Commenting 1 0.75 Docstrings present, and inline comments are minimal but readable.
Algorithm above Normal Difficulty 5 0  
Algorithm is Hard difficulty 5 0 Easy
Section IV : Max mark 10 from 20   9.75  

 Discussion: None provided. This is needed.

Suggestions/Notes:

  • Well done.

@gayanku
Copy link
Collaborator

gayanku commented Nov 24, 2025

Marking

Good/OK/Fair Practice (Design/Commenting, TF/Torch Usage)
Good design and implementation.
Spacing and comments.
Header blocks.
Recognition Problem
Good solution to problem.
Driver Script present.
File structure present.
Good Usage & Demo & Visualisation & Data usage.
Module present.
Commenting present.
No Data leakage found.
Difficulty : Easy. Easy. Unet 2D-10
Commit Log
Good Meaningful commit messages.
Good Progressive commits.
Documentation
Readme :Good.
Model/technical explanation :Acceptable. -2
Description and Comments :Good.
Markdown used and PDF submitted.
Pull Request
Successful Pull Request (Working Algorithm Delivered on Time in Correct Branch).
No Feedback required.
Request Description is good.
TOTAL-12

Marked as per the due date and changes after which aren't necessarily allowed to contribute to grade for fairness.
Subject to approval from Shakes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants