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

Overview

Pytorch Medical Segmentation

Read Chinese Introduction:Here!

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.

Requirements

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

Notice

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

Done

  • 2D
  • 3D

TODO

  • metrics.py to evaluate your results
  • 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 Kangneng Zhou an email, his wechat number is: ellisgege666

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. Thank you to Cheng Chen, Daiheng Gao, Jie Zhang, Xing Tao, Weili Jiang and Shanshan Li for all the help I received.

Comments
  • 训练相关

    训练相关

    您好!有一个关于训练结果的问题想要请教一下。 我使用的网上下载的胰腺数据集,原数据和标签都是 nii.gz 格式的,因为是3d数据,所以用的是3d的网络来跑的。是在本地的计算机上跑的代码。默认设置的epoch是100 参数设置如下: image 但是我训练到后面,loss值是在下降,但是dice值就一直是0了,false_positive_rate以及false_negative_rate也很不正常,如下所示: image 想请问原因可以能为什么呢?是否和epoch数有关?因为我看您的原代码是500000,我设置100已经需要跑一段时间了。 其他的参数是否有要根据数据的三维尺寸调整的呢? 感谢回复!

    opened by LoinJi 12
  • the prediction results are all black

    the prediction results are all black

    I fixed the errors in the model prediction in the same way as you, but now the prediction results are all black. What's the problem. What I did was a dichotomy. During the test, there was such a warning: image

    opened by ARnnn 10
  • 模型训练效果较差

    模型训练效果较差

    我使用这个版本的 ResUNet 在我的数据上进行训练可以得到0.78左右的 Dice 值. 我使用您的模型对同样的数据进行训练模型无法进行收敛 Dice 值始终处在0.1以下. 我在对模型进行检查后仍未能发现问题.

    这是我训练的 log. 其中红色线为2DResUNet, 蓝色线为3D模型. image

    我原始的数据类型为 .dcm 类型, 使用脚本转为 .nii.gz 格式. 我使用 dicompyler 对转后的 .nii.gz 进行检查未发现数据存在问题.

    希望能够得到您的回复!

    opened by JohnMasoner 5
  • 关于小数据集下设置aug=true后,会导致测试时outputs值整体小于0.5

    关于小数据集下设置aug=true后,会导致测试时outputs值整体小于0.5

    我自己3d脊椎训练的数据集是7张nii.gz文件,epoch为20,batch为4. 设置aug=true后,进行推理时,手动输出outputs最大值小于0.5,导致result图像为空,但是设置false后就会正常(指result最大值会大于0.5)。 目前还没试验过其他数据集,这一点可以注意一下。

    opened by Fuzhiyuan 3
  • bug

    bug

    RuntimeError: More than one value for "spacing" found in subject images: {'label': (1.0468800067901611, 1.0468800067901611, 2.5), 'source': (0.712891, 0.712891, 2.49998)} image

    opened by qq1440837150 3
  • hi, question about the image size of .nrrd format.

    hi, question about the image size of .nrrd format.

    Thanks for your github.

    I'm testing with .nrrd format. however, there is an issue where the resulting image is enlarged. (ex: input size:256x256x256 --> result : 128x128x128) Also, the image is enlarged to 32-bit or greater precision. What part of main.py should I edit?

    opened by Jihunlee326 3
  • 我用更新后的代码预测时出现了错误

    我用更新后的代码预测时出现了错误

    我用您更新后的代码重新训练了模型,在预测时出现了这样的错误: File "main.py", line 519, in test aggregator_1.add_batch(labels, locations) File "/home/anran/.conda/envs/seg/lib/python3.6/site-packages/torchio/data/inference/aggregator.py", line 131, in add_batch self.patch_overlap, File "/home/anran/.conda/envs/seg/lib/python3.6/site-packages/torchio/data/inference/aggregator.py", line 82, in crop_batch diff = patch_shape - crop_shape ValueError: operands could not be broadcast together with shapes (2,) (3,)

    请问要怎么解决

    opened by ARnnn 2
  • main.py第250行loss = criterion(outputs, y)-->loss = criterion(logits, y)

    main.py第250行loss = criterion(outputs, y)-->loss = criterion(logits, y)

    你好,很感谢您的代码,我预测效果很差,多次修改损失函数都没有效果,看代码发现这里有点疑问,请问这里是不是错了? man.py代码: logits = torch.sigmoid(outputs) labels = logits.clone() labels[labels>0.5] = 1 labels[labels<=0.5] = 0 loss = criterion(outputs, y)#有问题?应该为loss = criterion(logits, y)

    opened by qianjinfighter 2
  • digital-copyright

    digital-copyright

    Hi MontaEllis!👋, I added this optional feature to digitally sign you source-code and track it on a blockchain node should you ever be audited or experience a software supply-chain attack. Simply compare the byte encrypted signature on your .git binary with the hash written to your immutable blockchain node. If they ever differ you should escalate. See the MontaEllis-digital-copyright for complete instructions on accessing your hash.. Feel free to contact me directly to review any questions before accepting. ~~Best: [email protected]

    opened by JudeSafo 1
  • Sharing models through Hugging Face Hub

    Sharing models through Hugging Face Hub

    Hi MontaEllis team!

    The Medical Segmentation project is fantastic. I see you host and share models with your server. Would you be interested in sharing your models in the Hugging Face Hub?

    This integration would allow you to freely download/upload models and make your work more accessible and visible to the rest of the ML community. We can help you set up a MontaEllis organization (examples, Facebook AI y Stanford NLP).

    Creating the repos and adding new models should be a relatively straightforward process. This is a step-by-step guide explaining the process in case you're interested. Please let us know if you would be interested and if you have any questions.

    Some of the benefits of sharing your models through the Hub would be:

    • Presence in the HF Hub might lower the entry of barrier to your medical models and increase their visibility.
      • Repos provide valuable metadata about their tasks, languages, metrics, etc. that make them discoverable
    • versioning, commit history, and diffs.
    • multiple features from TensorBoard visualizations, PapersWithCode integration, and more.

    Additionally, we have a library to access repositories programmatically (both downloading pre-trained models and pushing, with many nice things such as filtering, caching, etc.). If we want to try out this integration, I would suggest you add one or two models manually and then use the huggingface_hub library to implement downloading those models programmatically from pytorch-medical-segmentation. To read more about it, you might want to check our documentation to read more about it.

    Relevant references:

    Happy to hear your thoughts,

    Omar and the Hugging Face team (cc @osanseviero @abidlabs )

    opened by omarespejel 1
