A pytorch-based deep learning framework for multi-modal 2D/3D medical image segmentation

Overview

A 3D multi-modal medical image segmentation library in PyTorch

Contributors Forks Stargazers Issues Open In Colab

We strongly believe in open and reproducible deep learning research. Our goal is to implement an open-source medical image segmentation library of state of the art 3D deep neural networks in PyTorch. We also implemented a bunch of data loaders of the most common medical image datasets. This project started as an MSc Thesis and is currently under further development. Although this work was initially focused on 3D multi-modal brain MRI segmentation we are slowly adding more architectures and data-loaders.

Top priorities 21-07

[Update] 21-07 We have just received a brand new GPU. The project developedment was postponed due to lack of computational resources. We will be back with more updates. Please Watch our Github repository for releases to be notified. We are always looking for passionate open-source contributos. Full credits will be given.

  • Project restructure, API/CLI design ++
  • Minimal test prediction example with pre-trained models
  • Overlapping and non-overlapping inference
  • Finalize preprocessing on Brats datasets
  • Save produced 3d-total-segmentation as nifty files
  • Medical image decathlon dataloaders
  • StructSeg 2019 challenge dataloaders
  • More options for 2D architectures
  • Rewrite manual
  • New notebooks with google colab support

Quick Start

  • If you want to quickly understand the fundamental concepts for deep learning in medical imaging, we strongly advice to check our blog post. We provide a general high-level overview of all the aspects of medical image segmentation and deep learning. For a broader overview on MRI applications find my latest review article.

  • To grasp more fundamental medical imaging concepts, check out our post on coordinate systems and DICOM images.

  • For a more holistic approach on Deep Learning in MRI you may advice my thesis this.

  • Alternatively, you can create a virtual environment and install the requirements. Check the installation folder for more instructions.

  • You can also take a quick glance at the manual.

  • If you do not have a capable environment or device to run this projects then you could give Google Colab a try. It allows you to run the project using a GPU device, free of charge. You may try our Colab demo using this notebook:Open In Colab

Implemented architectures

  • U-Net3D Learning Dense Volumetric Segmentation from Sparse Annotation Learning Dense Volumetric Segmentation from Sparse Annotation

  • V-net Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation

  • ResNet3D-VAE 3D MRI brain tumor segmentation using auto-encoder regularization

  • U-Net Convolutional Networks for Biomedical Image Segmentation

  • SkipDesneNet3D 3D Densely Convolutional Networks for Volumetric Segmentation

  • HyperDense-Net A hyper-densely connected CNN for multi-modal image segmentation

  • multi-stream Densenet3D A hyper-densely connected CNN for multi-modal image segmentation

  • DenseVoxelNet Automatic 3D Cardiovascular MR Segmentation with Densely-Connected Volumetric ConvNets

  • MED3D Transfer learning for 3D medical image analysis

  • HighResNet3D On the Compactness, Efficiency, and Representation of 3D Convolutional Networks: Brain Parcellation as a Pretext Task

Implemented medical imaging data-loaders

Task Data Info/ Modalities Train/Test Volume size Classes Dataset size (GB)
Iseg 2017 T1, T2 10 / 10 144x192x256 4 0.72
Iseg 2019 T1, T2 10 / 13 144x192x256 4 0.75
MICCAI BraTs2018 FLAIR, T1w, T1gd,T2w 285 / - 240x240x155 9 or 4 2.4
MICCAI BraTs2019 FLAIR, T1w, T1gd,T2w 335 / 125 240x240x155 9 or 4 4
Mrbrains 2018 FLAIR, T1w, T1gd,T2w 8 240x240x48 9 or 4 0.5
IXI brain development Dataset T1,T2 no labels 581 (110~150)x256x256 - 8.7
MICCAI Gleason 2019 Challenge 2D pathology images ~250 5K x 5K - 2.5

Preliminary results

Visual results on Iseg-2017

Iseg and Mr-brains

Model # Params (M) MACS(G) Iseg 2017 DSC (%) Mr-brains 4 classes DSC (%)
Unet3D 17 M 0.9 93.84 88.61
Vnet 45 M 12 87.21 84.09
DenseNet3D 3 M 5.1 81.65 79.85
SkipDenseNet3D 1.5 M 31 - -
DenseVoxelNet 1.8 M 8 - -
HyperDenseNet 10.4 M 5.8 - -

