Code Monkey home page Code Monkey logo

lits---liver-tumor-segmentation-challenge's Introduction

ImageSegmentation With Vnet3D

This is an example of the CT images Segment from LiTS---Liver-Tumor-Segmentation-Challenge

Prerequisities

The following dependencies are needed:

  • numpy >= 1.11.1
  • SimpleITK >=1.0.1
  • opencv-python >=3.3.0
  • tensorflow-gpu ==1.8.0
  • pandas >=0.20.1
  • scikit-learn >= 0.17.1

How to Use

(re)implemented the model with tensorflow in the paper of "Milletari, F., Navab, N., & Ahmadi, S. A. (2016) V-net: Fully convolutional neural networks for volumetric medical image segmentation.3DV 2016"

1、Preprocess

  • LiTS data of image and mask are all type of .nii files,in order to train and visulise,convert .nii file to .bmp file.
  • Liver data preparing,i have tried many patch size,and finally using the patch(256,256,16),if you have better GPU,you can change 16 to 24 or 32:run the getPatchImageAndMask.py
  • Tumor data preparing,using the patch(256,256,16):run the getPatchImageAndMask.py,disable the line gen_image_mask(srcimg, seg_liverimage, i, shape=(16, 256, 256), numberxy=5, numberz=10) and enable the line gen_image_mask(srcimg, seg_tumorimage, i, shape=(16, 256, 256), numberxy=5, numberz=10),and change the trainLiverMask to trainTumorMask
  • last save all the data folder path into csv file: run the utils.py

the file like this:

G:\Data\segmentation\Image/0_161

G:\Data\segmentation\Image/0_162

G:\Data\segmentation\Image/0_163

2、Liver and Tumor Segmentation

  • the VNet model

  • train and predict in the script of vnet3d_train.py and vnet3d_predict.py

3、download resource

Result

Trained Loss

Liver Segment Result

Liver leaderboard

test case segmentation result can see in the file of 35.mp4,38.mp4 and 51.mp4

first col is srcimage,second col is GroundTruth Mask image,third col is VNet segmentation image

Lesion leaderboard

Contact

lits---liver-tumor-segmentation-challenge's People

Contributors

dxye avatar junqiangchen 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lits---liver-tumor-segmentation-challenge's Issues

Can this code support GPU parallel?

I notice that the default GPU setting in this training code is :
os.environ["CUDA_VISIBLE_DEVICES"] = "0" and batch_size = 1

when I simply change them to:
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1,2,3,4,5,6,7" and batch_size = 8
(since I have 8 GPUs)
OOM error happens

so can this code support GPU parallel naturally or should I modify it for mutli-GPU scenario?
my tf version is 1.8.0

Thank you!

Result testing

Hello, thanks for making your code public, and your code is great, I have run your code, but i couldn't test my data on the LITS website, Can you tell me how to do that? Thank you.

ask for help

I'm a little confused about which code I want to run

I can't run v3d_predict.py

I got this error. "UnicodeEncodeError: 'utf-8' codec can't encode character '\udcfd' in position 3391: surrogates not allowed"

Download resource problem

Dear,
with the resources, I can't download because it all Chinese. I try to register but not allow any thai phone number. Could you help me?

liver segmentation trained model,log,test data can download on here:https://pan.baidu.com/s/1ijK6BG3vZM4nHwZ6S2yFiw, password:74j5
LiTS data have 130 cases,using 0-110 cases trainging,and other is testing.testing result can download on here:https://pan.baidu.com/s/1A_-u7tJcn7rIqnrLaSqi4A password:22es
LiTS train and test source data can download here:https://pan.baidu.com/s/1-kxJ7reS4kq5ypitfmQxeg password:nlrd

utils.py

你好,我是一个刚入门,请问运行utils.py时出现了TypeError: object of type 'NoneType' has no len()这个错误是怎么回事?

Cuda version

Hi,
I have problem in train file that generates some error related to cuda. can you please tell which cuda version you have used?
Thanks

GPU problem

