Pytorch-Medical-Segmentation

MontaEllisMIT更新放缓

基于 PyTorch 的医学图像分割非官方实现,支持 2D 和 3D 数据,方便快速搭建和训练分割模型。

This repository is an unoffical PyTorch implementation of Medical segmentation in 2D and 3D.

暂无版本917star198fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
pip install torchio<=0.18.20
python main.py
硬件要求按 README 说明

README 未说明显存、GPU 型号或 CPU 运行要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

非官方 PyTorch 医学图像 2D/3D 分割实现,内置多种网络与训练测试脚本

基于 PyTorch 的医学图像分割非官方实现,支持 2D 和 3D 数据,方便快速搭建和训练分割模型。

核心能力

  • 集成 unet、unet++、deeplab 等 2D 分割网络
  • 集成 unet3d、vnet3d、unetr 等 3D 分割网络
  • 用 patch 方式处理图像,不要求尺寸严格一致
  • 通过 hparam.py 统一切换 2D/3D 与训练测试模式
  • 提供 metrics.py 评估分割结果

容易踩的坑

依赖 pytorch1.7 与 torchio<=0.18.20,版本不匹配易报错;使用前需把源图和标签转成同一格式,且标签用 1 而非 255 标注;多类别需自行改代码,作者不识别具体类别;该仓库已废弃,建议改用 SLab-Medical-Segmentation

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Pytorch Medical Segmentation

    Read Chinese Introduction:Here!

    ❗️🚨 Important Notice 🚨❗️

    🔗 Please refer to our new repository: SLab-Medical-Segmentation

    🛑 The existing repository has been deprecated!

    Notes

    We are planning a major update to the code in the near future, so if you have any suggestions, please feel free to email me or mention them in the issue.

    Recent Updates

    • 2021.1.8 The train and test codes are released.
    • 2021.2.6 A bug in dice was fixed with the help of Shanshan Li.
    • 2021.2.24 A video tutorial was released(https://www.bilibili.com/video/BV1gp4y1H7kq/).
    • 2021.5.16 A bug in Unet3D implement was fixed.
    • 2021.5.16 The metric code is released.
    • 2021.6.24 All parameters can be adjusted in hparam.py.
    • 2021.7.7 Now you can refer medical classification in Pytorch-Medical-Classification
    • 2022.5.15 Now you can refer semi-supervised learning on medical segmentation in SSL-For-Medical-Segmentation
    • 2022.5.17 We update the training and inference code and fix some bugs.

    Requirements

    • pytorch1.7
    • torchio<=0.18.20
    • python>=3.6

    Notice

    • You can modify hparam.py to determine whether 2D or 3D segmentation and whether multicategorization is possible.
    • We provide algorithms for almost all 2D and 3D segmentation.
    • This repository is compatible with almost all medical data formats(e.g. nii.gz, nii, mhd, nrrd, ...), by modifying fold_arch in hparam.py of the config. I would like you to convert both the source and label images to the same type before using them, where labels are marked with 1, not 255.
    • If you want to use a multi-category program, please modify the corresponding codes by yourself. I cannot identify your specific categories.
    • Whether in 2D or 3D, this project is processed using patch. Therefore, images do not have to be strictly the same size. In 2D, however, you should set the patch large enough.

    Prepare Your Dataset

    Example1

    if your source dataset is :

    source_dataset
    ├── source_1.mhd
    ├── source_1.zraw
    ├── source_2.mhd
    ├── source_2.zraw
    ├── source_3.mhd
    ├── source_3.zraw
    ├── source_4.mhd
    ├── source_4.zraw
    └── ...
    

    and your label dataset is :

    label_dataset
    ├── label_1.mhd
    ├── label_1.zraw
    ├── label_2.mhd
    ├── label_2.zraw
    ├── label_3.mhd
    ├── label_3.zraw
    ├── label_4.mhd
    ├── label_4.zraw
    └── ...
    

    then your should modify fold_arch as *.mhd, source_train_dir as source_dataset and label_train_dir as label_dataset in hparam.py

    Example2

    if your source dataset is :

    source_dataset
    ├── 1
        ├── source_1.mhd
        ├── source_1.zraw
    ├── 2
        ├── source_2.mhd
        ├── source_2.zraw
    ├── 3
        ├── source_3.mhd
        ├── source_3.zraw
    ├── 4
        ├── source_4.mhd
        ├── source_4.zraw
    └── ...
    

    and your label dataset is :

    label_dataset
    ├── 1
        ├── label_1.mhd
        ├── label_1.zraw
    ├── 2
        ├── label_2.mhd
        ├── label_2.zraw
    ├── 3
        ├── label_3.mhd
        ├── label_3.zraw
    ├── 4
        ├── label_4.mhd
        ├── label_4.zraw
    └── ...
    

    then your should modify fold_arch as */*.mhd, source_train_dir as source_dataset and label_train_dir as label_dataset in hparam.py

    Training

    • without pretrained-model
    set hparam.train_or_test to 'train'
    python main.py
    
    • with pretrained-model
    set hparam.train_or_test to 'train'
    python main.py -k True
    

    Inference

    • testing
    set hparam.train_or_test to 'test'
    python main.py
    

    Examples

    Tutorials

    Done

    Network

    • 2D
    • 3D

    Metric

    • metrics.py to evaluate your results

    TODO

    • dataset
    • benchmark
    • nnunet

    By The Way

    This project is not perfect and there are still many problems. If you are using this project and would like to give the author some feedbacks, you can send Me an email.

    Acknowledgements

    This repository is an unoffical PyTorch implementation of Medical segmentation in 3D and 2D and highly based on MedicalZooPytorch and torchio. Thank you for the above repo. The project is done with the supervisions of Prof. Ruoxiu Xiao, Prof. Shuang Song and Dr. Cheng Chen. Thank you to Youming Zhang, Daiheng Gao, Jie Zhang, Xing Tao, Weili Jiang and Shanshan Li for all the help I received.