naldeborgh7575 / brain_segmentation Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
As far as I know, using Dice, PPV and Sensitivity to evaluate the segmentation image must have the ground truth of the testing dataset. I cannot get the 'more' that the type of it is .nii of the testing in brats2015 from , although I can download the other files that the type of them is .mha successfully. So i don't know how to evaluate the results.I find the paper 'Brain tumor segmentation with Deep Neural Networks' of Havaei suggest that there is no ground truth provided for the test and leaderboard datasets of brats2013
,but I'm very curious how does he evaluate the segmentations?Is there anyone who can solve this problem for me?Thanks
On running the Segmentation_Models.py file I get the following error:
System: Mac
Keras: 1.0.0
Tensorflow: 0.12.0
Jacobs-MacBook-Pro:code jacobjohn$ python Segmentation_Models.py
Using TensorFlow backend.
Finding patches of class 0... ] 0%
Traceback (most recent call last):
File "Segmentation_Models.py", line 376, in <module>
X,y = patches.make_training_patches()
File "/Users/jacobjohn/Codes/brain_segmentation-master/code/patch_library.py", line 155, in make_training_patches
p, l = self.find_patches(classes[i], per_class)
File "/Users/jacobjohn/Codes/brain_segmentation-master/code/patch_library.py", line 45, in find_patches
im_path = random.choice(self.train_data)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 277, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range
I tried a lot to run the code, but it seems there is a problem:
Loading scans...
-> Applyling bias correction...
Traceback (most recent call last):
File "n4_bias_correction.py", line 24, in <module>
n4.run()
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
runtime = self._run_wrapper(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1660, in _run_wrapper
runtime = self._run_interface(runtime)
File "/home/azim_se/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1686, in _run_interface
(self.cmd.split()[0], runtime.hostname))
IOError: command 'N4BiasFieldCorrection' could not be found on host othrys2.dhcp.af.op.dlr.de
Interface N4BiasFieldCorrection failed to run.
Traceback (most recent call last):
File "n4_bias_correction.py", line 24, in <module>
n4.run()
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
runtime = self._run_wrapper(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1660, in _run_wrapper
runtime = self._run_interface(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1686, in _run_interface
(self.cmd.split()[0], runtime.hostname))
IOError: command 'N4BiasFieldCorrection' could not be found on host tehran.mpi.inf-mpg.de
Interface N4BiasFieldCorrection failed to run.
Traceback (most recent call last):
File "brain_pipeline.py", line 167, in <module>
save_patient_slices(patients, 'reg')
File "brain_pipeline.py", line 139, in save_patient_slices
a = BrainPipeline(path)
File "brain_pipeline.py", line 25, in __init__
self.slices_by_mode, n = self.read_scans()
File "brain_pipeline.py", line 49, in read_scans
scans = [flair[0], t1_n4[0], t1_n4[1], t2[0], gt[0]]
IndexError: list index out of range
I don't know how to solve the problem, could you tell me exactly what I should do?
I have obtained the segmentation results,I will evaluate the results,but i don't have the ground truth of testing dataset.I find that many people evaluate on the online platform,but i need convert the .png to .mha. ITK can perform file type conversion,however ,I need to install the VS,I don't know why i can't install VS successfully.So is there any other method can convert the .png to .mha? I'm in a hurry and I hope someone can help me.Thanks
Hi
Thanks for the wonderful explanation. I would like to know how you created those 3D images ,are they particular slice ,so represented in 2D or you used tool?
If there is any python script to visualize 3D volumes then please guide,it will be great help
Thanks
Sagar
After running brain_pipeline.py,I got the labels all black. I use BRATS 2015.Will the all-black label affect the subsequent model training?Thanks.
In the script patch_library.py I am trying to create the patches, but get the Error above.
This are the lines I am stuck with:
im_path = random.choice(self.train_data) fn = os.path.basename(im_path) label = io.imread('Labels/' + fn[:-4] + 'L.png')
I created the labels beforehand with the brain_pipeline, but they do not fit the expectations above.
def save_labels(fns): ''' INPUT list 'fns': filepaths to all labels ''' progress.currval = 0 for label_idx in progress(xrange(len(labels))): slices = io.imread(labels[label_idx], plugin = 'simpleitk') for slice_idx in xrange(len(slices)): io.imsave('/data_l74/dlocke/Downloads/brain_segmentation-master/code/Labels/{}_{}L.png'.format(label_idx, slice_idx), slices[slice_idx])
Hi Nikki,
I am trying to replicate your model for brain tumour segmentation to explore image analysis tools and algorithms. After carefully implementing your model, I got either completely blank predictions or negated results (image had slices made in the area where tumour is absent) . I am using your pre-trained model with available weights downloaded from this repository. Could you please help me improve my result?
Few changes I made are listed here:
1.The BasicModel() used in SegmentationModels.py seems undefined, I replaced it with SegmentationModel().
Thanks in advance.
well while I'm running this code on windows platform and i downloaded all the required libraries required in code all 4 files are running without error but main code file is giving me above error and I can't understand it's reason I'm sort of newbie. I also tried to run same code and got different error on linux platform i took SC of it
can someone guide me how to resolve this issue and run this code.
I downloaded data set from https://wiki.cancerimagingarchive.net/display/Public/TCGA-GBM
but my question is in this data how can we determine which is folder we should give as T1 and T1c and T2 and Flair image for computation.
As far as I know, using Dice, PPV and Sensitivity to evaluate the segmentation image must have the ground truth of the testing set, but I cannot get ground truth from the official website.
Variable xrange is used in for loops, but the value has not been initialized prior.
Windows 10
Python 3.6
Brats 2013 datase (HG/LG)
Traceback (most recent call last):
File "D:/Darsh/Nirma/Semester 7/Trial/nn-segmentation-for-lar-master/brain_tumor_segmentation_cnn/brain_pipeline.py", line 234, in
save_patient_slices(patients, 'reg')
File "D:/Darsh/Nirma/Semester 7/Trial/nn-segmentation-for-lar-master/brain_tumor_segmentation_cnn/brain_pipeline.py", line 202, in save_patient_slices
a.save_patient(type_modality, patient_num)
File "D:/Darsh/Nirma/Semester 7/Trial/nn-segmentation-for-lar-master/brain_tumor_segmentation_cnn/brain_pipeline.py", line 154, in save_patient
for slice_ix in progress(range(176)):
File "C:\Users\DELL\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\progressbar\bar.py", line 433, in next
self.update(self.value + 1)
File "C:\Users\DELL\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\progressbar\bar.py", line 553, in update
% (self.min_value, self.max_value))
ValueError: Value out of range, should be between 0 and 176
Process finished with exit code 1
Above is the error i'm getting after several images are created for the first iteration.
As defined in SegmentationModels.py
function def get_dice_coef(self, test_img, label):
requires labelled ground truth image label
. I created the same using save_labels
in brain_pipeline.py
of size 240 X 240 . When the call to get_dice_coef(self, test_img, label):
is made it gives value error for reshape due to this line imgs = io.imread(test_img).astype('float').reshape(5,240,240)
.
This is because we make the call to predict_image
in the first line of the function get_dice_coef()
(reference:segmentation = self.predict_image(test_img)
) but test_img
is of size 240 X 240. def show_segmented_image(self, test_img, modality='t1c', show = False):
is producing the slice of 240 X 240 test image. Isn't that used for calculating dice_coeff ?
I am facing some difficulty in the sequential model, the following error is popping up? Becuase we can't use Graph in the newer version so I started with Keras1.0.
ERROR:
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/home/joydeep/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 543, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/home/joydeep/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 148, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/home/joydeep/.local/lib/python2.7/site-packages/keras/layers/normalization.py", line 109, in call
x_normed = K.in_train_phase(x_normed, x_normed_running)
File "/home/joydeep/.local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 742, in in_train_phase
x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, 'bool'),
i use pip to install nipype, but i failed to run n4.
can i just install the python version of ants?
could this project work in windows?or only work in linux or maxos?
sorry how do you read the image?i cant find the reading code
When I change scans = [flair[0], t1_n4[0], t1_n4[1], t2[0], gt[0]]
to scans = [flair[0], t1[0], t1c[0], t2[0], gt[0]]
and only using globe
before than to find t1
and t1c
.mha
images, after running Segmentation_Models.py
I get the following error:
code$ python Segmentation_Models.py
Using TensorFlow backend.
Finding patches of class 0... ] 0%
Traceback (most recent call last):
File "Segmentation_Models.py", line 376, in <module>
X,y = patches.make_training_patches()
File "/home/majid/BRATS/brain_segmentation-master/code/patch_library.py", line 155, in make_training_patches
p, l = self.find_patches(classes[i], per_class)
File "/home/majid/BRATS/brain_segmentation-master/code/patch_library.py", line 45, in find_patches
im_path = random.choice(self.train_data)
File "/home/majid/anaconda2/lib/python2.7/random.py", line 275, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
IndexError: list index out of range
Hi, I tried a lot to reproduce your results, but it seems there is a problem in my machine.
In the case that n4-bias-correction is True, I get the following error:
Loading scans...
-> Applyling bias correction...
Traceback (most recent call last):
File "n4_bias_correction.py", line 24, in <module>
n4.run()
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
runtime = self._run_wrapper(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1660, in _run_wrapper
runtime = self._run_interface(runtime)
File "/home/azim_se/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1686, in _run_interface
(self.cmd.split()[0], runtime.hostname))
IOError: command 'N4BiasFieldCorrection' could not be found on host othrys2.dhcp.af.op.dlr.de
Interface N4BiasFieldCorrection failed to run.
Traceback (most recent call last):
File "n4_bias_correction.py", line 24, in <module>
n4.run()
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
runtime = self._run_wrapper(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1660, in _run_wrapper
runtime = self._run_interface(runtime)
File "/home/azim/.local/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1686, in _run_interface
(self.cmd.split()[0], runtime.hostname))
IOError: command 'N4BiasFieldCorrection' could not be found on host tehran.mpi.inf-mpg.de
Interface N4BiasFieldCorrection failed to run.
Traceback (most recent call last):
File "brain_pipeline.py", line 167, in <module>
save_patient_slices(patients, 'reg')
File "brain_pipeline.py", line 139, in save_patient_slices
a = BrainPipeline(path)
File "brain_pipeline.py", line 25, in __init__
self.slices_by_mode, n = self.read_scans()
File "brain_pipeline.py", line 49, in read_scans
scans = [flair[0], t1_n4[0], t1_n4[1], t2[0], gt[0]]
IndexError: list index out of range
I would do appreciate if you could help me figure this problem out.
Somehow I cannot get the script running. I always get the Error above.
Here is the full Error:
Loading scans...
Traceback (most recent call last):
File "brain_pipeline.py", line 167, in <module>
save_patient_slices(patients, 'reg')
File "brain_pipeline.py", line 140, in save_patient_slices
a = BrainPipeline(path)
File "brain_pipeline.py", line 25, in __init__
self.slices_by_mode, n = self.read_scans()
File "brain_pipeline.py", line 51, in read_scans
scans = [flair[0], t1_n4[0], t1_n4[1], t2[0], gt[0]]
IndexError: list index out of range
Does somebody know a solution?
for more than 7 hours it stays on searching for patch 0 for only 4 patient's slices PNG(Training_PNG data is low) still it has not completed. Ct variable is not changing.
I am facing difficulties in running the code. I am not sure about which code I must run first and exactly where should I set the path for dataset?
Using TensorFlow backend.
Finding patches of class 0... ] 0%
Traceback (most recent call last):
File "Segmentation_Models.py", line 377, in
X,y = patches.make_training_patches()
File "brain_segmentation-master/code/patch_library.py", line 155, in make_training_patches
p, l = self.find_patches(classes[i], per_class)
File "/brain_segmentation-master/code/patch_library.py", line 47, in find_patches
label = io.imread('Labels/' + fn[:-4] + 'L.png')
File ".local/lib/python2.7/site-packages/skimage/io/_io.py", line 61, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File ".local/lib/python2.7/site-packages/skimage/io/manage_plugins.py", line 211, in call_plugin
return func(*args, **kwargs)
File ".local/lib/python2.7/site-packages/skimage/io/_plugins/pil_plugin.py", line 35, in imread
with open(fname, 'rb') as f:
IOError: [Errno 2] No such file or directory: 'Labels/LaL.png'
Hello,
I am running the code and getting following error. Can anyone please suggest what am I missing here??
home/ubuntu/anaconda2/lib/python2.7/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float
to np.floating
is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type
.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Compiling single model...
Traceback (most recent call last):
File "Segmentation_Models_edited.py", line 411, in
SegObj = SegmentationModel()
File "Segmentation_Models_edited.py", line 60, in init
self.model_comp = self.compile_model()
File "Segmentation_Models_edited.py", line 72, in compile_model
single.add(Convolution2D(self.n_filters[0], self.k_dims[0], self.k_dims[0], border_mode='valid', W_regularizer=l1l2(l1=self.w_reg, l2=self.w_reg), input_shape=(self.n_chan,33,33)))
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/models.py", line 299, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 401, in create_input_layer
self(x)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 572, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 635, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 166, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/layers/convolutional.py", line 475, in call
filter_shape=self.W_shape)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2691, in conv2d
x = tf.nn.conv2d(x, kernel, strides, padding=padding)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 631, in conv2d
data_format=data_format, name=name)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2958, in create_op
set_shapes_for_outputs(ret)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 7 from 4 for 'Conv2D' (op: 'Conv2D') with input shapes: [?,4,33,33], [7,7,33,64].
Thanks
In the Readme, you say:
I employed an n4ITK bias correction on all T1 and T1C images in the dataset (code), which removed the intensity gradient on each scan.
Why T2 and Flair scans do not need to be employed a bias correction?
Hey,
I am getting just a black image if I am trying to visualize the predicted image.
imgs = sitk.GetArrayFromImage(sitk.ReadImage(tests[10]))
plist = []
for img in imgs[:-1]:
if np.max(img) != 0:
img /= np.max(img)
p = extract_patches_2d(img, (33,33))
plist.append(p)
patches = np.array(zip(np.array(plist[0]), np.array(plist[1]), np.array(plist[2]), np.array(plist[3])))
full_pred = model.predict_classes(patches)
fp1 = full_pred.reshape(208,208
full_pred = model.predict_classes(imgs)
imgs = sitk.GetArrayFromImage(sitk.ReadImage(tests[10]))
plt.figure(figsize=(10,10))
plt.subplot(121)
plt.imshow(imgs[70])
plt.subplot(122)
plt.imshow(fp1)
plt.show()
I am trying to create an image with the Segmentation like in the description. But with the code it does not work. Can somebody help me out
Hi,
First, I'm sorry this is not related to software, but I'm writing here so someone may help me.
I need this software for my student project, but I'm having issues about to find the dataset.
BRATS 2015 is asking for registration to download the dataset. However, my registration is waiting for confirmation for 5 days and I don't have too much time.
I have selected BRATS2015 for research unit. It seems my registration will not be confirmed.
Is there another way to get this dataset? If someone who already downloaded the dataset before, can provide me with these data over another link I'll be really really thankful. Or can you propose me another brain tumour MRI dataset suitable with this software?
Thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.