My GPU is RTX 2070 8G, when I run vnet3d_train with patch(256,256,16), it fails, error log liike that:
Caused by op 'output/Conv3D', defined at:
File "D:/py/LiTS---Liver-Tumor-Segmentation-Challenge-master/LiTS/vnet3d_train.py", line 42, in
train()
File "D:/py/LiTS---Liver-Tumor-Segmentation-Challenge-master/LiTS/vnet3d_train.py", line 36, in train
Vnet3d = Vnet3dModule(256, 256, 16, channels=1, costname=("dice coefficient",))
File "D:\py\LiTS---Liver-Tumor-Segmentation-Challenge-master\LiTS\Vnet\model_vnet3d.py", line 203, in init
self.phase, self.drop)
File "D:\py\LiTS---Liver-Tumor-Segmentation-Challenge-master\LiTS\Vnet\model_vnet3d.py", line 152, in _create_conv_net
output_map = conv_sigmod(x=layer9, kernal=(1, 1, 1, 32, n_class), scope='output')
File "D:\py\LiTS---Liver-Tumor-Segmentation-Challenge-master\LiTS\Vnet\model_vnet3d.py", line 52, in conv_sigmod
conv = conv3d(x, W) + B
File "D:\py\LiTS---Liver-Tumor-Segmentation-Challenge-master\LiTS\Vnet\layer.py", line 51, in conv3d
conv_3d = tf.nn.conv3d(x, W, strides=[1, stride, stride, stride, 1], padding='SAME')
File "C:\Users\aiage\Miniconda3\envs\vnet_tensor\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 1487, in conv3d
name=name)
File "C:\Users\aiage\Miniconda3\envs\vnet_tensor\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\aiage\Miniconda3\envs\vnet_tensor\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op
op_def=op_def)
File "C:\Users\aiage\Miniconda3\envs\vnet_tensor\lib\site-packages\tensorflow\python\framework\ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InternalError (see above for traceback): Blas SGEMM launch failed : m=1048576, n=1, k=32
[[Node: output/Conv3D = Conv3D[T=DT_FLOAT, data_format="NDHWC", dilations=[1, 1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1, 1], _device="/job:localhost/replica:0/task:0/device:GPU:0"](add_8, outputW/read/_139)]]
[[Node: Neg/_143 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_2696_Neg", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

And what can I do with it ?

about original test data file .nii

您好,请问您可以提供.nii格式的原始测试数据吗?我在LITS挑战赛的官方网站上不能打开测试数据链接。
image

万分感谢!

Performance issue in /LiTS/data_input (by P3)

Hello! I've found a performance issue in dataset_input.py: dataset.batch(batch_size)(line 109) should be called before dataset.map(_parse_function)(line 107) and dataset.map(_preprocess_function)(line 108), which could make your program more efficient.

Here is the tensorflow document to support it.

Besides, you need to check the function _preprocess_function called in dataset.map(_preprocess_function) whether to be affected or not to make the changed code work properly. For example, if _preprocess_function needs data with shape (x, y, z) as its input before fix, it would require data with shape (batch_size, x, y, z) after fix.

Looking forward to your reply. Btw, I am very glad to create a PR to fix it if you are too busy.

Performance issues in LiTS/data_input/dataset_input.py(P2)

Hello,I found a performance issue in the definition of datagenerator ,
LiTS/data_input/dataset_input.py,
dataset = dataset.map(_parse_function) was called without num_parallel_calls.
I think it will increase the efficiency of your program if you add this.

The same issues also exist in dataset = dataset.map(_preprocess_function)

Here is the documemtation of tensorflow to support this thing.

Looking forward to your reply. Btw, I am very glad to create a PR to fix it if you are too busy.

About *.nii to *.bmp for test

您好,这段nii转bmp的代码是我模仿生成训练数据写的,测试的效果很差,想知道问题是出在了哪里 :)

def prepareTestData():
    for i in range(0, 70, 1):
        filepath = testImage + str(i) + ".nii"
        src = load_itk(filepath)
        data = sitk.GetArrayFromImage(src)
        data = data.astype(np.float32)
        data = np.clip(data, 0, 255).astype('uint8')
        channel, width, height = data.shape[0], data.shape[1], data.shape[2]
        for j in range(channel):
            savePath = outputPath + str(i)
            if not os.path.exists(savePath):
                os.makedirs(savePath)
            v_flip = cv2.flip(data[j, :, :], 0)  # 上下翻转图片
            cv2.imwrite(savePath + "/" + str(j) + ".bmp", v_flip)

batch_xs[index, :, :] = imgs[128:384, 128:384] TypeError: 'NoneType' object is not subscriptable

Here is my code:
from model_vnet3d import Vnet3dModule
from util import convertMetaModelToPbModel
import numpy as np
import pandas as pd
import cv2
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

def train():
'''
Preprocessing for dataset
'''
# Read data set (Train data from CSV file)
csvmaskdata = pd.read_csv('E:/LiTS---Liver/LiTS/dataprocess/trainY.csv')
csvimagedata = pd.read_csv('E:/LiTS---Liver/LiTS/dataprocess/trainX.csv')
maskdata = csvmaskdata.iloc[:, :].values
imagedata = csvimagedata.iloc[:, :].values
# shuffle imagedata and maskdata together
perm = np.arange(len(csvimagedata))
np.random.shuffle(perm)
imagedata = imagedata[perm]
maskdata = maskdata[perm]

Vnet3d = Vnet3dModule(128, 128, 16, channels=1, costname="dice coefficient")
Vnet3d.train(imagedata, maskdata, "Vnet3dModule.pd", "E:/LiTS---Liver/LiTS/log2/diceVnet3d/model/", 0.001, 0.7, 100000, 1)

def predict0():
Vnet3d = Vnet3dModule(128, 128, 16, inference=True, model_path="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd")
for filenumber in range(30):
batch_xs = np.zeros(shape=(16, 128, 128))
for index in range(16):
imgs = cv2.imread(
"E:\LiTS---Liver\LiTS\test\image\" + str(filenumber) + "\" + str(index) + ".bmp", 0)
batch_xs[index, :, :] = imgs[128:384, 128:384]

    predictvalue = Vnet3d.prediction(batch_xs)

    for index in range(16):
        result = np.zeros(shape=(512, 512), dtype=np.uint8)
        result[128:384, 128:384] = predictvalue[index]
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
        result = cv2.morphologyEx(result, cv2.MORPH_CLOSE, kernel)
        cv2.imwrite(
            "E:\LiTS---Liver\LiTS\\test\image\\" + str(filenumber) + "\\" + str(index) + "mask.bmp",
            result)

def meta2pd():
convertMetaModelToPbModel(meta_model="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd", pb_model="model")

#train()
predict0()
#meta2pd()

Time limit exceeded on lits challenge

hello,
yesterday i made a submission on codalab but after running a couple of hours i was surprised by a weird ''time limit exceeded" error do you have any idea about the origin of this error ? thank you

about the number of sample

hello,thanks for your contribution.I want ask one question,as follow:
how do you sellect the number of sample which is in the getPatchImageAndMask.py.
I print the number of sample,which is 5917.I use the dataset of LITS.
Looking forward to hearing from you!

Unable to download model

Hi I don't have baidu account. So, I am unable to download your model file. Can you please share any other links for this?

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.