Usage

How to train your model

  • For Iseg-2017 :
python ./examples/train_iseg2017_new.py --args
  • For MR brains 2018 (4 classes)
python ./examples/train_mrbrains_4_classes.py --args
  • For MR brains 2018 (8 classes)
python ./examples/train_mrbrains_9_classes.py --args
  • For MICCAI 2019 Gleason Challenge
python ./examples/test_miccai_2019.py --args
  • The arguments that you can modify are extensively listed in the manual.

Inference

How to test your trained model in a medical image

python ./tests/inference.py --args

Covid-19 segmentation and classification

We provide some implementations around Covid-19 for humanitarian purposes. In detail:

Classification model

  • COVID-Net A Tailored Deep Convolutional Neural Network Design for Detection of COVID-19 Cases from Chest Radiography Images

Datasets

Classification from 2D images:

3D COVID-19 segmentation dataset

Latest features (06/2020)

  • On the fly 3D total volume visualization
  • Tensorboard and PyTorch 1.4+ support to track training progress
  • Code cleanup and packages creation
  • Offline sub-volume generation
  • Add Hyperdensenet, 3DResnet-VAE, DenseVoxelNet
  • Fix mrbrains,Brats2018,Brats2019, Iseg2019, IXI,MICCAI 2019 gleason challenge dataloaders
  • Add confusion matrix support for understanding training dynamics
  • Some Visualizations

Support

If you really like this repository and find it useful, please consider (★) starring it, so that it can reach a broader audience of like-minded people. It would be highly appreciated :) !

Contributing to Medical ZOO

If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues. More info on the contribute directory.

Current team

Ilias Papastatis, Sergios Karagianakos and Nikolas Adaloglou

License , citation and acknowledgements

Please advice the LICENSE.md file. For usage of third party libraries and repositories please advise the respective distributed terms. It would be nice to cite the original models and datasets. If you want, you can also cite this work as:

@MastersThesis{adaloglou2019MRIsegmentation,
author = {Adaloglou Nikolaos},
title={Deep learning in medical image analysis: a comparative analysis of
multi-modal brain-MRI segmentation with 3D deep neural networks},
school = {University of Patras},
note="\url{https://github.com/black0017/MedicalZooPytorch}",
year = {2019},
organization={Nemertes}}

Acknowledgements

In general, in the open source community recognizing third party utilities increases the credibility of your software. In deep learning, academics tend to skip acknowledging third party repos for some reason. In essence, we used whatever resource we needed to make this project self-complete, that was nicely written. However, modifications were performed to match the project structure and requirements. Here is the list of the top-based works: HyperDenseNet model. Most of the segmentation losses from here. 3D-SkipDenseNet model from here. 3D-ResNet base model from here. Abstract model class from MimiCry project. Trainer and Writer class from PyTorch template. Covid-19 implementation based on our previous work from here. MICCAI 2019 Gleason challenge data-loaders based on our previous work from here. Basic 2D Unet implementation from here.Vnet model from here

