Giter VIP home page Giter VIP logo

josedolz / hyperdensenet_pytorch Goto Github PK

View Code? Open in Web Editor NEW
77.0 6.0 12.0 405 KB

Pytorch version of the HyperDenseNet deep neural network for multi-modal image segmentation

Python 100.00%
hyperdensenet deep-learning 3d-convolutional-network 3d-cnn medical-image-processing medical-image-segmentation multi-modal-imaging multi-modal-learning segmentation image-segmentation pytorch pytorch-cnn

hyperdensenet_pytorch's Introduction

Hyperdensenet_Pytorch

This is a Pytorch implementation of Hyperdensenet. For the detailed architecture please refer to the original paper: link

This is not the original implementation of the paper (Do not use it to reproduce the results). The original code is based on Theano and can be found here

Design of the Proposed Model

model

Dependencies

This code depends on the following libraries:

  • Python >= 3.5
  • Pytorch 0.3.1 (Testing on more recent versions)
  • nibabel
  • medpy

Training

The model can be trained using below command:

python mainHyperDenseNet.py

Preparing your data

  • To use your own data, you will have to specify the path to the folder containing this data (--root_dir).
  • Images have to be in nifti (.nii) format
  • You have to split your data into two folders: Training/Validation. Each folder will contain N sub-folders: N-1 subfolders that will contain each modality and GT, which contain the nifti files for the images and their corresponding ground truths. Then, for training, you only need to specify which subfolders you want to use in the command line. For example:
--modality_dirs T1 T2_FLAIR
  • Image names should be the same across folders (e.g., )

Current version

  • The current version includes HyperDenseNet for 2 and 3 modalities. To run either one or the other, you simply need to specify the number of modalities on the input arg numModal
--numModal n

where n is the number of modalities.

  • Patch size, and sampling steps values are hard-coded. We will work on a generalization of this, allowing the user to decide the input patch size and the frequency to sample the patches.
  • We are working on adding an external testing function.
  • In the original paper we used a ROI to mask out the background. This will help during sampling patches for training, as well as remove outliers on the testing images, since the receptive field of this network is small.

If you use this code in your research, please consider citing the following paper:

Dolz J, Gopinath K, Yuan J, Lombaert H, Desrosiers C, Ayed IB. HyperDense-Net: A hyper-densely connected CNN for multi-modal image segmentation. IEEE transactions on medical imaging. 2018 Oct 30;38(5):1116-26.

HyperDenseNet_pytorch

hyperdensenet_pytorch's People

Contributors

josedolz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hyperdensenet_pytorch's Issues

Error message Inference (dscAll)

Dear @josedolz,

I am using your HyperDenseNet with 2 modalities (T1 and Flair). It trains and the validation runs also. When the validation is done, I receive an error which involves calculating dsc. The error is as follows:

** in inference(network, moda_n, moda_g, imageNames, epoch, folder_save, number_modalities)
100
101 dsc = evaluateSegmentation(gt,bin_seg)
--> 102 dscAll[i_s, :] = dsc
103
104 return dscAll

ValueError: could not broadcast input array from shape (2) into shape (1)**

Can you help me solve this error?

Kind regards,
Heather

When I am running this project, I meet a question

My problem is : IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

I have found many methods to deal with this problem, but nothing is useful. Many people in Google said that we should use 'int' in this code, but this also do nothing.

This problem is in sampling.py ,line 77 "label_patches = label_patches[label_selector]"

I am very nervous,can you help me.

Thank you!

some helpful codes for this project

u can try to run following codes if u meet the same problems:

#coding = utf-8
import os
import shutil
import nibabel as nb

srcdir = r'C:\Users\xxx\Desktop\iSeg-2017-Training'
destdir = r'C:\Users\xxx\Desktop\DataNii'
os.chdir(srcdir)
for filename in os.listdir():
        if (os.path.splitext(filename)[1] == '.img'):
            img = nb.load(filename)
            nb.save(img, filename.replace('.img', '.nii'))
        if (os.path.splitext(filename)[1] == '.nii'):    
            shutil.move(filename, destdir)
print("done")
import nibabel as nib
import numpy as np
import os
path = r"C:\Users\xxx\Desktop\DataNii\Validation\GT"
os.chdir(path)
dict = {0: 0, 10: 1, 150: 2, 250: 3}
for file in os.listdir(path):
    gt = nib.load(file).get_fdata()
    shape = gt.shape
    gt = gt.reshape(-1) 
    for i in range(len(gt)):
        gt[i] = dict[gt[i]]
    gt = gt.reshape(shape)
    img_gt = nib.Nifti1Image(gt, np.eye(4))
    nib.save(img_gt, file)
print("done")      

配置环境时除了一些问题

问题:ImportError: cannot import name 'extract_patches' from 'skimage.feature' (D:\Program Files (x86)\anaconda3\envs\hyperdense\lib\site-packages\skimage\feature_init_.py)
请问这个要怎么解决

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.