junqiangchen/PytorchDeepLearing

Meidcal Image Segmentation Pytorch Version

What it solves

Image segmentation is a common task in medical imaging and computer vision. This project offers ready-to-use PyTorch implementations of segmentation networks, loss functions, and evaluation metrics, reducing the need to code these from scratch. It also provides examples for deploying a segmentation model as a web service and for interactive segmentation with popular tools.

How it works

The repository contains PyTorch code (using PyTorch 1.10.0) for:

  • Segmentation network architectures: the Unet and Vnet families, each available in 2D and 3D versions.
  • Loss functions: binary crossentropy, dice loss, focal loss (with sigmoid variants), categorical crossentropy, dice, and focal losses—all available for 2D and 3D. Also includes SSIM and MS-SSIM for image similarity, and centerline dice loss for vessel segmentation.
  • Evaluation metrics: nine types including dice, surface distance, jaccard, VOE, RVD, FNR, FPR, ASSD, RMSD, and MSD.
  • A Flask application (flask_app.py) as a demo for deploying a segmentation model as a REST service.
  • Interactive segmentation scripts: SegmentwithSAM.py, SegmentwithSAM2.py, SegmentwithVISTA3D.py, and SegmentwithnnInteractive.py, which support different input types (bounding box, points, mask, lasso).

Who it's for

Researchers, developers, and engineers working on medical image segmentation or other image segmentation tasks who want to use or extend existing models, losses, and metrics, or quickly deploy a segmentation service.

Highlights

  • 2D and 3D versions of Unet and Vnet segmentation networks.
  • A comprehensive set of loss functions, including binary and categorical forms, plus SSIM/MS-SSIM and centerline dice.
  • Nine segmentation evaluation metrics.
  • Flask demo for model deployment.
  • Interactive segmentation using SAM, SAM2, VISTA3D, and nnInteractive.

Related

  • Project
  • Project
  • Project
  • Project