Comments
  • 'Namespace' object has no attribute 'samples_train'

    'Namespace' object has no attribute 'samples_train'

    command: !python test_miccai_2019.py --dataset_name MICCAI_2019_pathology_challenge --nEpochs 2 --opt adam --model UNET2D

    output:

    2020-05-01 07:37:33.986079: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
    Traceback (most recent call last):
      File "test_miccai_2019.py", line 86, in <module>
        main()
      File "test_miccai_2019.py", line 34, in main
        path='.././datasets')
      File "/content/MedicalZooPytorch/lib/medloaders/__init__.py", line 17, in generate_datasets
        samples_train = args.samples_train
    AttributeError: 'Namespace' object has no attribute 'samples_train'
    

    updated command : !python test_miccai_2019.py --dataset_name MICCAI_2019_pathology_challenge --nEpochs 2 --opt adam --model UNET2D --samples_train 10

    ouput:

    usage: test_miccai_2019.py [-h] [--batchSz BATCHSZ]
                               [--dataset_name DATASET_NAME] [--nEpochs NEPOCHS]
                               [--dim DIM [DIM ...]] [--classes CLASSES]
                               [--inChannels INCHANNELS]
                               [--inModalities INMODALITIES] [--fold_id FOLD_ID]
                               [--lr LR] [--cuda] [--resume PATH]
                               [--model {VNET,VNET2,UNET3D,DENSENET1,DENSENET2,DENSENET3,HYPERDENSENET,UNET2D}]
                               [--opt {sgd,adam,rmsprop}]
    test_miccai_2019.py: error: unrecognized arguments: --samples_train 10
    

    Other way around by altering the test_miccai_2019.py code:

    medical_loaders.generate_datasets(args, path='.././datasets',samples_train=samples_train,
    samples_val=samples_val)
    

    Adding samples_train and Samples_val ,rises error in generate_dataset()

    opened by maddy023 4
  • AttributeError: 'MRIDatasetMRBRAINS2018' object has no attribute 'affine'

    AttributeError: 'MRIDatasetMRBRAINS2018' object has no attribute 'affine'

    when load processed data, there is a bug

            if load:
                ## load pre-generated data
                self.list = utils.load_list(self.save_name)
                return
         ...
            self.affine = img_loader.load_affine_matrix(list_reg_t1[0]) # it is a bug
    
    opened by Healingl 2
  • RuntimeError: Expected 5-dimensional input for 5-dimensional weight 8 4 3 3 3, but got 4-dimensional input of size [4, 256, 64, 64] instead

    RuntimeError: Expected 5-dimensional input for 5-dimensional weight 8 4 3 3 3, but got 4-dimensional input of size [4, 256, 64, 64] instead

    Hi, When I want to train on BraTS2018, I use this command line "python train_brats2018_new.py"

    It shows this problem

    Summary train Epoch 1: Loss:0.7025 DSC:29.7528 Background : 0.8263 NCR/NET : 0.0612 ED : 0.2336 ET : 0.0689 Traceback (most recent call last): File "train_brats2018_new.py", line 75, in main() File "train_brats2018_new.py", line 33, in main trainer.training() File "/content/drive/My Drive/MedicalZooPytorch/lib/train/trainer.py", line 38, in training self.validate_epoch(epoch) File "/content/drive/My Drive/MedicalZooPytorch/lib/train/trainer.py", line 83, in validate_epoch output = self.model(input_tensor) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, **kwargs) File "/content/drive/My Drive/MedicalZooPytorch/lib/medzoo/Vnet.py", line 150, in forward out16 = self.in_tr(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, **kwargs) File "/content/drive/My Drive/MedicalZooPytorch/lib/medzoo/Vnet.py", line 58, in forward out = self.conv1(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 480, in forward self.padding, self.dilation, self.groups) RuntimeError: Expected 5-dimensional input for 5-dimensional weight 16 4 5 5 5, but got 4-dimensional input of size [4, 256, 64, 64] instead

    Could you help me solve that?

    opened by xuanxu92 2
  • digital-copyright

    digital-copyright

    Hi black0017!👋, I added this optional feature to digitally sign you source-code and track it should you ever be audited or experience a software supply-chain attack. Simply compare the byte encrypted signature on your .git file with the hash written to your immutable blockchain node.See the black0017-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
  • ResNet3D VAE fix

    ResNet3D VAE fix

    Hi there,

    I was just playing around with the package and found a typo in ResNet3D VAE constructor that prevents network for working with inputs where x,y,z dimensions are different (e.g., 56, 64, 48).

    Thanks! Paul

    bug 
    opened by pyushkevich 1
  • ValueError: low >= high

    ValueError: low >= high

    !python test_covid_ct.py --dataset_name covid_seg

    2020-05-01 11:52:26.733364: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
    COVID SEGMENTATION DATASET
    0
    Mode: train Subvolume samples to generate:  10  Volumes:  0
    Traceback (most recent call last):
      File "test_covid_ct.py", line 76, in <module>
        main()
      File "test_covid_ct.py", line 27, in main
        path='.././datasets')
      File "/content/MedicalZooPytorch/lib/medloaders/__init__.py", line 79, in generate_datasets
        fold=args.fold_id, samples=samples_train, save=True)
      File "/content/MedicalZooPytorch/lib/medloaders/Covid_Segmentation_dataset.py", line 70, in __init__
        self.create_sub_volumes()
      File "/content/MedicalZooPytorch/lib/medloaders/Covid_Segmentation_dataset.py", line 96, in create_sub_volumes
        random_index = np.random.randint(total)
      File "mtrand.pyx", line 743, in numpy.random.mtrand.RandomState.randint
      File "_bounded_integers.pyx", line 1260, in numpy.random._bounded_integers._rand_int64
    ValueError: low >= high
    
    opened by maddy023 1
  • pretrained models for COVID-19 CT segmentation

    pretrained models for COVID-19 CT segmentation

    Hi @black0017 ,

    Thanks for your great work.

    I notice that you are also working on pre-trained models on public datasets.

    Here is a benchmark for lung and infection segmentation in COVID-19 CT scans.

    Are you interested in including this COVID-19 segmentation dataset for pre-trained models?

    Best regards, Jun

    opened by JunMa11 1
  • PEXP -> PEPX

    PEXP -> PEPX

    From Wang 2020:

    "It can be observed that the COVID-Net network architecture makes heavy use of a lightweight residual projection-expansion-projection-extension (PEPX) design pattern."

    opened by glennmatlin 0
  • PEXP -> PEPX

    PEXP -> PEPX

    From Wang 2020:

    "It can be observed that the COVID-Net network architecture makes heavy use of a lightweight residual projection-expansion-projection-extension (PEPX) design pattern."

    opened by glennmatlin 0
  • Low validation DSC when training on Brats2018

    Low validation DSC when training on Brats2018

    Hello, First of all, thanks for the amazing work. Question: I tried to train the Unet3D model on bratS 2018 dataset using the 'train_brats_2018_new.py'. but I got lower validation DSC and higher validation loss, I think the model is facing some trouble on validation set: image

    opened by MohammedAdelFahmi 1
  • MICCAI_BraTS_2018_Data_Training/brats2018-list-' + mode + '-samples-' + str(samples) + '.txt'

    MICCAI_BraTS_2018_Data_Training/brats2018-list-' + mode + '-samples-' + str(samples) + '.txt'

    When I run "brats2018.py", I do not know what should be in this file

    self.save_name = self.root + '/MICCAI_BraTS_2018_Data_Training/brats2018-list-' + mode + '-samples-' + str( samples) + '.txt'

    Please help me.

    opened by hu-yj 0
  • question about train

    question about train

    When I used the mrbrains18 dataset for training, the following error occurred Traceback (most recent call last): File "./train_mrbrains_9_classes.py", line 81, in main() File "./train_mrbrains_9_classes.py", line 26, in main path='/home/zwj/MedicalZooPytorch-master/datasets/mrbrains_2018/training') File "/home/zwj/MedicalZooPytorch-master/lib/medloaders/init.py", line 50, in generate_datasets split_id=0, samples=samples_train, load=args.loadData) AttributeError: 'Namespace' object has no attribute 'loadData'

    opened by zhuangss 5
  • AttributeError: 'Namespace' object has no attribute 'loadData'

    AttributeError: 'Namespace' object has no attribute 'loadData'

    Hi,

    When trying to do inference using iseg2017 model. I am getting below error

    File "inference.py", line 80, in <module> main() File "inference.py", line 24, in main training_generator, val_generator, full_volume, affine = medical_loaders.generate_datasets(args, File "/mnt/nas02/Sampledata_BrainVolumetry/brain_try/MedicalZoo/MedicalZooPytorch/lib/medloaders/__init__.py", line 28, in generate_datasets split_id=split_idx, samples=samples_train, load=args.loadData) AttributeError: 'Namespace' object has no attribute 'loadData'

    When I check inference.py file its not taking any input argument for loadData

    opened by AkhilaPhenomx 1
  • Example command lines for running COVID segmentation example?

    Example command lines for running COVID segmentation example?

    Can you please provide the exact command lines to train and infer a segmentation model on the COVID dataset? I see you've provided data loaders, but it's not quite clear what commands to use.

    Thanks.

    documentation 
    opened by daquang 0