Owner
EasyCV-Ellis
公众号【easycv_ellis】博主,欢迎关注! @Easy-Shu 的兄弟公众号!
EasyCV-Ellis
Unoffical reMarkable AddOn for Firefox.

reMarkable for Firefox (Download) This repo converts the offical reMarkable Chrome Extension into a Firefox AddOn published here under the name "Unoff

Jelle Schutter 45 Nov 28, 2022
Pytorch Code for "Medical Transformer: Gated Axial-Attention for Medical Image Segmentation"

Medical-Transformer Pytorch Code for the paper "Medical Transformer: Gated Axial-Attention for Medical Image Segmentation" About this repo: This repo

Jeya Maria Jose 615 Dec 25, 2022
The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

MIC-DKFZ 1.2k Jan 4, 2023
Build a medical knowledge graph based on Unified Language Medical System (UMLS)

UMLS-Graph Build a medical knowledge graph based on Unified Language Medical System (UMLS) Requisite Install MySQL Server 5.6 and import UMLS data int

Donghua Chen 6 Dec 25, 2022
Multi-atlas segmentation (MAS) is a promising framework for medical image segmentation

Multi-atlas segmentation (MAS) is a promising framework for medical image segmentation. Generally, MAS methods register multiple atlases, i.e., medical images with corresponding labels, to a target image;