Owner
Adaloglou Nikolas
Human-Centered AI PhD Researcher.
Adaloglou Nikolas
Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal, multi-exposure and multi-focus image fusion.

U2Fusion Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal (VIS-IR, medical), multi

Han Xu 129 Dec 11, 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
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
We present a framework for training multi-modal deep learning models on unlabelled video data by forcing the network to learn invariances to transformations applied to both the audio and video streams.

Multi-Modal Self-Supervision using GDT and StiCa This is an official pytorch implementation of papers: Multi-modal Self-Supervision from Generalized D

Facebook Research 42 Dec 9, 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
Multi-Modal Machine Learning toolkit based on PyTorch.

简体中文 | English TorchMM 简介 多模态学习工具包 TorchMM 旨在于提供模态联合学习和跨模态学习算法模型库,为处理图片文本等多模态数据提供高效的解决方案,助力多模态学习应用落地。 近期更新 2022.1.5 发布 TorchMM 初始版本 v1.0 特性 丰富的任务场景:工具

njustkmg 1 Jan 5, 2022
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
ivadomed is an integrated framework for medical image analysis with deep learning.

Repository on the collaborative IVADO medical imaging project between the Mila and NeuroPoly labs.

null 144 Dec 19, 2022
Medical image analysis framework merging ANTsPy and deep learning

ANTsPyNet A collection of deep learning architectures and applications ported to the python language and tools for basic medical image processing. Bas

Advanced Normalization Tools Ecosystem 118 Dec 24, 2022
Self-supervised Multi-modal Hybrid Fusion Network for Brain Tumor Segmentation

JBHI-Pytorch This repository contains a reference implementation of the algorithms described in our paper "Self-supervised Multi-modal Hybrid Fusion N

FeiyiFANG 5 Dec 13, 2021
Code and pre-trained models for MultiMAE: Multi-modal Multi-task Masked Autoencoders

MultiMAE: Multi-modal Multi-task Masked Autoencoders Roman Bachmann*, David Mizrahi*, Andrei Atanov, Amir Zamir Website | arXiv | BibTeX Official PyTo

Visual Intelligence & Learning Lab, Swiss Federal Institute of Technology (EPFL) 385 Jan 6, 2023
Multi-Modal Machine Learning toolkit based on PaddlePaddle.

简体中文 | English PaddleMM 简介 飞桨多模态学习工具包 PaddleMM 旨在于提供模态联合学习和跨模态学习算法模型库,为处理图片文本等多模态数据提供高效的解决方案,助力多模态学习应用落地。 近期更新 2022.1.5 发布 PaddleMM 初始版本 v1.0 特性 丰富的任务

njustkmg 520 Dec 28, 2022
Copy Paste positive polyp using poisson image blending for medical image segmentation

Copy Paste positive polyp using poisson image blending for medical image segmentation According poisson image blending I've completely used it for bio

Phạm Vũ Hùng 2 Oct 19, 2021
TorchIO is a Medical image preprocessing and augmentation toolkit for deep learning. Part of the PyTorch Ecosystem.

Medical image preprocessing and augmentation toolkit for deep learning. Part of the PyTorch Ecosystem.

Fernando Pérez-García 1.6k Jan 6, 2023
Deep RGB-D Saliency Detection with Depth-Sensitive Attention and Automatic Multi-Modal Fusion (CVPR'2021, Oral)

DSA^2 F: Deep RGB-D Saliency Detection with Depth-Sensitive Attention and Automatic Multi-Modal Fusion (CVPR'2021, Oral) This repo is the official imp

如今我已剑指天涯 46 Dec 21, 2022
A keras-based real-time model for medical image segmentation (CFPNet-M)

CFPNet-M: A Light-Weight Encoder-Decoder Based Network for Multimodal Biomedical Image Real-Time Segmentation This repository contains the implementat

null 268 Nov 27, 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
Code for Referring Image Segmentation via Cross-Modal Progressive Comprehension, CVPR2020.

CMPC-Refseg Code of our CVPR 2020 paper Referring Image Segmentation via Cross-Modal Progressive Comprehension. Shaofei Huang*, Tianrui Hui*, Si Liu,

spyflying 55 Dec 1, 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