NanYoMy 13 Oct 9, 2022
A PyTorch implementation for V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation

A PyTorch implementation of V-Net Vnet is a PyTorch implementation of the paper V-Net: Fully Convolutional Neural Networks for Volumetric Medical Imag

Matthew Macy 606 Dec 21, 2022
Official and maintained implementation of the paper "OSS-Net: Memory Efficient High Resolution Semantic Segmentation of 3D Medical Data" [BMVC 2021].

OSS-Net: Memory Efficient High Resolution Semantic Segmentation of 3D Medical Data Christoph Reich, Tim Prangemeier, Özdemir Cetin & Heinz Koeppl | Pr

Christoph Reich 23 Sep 21, 2022
A pytorch-based deep learning framework for multi-modal 2D/3D medical image segmentation

A 3D multi-modal medical image segmentation library in PyTorch We strongly believe in open and reproducible deep learning research. Our goal is to imp

Adaloglou Nikolas 1.2k Dec 27, 2022
CoTr: Efficiently Bridging CNN and Transformer for 3D Medical Image Segmentation

CoTr: Efficient 3D Medical Image Segmentation by bridging CNN and Transformer This is the official pytorch implementation of the CoTr: Paper: CoTr: Ef

null 218 Dec 25, 2022
Medical Image Segmentation using Squeeze-and-Expansion Transformers

Medical Image Segmentation using Squeeze-and-Expansion Transformers Introduction This repository contains the code of the IJCAI'2021 paper 'Medical Im

askerlee 172 Dec 20, 2022
Semi Supervised Learning for Medical Image Segmentation, a collection of literature reviews and code implementations.

Semi-supervised-learning-for-medical-image-segmentation. Recently, semi-supervised image segmentation has become a hot topic in medical image computin

Healthcare Intelligence Laboratory 1.3k Jan 3, 2023
This repo holds code for TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation

TransUNet This repo holds code for TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation Usage

null 1.4k Jan 4, 2023
[CVPR'21] FedDG: Federated Domain Generalization on Medical Image Segmentation via Episodic Learning in Continuous Frequency Space

FedDG: Federated Domain Generalization on Medical Image Segmentation via Episodic Learning in Continuous Frequency Space by Quande Liu, Cheng Chen, Ji

Quande Liu 178 Jan 6, 2023
Shape-aware Semi-supervised 3D Semantic Segmentation for Medical Images

SASSnet Code for paper: Shape-aware Semi-supervised 3D Semantic Segmentation for Medical Images(MICCAI 2020) Our code is origin from UA-MT You can fin

klein 125 Jan 3, 2023
A collection of loss functions for medical image segmentation

A collection of loss functions for medical image segmentation

Jun 3.1k Jan 3, 2023
The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"

Swin-Unet The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"(https://arxiv.org/abs/2105.05537). A validatio

null 869 Jan 7, 2023
Context Axial Reverse Attention Network for Small Medical Objects Segmentation

CaraNet: Context Axial Reverse Attention Network for Small Medical Objects Segmentation This repository contains the implementation of a novel attenti

null 401 Dec 23, 2022
Jittor Medical Segmentation Lib -- The assignment of Pattern Recognition course (2021 Spring) in Tsinghua University

THU模式识别2021春 -- Jittor 医学图像分割 模型列表 本仓库收录了课程作业中同学们采用jittor框架实现的如下模型: UNet SegNet DeepLab V2 DANet EANet HarDNet及其改动HarDNet_alter PSPNet OCNet OCRNet DL

null 48 Dec 26, 2022
[MedIA2021]MIDeepSeg: Minimally Interactive Segmentation of Unseen Objects from Medical Images Using Deep Learning

MIDeepSeg: Minimally Interactive Segmentation of Unseen Objects from Medical Images Using Deep Learning [MedIA or Arxiv] and [Demo] This repository pr

Healthcare Intelligence Laboratory 92 Dec 8, 2022