Giter Club home page Giter Club logo

niftynet's Introduction

NifTK

Welcome to the NifTK project. This project contains several applications with graphical user interface, and various command line applications and command line scripts. The NifTK project is part of the overall NifTK platform.

NifTK is co-developed by members of the Centre for Medical Image Computing (CMIC) at University College London (UCL) and The School of Biomedical Engineering and Imaging Sciences at King's College London (KCL). The Principal Investigator is Prof. Sebastien Ourselin at KCL, and the Team Leader is Dr Matt Clarkson at UCL.

If you use this software, please cite this paper.

Not for Clinical Use

This software may not be used for, or in relation to, patient management.

Useful Links

License

Copyright (c) 2010 - 2019, University College London.

This project is distributed under the conditions of the BSD 3-clause license.

Funding

This project was originally funded by the NIHR Biomedical Research Centre at University College London (UCL) and University College London Hospitals (UCLH), Innovate UK and the Engineering And Physical Science Research Council (EPSRC).

Supported Platforms

NifTK is a cross-platform C++ library and officially supports:

  • Windows
  • MacOS X
  • Linux

niftynet's People

Contributors

alekswithakayy avatar besler avatar csudre avatar danieltudosiu avatar dzhoshkun avatar elias-1 avatar eligibson avatar ericspod avatar eschnider avatar fepegar avatar gourie avatar irme avatar kotrix avatar lucasfidon avatar martaranzini avatar min-sheng avatar oesllelucena avatar patrick-llgc avatar pedrob37 avatar pritesh-mehta avatar r-gray avatar samueljoutard avatar taigw avatar tomdoel avatar tomvars avatar tvercaut avatar wyli avatar xygorn avatar yipenghu avatar zach-er 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  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

niftynet's Issues

bug in validation during training

For the 'validation during training'feature:

When enabled, it should compute gradients and update the network using data from the training set, and compute losses on the validation set after every N training iterations.

But in the current version, at each validation step, the network gets
updated using gradients computed from validation data.

As a result, it trains with validation set data unexpectedly and gives
wrong validation curves.

also filed at https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/issues/214

Cannot perform training on the Promise12 dataset

Hello, I am trying to run the demo:

python net_segment.py train --conf demos/PROMISE12/promise12_demo_train_config.ini --max_iter 10

but apparently it cannot load the Promise12 images in .mhd format since It is giving me the following error:

File "/home/alemh/anaconda2/envs/nifty_env/lib/python3.5/site-packages/niftynet/io/misc_io.py", line 80, in load_image
'No loader could load the file') # Throw last error
nibabel.filebasedimages.ImageFileError: No loader could load the file

Do you have any insights on how to solve this? Any help would be appreciated

Dice losses computed for the whole batch?

Hey there,
when looking into the implementation of the dice losses I noticed that they do not respect each image in the batch individually but are rather computed over the entire batch (if I understood that correctly). This was not mentioned in the corresponding paper ("Generalized Dice overlap as a deep learning loss function for highly unbelanced segmentations" by CH Sudre et al.).
It that behavior intentional? Due to the nature of the dice loss, computing it over the entire batch vs computing it for each sample individually and then taking the mean is not equivalent.
Regards,
Fabian

what dose ids mean in dice_hinge.py

Dear all,
I'm not clear the ids in dice_hinge.py.
Why introduce this variable๏ผŸAnd what is the role of variables h1 and h2?
Besides, compared to the classical dice, what is the advantage of the dice_hinge?

def dice(prediction, ground_truth, weight_map=None):
    ground_truth = tf.to_int64(ground_truth)
    prediction = tf.cast(prediction, tf.float32)
    prediction=tf.nn.softmax(prediction)
    ids = tf.range(tf.to_int64(tf.shape(ground_truth)[0]), dtype=tf.int64)
    ids = tf.stack([ids, ground_truth], axis=1)
    one_hot = tf.SparseTensor(
        indices=ids,
        values=tf.ones_like(ground_truth, dtype=tf.float32),
        dense_shape=tf.to_int64(tf.shape(prediction)))

    dice_numerator = 2.0 * tf.sparse_reduce_sum(
        one_hot * prediction, reduction_axes=[0])
    dice_denominator = \
        tf.reduce_sum(tf.square(prediction), reduction_indices=[0]) + \
        tf.sparse_reduce_sum(one_hot, reduction_axes=[0])
    epsilon_denominator = 0.00001

    dice_score = dice_numerator / (dice_denominator + epsilon_denominator)

    [tf.summary.scalar('Dice{}'.format(i),d) for i,d in enumerate(tf.unstack(dice_score,0))]
    dice_score=tf.Print(dice_score,[dice_score],summarize=10,message='dice')
    h1=tf.square(tf.minimum(0.1,dice_score)*10-1)
    h2=tf.square(tf.minimum(0.01,dice_score)*100-1)


    return 1.0 - tf.reduce_mean(dice_score) + \
           tf.reduce_mean(h1)*10 + \
           tf.reduce_mean(h2)*10

Abdominal organ segmentation

Hello, the NiftyNet paper "https://arxiv.org/pdf/1709.03485.pdf" references abdominal organ segmentation experiments using the " Multi-Atlas Labeling Beyond the Cranial Vault" dataset. I already downloaded the dataset and I would like to train it from scratch using the dense_vnet architecture, but I could not find it in the repository. Also the paper references an implementation of an special dice loss function for this multi-class segmentation in the configuration file but I could not find it. Can you give me any insights on this?. Thank you

Dice loss - mean over labels not in patch

Related to issue #22 I think there is also a problem with Dice Loss. Eg. for a two class problem the loss function returns a Dice value of 0.5 if just one of the two label is present in the patch, tough the prediction is correctly segmenting that one label. In the paper referenced in #22 (Generalized Dice overlap as a deep learning loss function for highly unbalanced segmentations) it is mentioned that for the loss functions to work correctly, the presence of each label is required (I also noticed that the Dice loss formulation in the paper, having epsilon in the nominator and denominator cant be true). Anyway, I would argue that this is rarely the case to have all labels inside one patch, if no special sampling strategy is used, when large sized image volumes are to segment.
To fix that, I would suggest to calculate the mean just over the labels being present in the patch?

Eg. fixing the dice loss in loss_segmentation.py as following:

one_hot_summed = tf.sparse_reduce_sum(one_hot, reduction_axes=[0])
return 1.0 - (tf.reduce_sum(dice_score) / tf.to_float(tf.count_nonzero(one_hot_summed)))

Once more thank you very much for the great work you are doing here.
Best, elias

how to set spatial_window_size properly?

Dear niftynet developer,
I'm confused about setting the spatial_window_size parameter in the network.

For instance, I have 100 volumes which are varying in the number of slices. To be precise, the dimension of the first volume is 512*512*125, the second volume's dimension is 512*512*203, and so on.
If I set the spatial_window_size as 64*64*3, how many inputs would be generated?
Because 64*64*3 can't be divided by both 512*512*125 and 512*512*203. And I also don't know where I can set the step size of the sliding window.
Would it be possible for you to give me some advice on how to set the spatial_window_size parameter for densevnet?

By the way, are there some constraints about densevnet like other networks in Network model references?

Looking forward to your reply.
Best wishes!

Edward

is pre_trained model avaliable for download?

Also, have you run the implemented networks and compare the results against original paper's benchmark?
It's also very interesting to see the limit of [batch_size, input_size] for each network at given GPU memory.

great work overall, cheers!

explanation of the`load_image` function and the dataflow

#31 and #34 asked for clarifications of load_image(filename):

how the image data is transferred to the network?
I can't find where the load_image(filename) function is called in the application_driver.py.

I know the niftynet defines the load_image(filename) function in niftynet/io/misc_io.py. However, I don't find how the load_image is called in promise 2012 demo.
there is no load_image function in both application_driver.py and segmentation_application.py.

More information on samples per volume

Hello NiftyNet Team,

Could you provide more information on the sample_per_volume training parameter? How does increasing or decreasing this parameter affect training?

Thanks,

Ken

Tensorflow 1.4 Issues

I need to use tensorFlow 1.4 for our HPC GPUs since Tensorflow 1.3 isn't fully supported, I noticed that I needed to comment out lines 468-470 in <niftynet.layer.resampler.py> to get the PROMISE12 demo working.

@tf.RegisterGradient('FloorMod')
def _floormod_grad(op, grad):
    return [None, None]

What other changes do I need to make to make NiftyNet compatible with tensorflow1.4?

crop_kernel size in 3D unet

Dear NiftyNet team:
I print the size of every layer output in unet (line 121). It's strange, the 'crop_kernel' size has a different format compared to the input size.
Markdown

Would it be possible for you to give me some explanation about the size of crop_kernel?
Best regards,
Edward

A strange number for Dice score in the training process

Dear all,
I use Dice as loss function and print the Dice score in the training process. Following is an example.
Dice score
Dice score2
However, the Dice scores of the foreground and background have a big gap. Normally, these two scores are very close.
Any explanation about this phenomenon will be very much appreciated.

2D segmentation Error

I'm currently trying to segment 2D RGB (256x256x3) images. I've converted my images to the .nii format in order to make it compatible with NiftyNet. As a test, I tried to run a training segmentation session with the Vnet application. However, I keep getting the following error no matter how I tweak the configuration file.

ValueError: Dimension 1 in both shapes must be equal, but are 2 and 1 for 'worker_0/VNet/residual_concat/concat' (op: 'ConcatV2') with input shapes: [20,2,2,256], [20,1,1,128], [] and with computed input tensors: input[2] = <-1>.

Below is my configuration file:

[input]
path_to_search = data/DSB_stage1_train/data
filename_contains = train, _data, nii
spatial_window_size = 8, 8, 1

[label]
path_to_search = data/DSB_stage1_train/labels3d
filename_contains = train, _labels, nii
spatial_window_size = 8, 8, 1

############################## system configuration sections
[SYSTEM]
cuda_devices = 2
num_threads = 2
num_gpus = 1
model_dir = ./nntest

[NETWORK]
name = vnet
activation_function = prelu
batch_size = 20
volume_padding_size=0

[TRAINING]
lr = 0.0002
loss_type = Dice
starting_iter = 0
max_iter = 100

############################ custom configuration sections
[SEGMENTATION]
image = input
label = label
num_classes = 2

I am currently using Red Hat Linux with Tensorflow 1.3 and Python 2.7. I always cd to my NiftyNet directory before I execute the following command: python net_segment.py train -c DSBtrain.ini

What am I doing wrong?

TypeError: not all arguments converted during string formatting

When the segmentation training beginning, following error occurred
TypeError: not all arguments converted during string formatting
Following is the full error information.

Number of subjects 1432, input section names: ['subject_id', 'Liver2018', 'Liverlabel']
Dataset partitioning:
-- Training 1360 cases (94.97%),
-- Validation 36 cases (2.51%),
-- Inference 36 cases (2.51%).

initialise readers in application_driver
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m Image reader: loading [image] from ('Liver2018',) (1360)
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m Image reader: loading [label] from ('Liverlabel',) (1360)
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m Image reader: loading [image] from ('Liver2018',) (36)
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m Image reader: loading [label] from ('Liverlabel',) (36)
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m reading size of preprocessed images (in sampler_resize.py)
sampler_resizeไธญspatial_window_size =  ()
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m initialised window instance
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m buffering with 3 windows
--- Logging error ---
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 992, in emit
    msg = self.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 838, in format
    return fmt.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 575, in format
    record.message = record.getMessage()
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "E:\Yang\niftynet\__init__.py", line 129, in main
    app_driver.initialise_application(system_param, input_data_param)
  File "E:\Yang\niftynet\engine\application_driver.py", line 192, in initialise_application
    self.app.initialise_sampler()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 212, in initialise_sampler
    self.SUPPORTED_SAMPLING[self.net_param.window_sampling][0]()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 184, in initialise_resize_sampler
    self.readers]]
  File "E:\Yang\niftynet\application\segmentation_application.py", line 183, in <listcomp>
    queue_length=self.net_param.queue_length) for reader in
  File "E:\Yang\niftynet\engine\sampler_resize.py", line 60, in __init__
    " [-1 for dynamic size]", self.window.shapes, "(in sampler_resize.py)")
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\tf_logging.py", line 82, in info
    _logger.info(msg, *args, **kwargs)
Message: 'initialised sampler output %s  [-1 for dynamic size]'
Arguments: ({'image': (128, 128, 64, 1, 1), 'label': (128, 128, 64, 1, 1)}, '(in sampler_resize.py)')
--- Logging error ---
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 992, in emit
    msg = self.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 838, in format
    return fmt.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 575, in format
    record.message = record.getMessage()
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "E:\Yang\niftynet\__init__.py", line 129, in main
    app_driver.initialise_application(system_param, input_data_param)
  File "E:\Yang\niftynet\engine\application_driver.py", line 192, in initialise_application
    self.app.initialise_sampler()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 212, in initialise_sampler
    self.SUPPORTED_SAMPLING[self.net_param.window_sampling][0]()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 184, in initialise_resize_sampler
    self.readers]]
  File "E:\Yang\niftynet\application\segmentation_application.py", line 183, in <listcomp>
    queue_length=self.net_param.queue_length) for reader in
  File "E:\Yang\niftynet\engine\sampler_resize.py", line 60, in __init__
    " [-1 for dynamic size]", self.window.shapes, "(in sampler_resize.py)")
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\tf_logging.py", line 82, in info
    _logger.info(msg, *args, **kwargs)
Message: 'initialised sampler output %s  [-1 for dynamic size]'
Arguments: ({'image': (128, 128, 64, 1, 1), 'label': (128, 128, 64, 1, 1)}, '(in sampler_resize.py)')
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m reading size of preprocessed images (in sampler_resize.py)
sampler_resizeไธญspatial_window_size =  ()
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m initialised window instance
๏ฟฝ[1mINFO:niftynet:๏ฟฝ[0m buffering with 3 windows
--- Logging error ---
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 992, in emit
    msg = self.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 838, in format
    return fmt.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 575, in format
    record.message = record.getMessage()
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "E:\Yang\niftynet\__init__.py", line 129, in main
    app_driver.initialise_application(system_param, input_data_param)
  File "E:\Yang\niftynet\engine\application_driver.py", line 192, in initialise_application
    self.app.initialise_sampler()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 212, in initialise_sampler
    self.SUPPORTED_SAMPLING[self.net_param.window_sampling][0]()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 184, in initialise_resize_sampler
    self.readers]]
  File "E:\Yang\niftynet\application\segmentation_application.py", line 183, in <listcomp>
    queue_length=self.net_param.queue_length) for reader in
  File "E:\Yang\niftynet\engine\sampler_resize.py", line 60, in __init__
    " [-1 for dynamic size]", self.window.shapes, "(in sampler_resize.py)")
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\tf_logging.py", line 82, in info
    _logger.info(msg, *args, **kwargs)
Message: 'initialised sampler output %s  [-1 for dynamic size]'
Arguments: ({'image': (128, 128, 64, 1, 1), 'label': (128, 128, 64, 1, 1)}, '(in sampler_resize.py)')
--- Logging error ---
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 992, in emit
    msg = self.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 838, in format
    return fmt.format(record)
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 575, in format
    record.message = record.getMessage()
  File "C:\ProgramData\Anaconda3\lib\logging\__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "E:\Yang\niftynet\__init__.py", line 129, in main
    app_driver.initialise_application(system_param, input_data_param)
  File "E:\Yang\niftynet\engine\application_driver.py", line 192, in initialise_application
    self.app.initialise_sampler()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 212, in initialise_sampler
    self.SUPPORTED_SAMPLING[self.net_param.window_sampling][0]()
  File "E:\Yang\niftynet\application\segmentation_application.py", line 184, in initialise_resize_sampler
    self.readers]]
  File "E:\Yang\niftynet\application\segmentation_application.py", line 183, in <listcomp>
    queue_length=self.net_param.queue_length) for reader in
  File "E:\Yang\niftynet\engine\sampler_resize.py", line 60, in __init__
    " [-1 for dynamic size]", self.window.shapes, "(in sampler_resize.py)")
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\tf_logging.py", line 82, in info
    _logger.info(msg, *args, **kwargs)
Message: 'initialised sampler output %s  [-1 for dynamic size]'
Arguments: ({'image': (128, 128, 64, 1, 1), 'label': (128, 128, 64, 1, 1)}, '(in sampler_resize.py)')

2018-01-30 12:06:06.306439: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions,
 but these are available on your machine and could speed up CPU computations.
2018-01-30 12:06:06.306439: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions
, but these are available on your machine and could speed up CPU computations.
2018-01-30 12:06:06.551453: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:955] Found device 0 with properties:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:01:00.0
Total memory: 11.00GiB
Free memory: 10.58GiB

Train and validation split?

How do I control validation set size? I cannot find it in code, I cannot see it on Tensorboard. Do you train without validation?

raise error when run demo

I run the demo net_segment for inference ,that's OK,but raise error when train :
net_segment train -c ./extensions/dense_vnet_abdominal_ct/config.ini

`Traceback (most recent call last):
File "/usr/local/bin/net_segment", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/niftynet/init.py", line 54, in main
app_driver.initialise_application(system_param, input_data_param)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_driver.py", line 131, in initialise_application
self.app.initialise_dataset_loader(data_param, app_param)
File "/usr/local/lib/python3.5/dist-packages/niftynet/application/segmentation_application.py", line 63, in initialise_dataset_loader
self.reader.initialise_reader(data_param, task_param)
File "/usr/local/lib/python3.5/dist-packages/niftynet/io/image_reader.py", line 98, in initialise_reader
self._file_list = util_csv.load_and_merge_csv_files(data_to_load)
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/util_csv.py", line 254, in load_and_merge_csv_files
match_and_write_filenames_to_csv([matcher], csv_file)
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/util_csv.py", line 209, in match_and_write_filenames_to_csv
KeywordsMatching.matching_subjects_and_filenames(c)
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/filename_matching.py", line 73, in matching_subjects_and_filenames
self.dict))
OSError: no file matched based on this matcher: {'filename_not_contains': (), 'filename_contains': ('Label',), 'path_to_search': ('/home/yyydido/niftynet/data/dense_vnet_abdominal_ct',)}'

Selective Sampler memory error

Dear NiftyNet,

I am running a selective sampler with VNet and I get the following error message:

INFO:niftynet: Parameters from random initialisations ...
list labels is (0, 1)
262144 0.001
list labels is (0, 1)
262144 0.001
list labels is (0, 1)
262144 0.001
list labels is (0, 1)
262144 0.001
final calculated for value in list_labels
final calculated for value in list_labels
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/image_window_buffer.py", line 143, in _push
for output_dict in self():
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/sampler_uniform.py", line 83, in layer_op
self.window.n_samples)
File "/usr/local/lib/python3.5/dist-packages/niftynet/contrib/segmentation_selective_sampler/sampler_selective.py", line 81, in spatial_coordinates_function
win_sizes['label'], data['label'], self.constraint)
File "/usr/local/lib/python3.5/dist-packages/niftynet/contrib/segmentation_selective_sampler/sampler_selective.py", line 183, in candidate_indices
counts_window = fftconvolve(seg_label, window_ones, 'same')
File "/usr/local/lib/python3.5/dist-packages/scipy/signal/signaltools.py", line 393, in fftconvolve
ret = (np.fft.irfftn(sp1 * sp2, fshape)[fslice].copy())
File "/home/ubuntu/.local/lib/python3.5/site-packages/numpy/fft/fftpack.py", line 1231, in irfftn
a = ifft(a, s[ii], axes[ii], norm)
File "/home/ubuntu/.local/lib/python3.5/site-packages/numpy/fft/fftpack.py", line 288, in ifft
return output * (1 / (sqrt(n) if unitary else n))
MemoryError

I have 50 gb of memory but this isnt enough for some reason. I use the following relevant hyperparameters:

spatial_window_size = (128, 128, 128) (training and validation)

optimiser = adam
sample_per_volume = 1

lr = 0.0001
loss_type = GDSC

image = volume
label = segmentation
output_prob = True
num_classes = 2
label_normalisation = False

rand_samples = 0
min_numb_labels = 1
min_sampling_ratio = 0.001
compulsory_labels = 0,1

This error occurs not only for VNet. Ive been trying to get selective sampler to work on different networks as well. I use the big spatial window size because the amount of foreground is small in comparison to the background (also the reason I use selective sampler). Decreasing the spatial window size to (32, 32, 32) did not change anything and resulted in the same error.

Can you explain to me why so much memory is used and what I can do to prevent this error?

Need more examples

Are there any examples for ToyNet? or in other words,are there any examples for how to developing a new network from data prepare to train ?

Raise error when run examples from pip-installed NiftyNet

First, I used net_download to download the example data.Then, I want to try these examples
https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNetExampleServer/blob/master/anisotropic_nets_brats_challenge_model_zoo.md
net_run inference -a anisotropic_nets_brats_challenge.brats_seg_app.BRATSApp -c extensions/anisotropic_nets_brats_challenge/whole_tumor_axial.ini

NiftyNet version 0.2.0.post1 Traceback (most recent call last): File "/usr/local/bin/net_run", line 11, in <module> sys.exit(main()) File "/usr/local/lib/python3.5/dist-packages/niftynet/__init__.py", line 33, in main system_param, input_data_param = user_parameters_parser.run() File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/user_parameters_parser.py", line 75, in run app_module = ApplicationFactory.create(module_name) File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 155, in create return select_module(name, cls.type_str, cls.SUPPORTED) File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 117, in select_module the_module = getattr(importlib.import_module(module), class_name) File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked ImportError: No module named 'anisotropic_nets_brats_challenge'

https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNetExampleServer/blob/master/highres3dnet_brain_parcellation_model_zoo.md
net_run inference -c extensions/highres3dnet_brain_parcellation/highres3dnet_config_eval.ini
`NiftyNet version 0.2.0.post1
CRITICAL:tensorflow:Could not import application: Incorrect module name format . Expected "module.object".
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 116, in select_module
module, class_name = module_name.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/user_parameters_parser.py", line 75, in run
app_module = ApplicationFactory.create(module_name)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 155, in create
return select_module(name, cls.type_str, cls.SUPPORTED)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 136, in select_module
raise ValueError(err)
ValueError: Could not import application: Incorrect module name format . Expected "module.object".

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/net_run", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/niftynet/init.py", line 33, in main
system_param, input_data_param = user_parameters_parser.run()
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/user_parameters_parser.py", line 83, in run
module_name, app_module.REQUIRED_CONFIG_SECTION))
UnboundLocalError: local variable 'app_module' referenced before assignment
`

https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNetExampleServer/blob/master/ultrasound_simulator_gan_model_zoo.md
net_run inference -c extensions/ultrasound_simulator_gan/config.ini
`NiftyNet version 0.2.0.post1
CRITICAL:tensorflow:Could not import application: Incorrect module name format . Expected "module.object".
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 116, in select_module
module, class_name = module_name.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/user_parameters_parser.py", line 75, in run
app_module = ApplicationFactory.create(module_name)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 155, in create
return select_module(name, cls.type_str, cls.SUPPORTED)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/application_factory.py", line 136, in select_module
raise ValueError(err)
ValueError: Could not import application: Incorrect module name format . Expected "module.object".

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/net_run", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/niftynet/init.py", line 33, in main
system_param, input_data_param = user_parameters_parser.run()
File "/usr/local/lib/python3.5/dist-packages/niftynet/utilities/user_parameters_parser.py", line 83, in run
module_name, app_module.REQUIRED_CONFIG_SECTION))
UnboundLocalError: local variable 'app_module' referenced before assignment
`

Using Multiple GPU Fails ?

When I run the net_segment with dense_vnet on my data, everything works perfectly on a single GPU. However, specifying more than 1 GPU throws the following error:

InvalidArgumentError (see above for traceback): Duplicate tag imgseg/image/0 found in summary inputs
[[Node: MergedOutputs/Merge/MergeSummary = MergeSummary[N=3, device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/DenseVNet/PyFunc, worker_1/DenseVNet/PyFunc, MergedOutputs/loss_device_average)]]
[[Node: ApplyGradients/Mean_44/_2581 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_49819_ApplyGradients/Mean_44", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]]

Any idea what is wrong ?

spatial_window_size in promise12_demo_inference_config.ini

Dear all,
In NiftyNet/demos/PROMISE12/promise12_demo_inference_config.ini, we can see border = (5, 5, 5) and spatial_window_size = (0, 0, 3). Why set these two parameters to these values? (the input spatial_window_size is (64,64,64) and the original image size is (512*512*SliceNumber) )

[INFERENCE]
border = (5, 5, 5)
#inference_iter = 10
save_seg_dir = output/
output_interp_order = 0
spatial_window_size = (0, 0, 3)

The documentation in NiftyNet/config/ seems not enough to explain the setting of these two parameters. Would it be possible for you to add more explaination about these two parameters in the inference process?
For example, if I change the input spatial_window_size into 128*128*64 for Promise2012 dataset and want to obtain a 512*512*SliceNumber output in the inference process, what should the two parameters be?

Looking forward to your reply.

Best regards,
Edward

output window size of 3D U-net

Hi,
I modified demos/BRATS17 for 3D unet segmentation with my data (dimension :120x120x120, resolution 1x1x1). If I set the parameter: spatial_window_size = (8,8,8) for label, and run the command:
net_run.py train -c unet_config.ini . Everything is OK.

My questions are:
Q1: Why I can not modify spatial_window_size for a bigger value?
Q2: With this spatial_window_size, when I do: inference, there is an error:
CRITICAL:niftynet: network output window can be cropped by specifying the border parameter in config file, but here the output window (8, 8, 8) is already smaller than the input window size minus padding: [96 96 96], not supported by this aggregator

Here is my config file:
[T1]
path_to_search = ./NN
filename_contains = T1
filename_not_contains =
spatial_window_size = (96,96,96)
pixdim = (1.0, 1.0, 1.0)
axcodes=(A, R, S)
interp_order = 3

[T2]
csv_file=
path_to_search = ./NN
filename_contains = T2
filename_not_contains =
spatial_window_size = (96,96,96)
pixdim = (1.0, 1.0, 1.0)
axcodes=(A, R, S)
interp_order = 3

[label]
csv_file=
path_to_search = ./NN
filename_contains = GT
filename_not_contains =
spatial_window_size = (8,8,8)
pixdim = (1.0, 1.0, 1.0)
axcodes=(A, R, S)
interp_order = 0

[SYSTEM]
cuda_devices = ""
num_threads = 2
num_gpus = 1
model_dir = ./unet

[NETWORK]
name = unet
activation_function = prelu
batch_size = 1
decay = 0
reg_type = L2

volume_padding_size = 0

histogram_ref_file = ./label_mapping_whole_tumor.txt
norm_type = percentile
cutoff = (0.01, 0.99)
normalisation = True
whitening = True
normalise_foreground_only=True
foreground_type = otsu_plus
multimod_foreground_type = and

queue_length = 56
window_sampling = uniform

[TRAINING]
sample_per_volume = 32
rotation_angle = (-10.0, 10.0)
scaling_percentage = (-10.0, 10.0)
lr = 0.01
loss_type = Dice
starting_iter = 0
save_every_n = 5
max_iter = 10
max_checkpoints = 20

[INFERENCE]
border = (0, 0, 0)
#inference_iter = 10
save_seg_dir = ./unet
output_interp_order = 0
spatial_window_size = (96,96,96)

############################ custom configuration sections
[SEGMENTATION]
image = T1,T2
label = label
output_prob = False
num_classes = 4
label_normalisation = True

NotImplementedError failed to generate sampling locations

Dear NiftyNet team,

I am currently running a pip installed NiftyNet with Tensorflow 1.4 on Ubuntu 16.04 with a Nvidia Tesla P100 12 gb GPU. If more information is required please let me know. I am new to deep learning and trying to train four different architectures (DeepMedic, HighRes3dNet, UNet and VNet) on 1 data set. I keep the hyperparameters of these architectures the same as in the config files. Everytime I run a network, I get the following error message:

CRITICAL:niftynet: Don't know how to generate sampling locations: Spatial dimensions of the grouped input sources are not consistent. {(431, 433, 531), (611, 613, 967)}
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/image_window_buffer.py", line 143, in _push
for output_dict in self():
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/sampler_uniform.py", line 83, in layer_op
self.window.n_samples)
File "/usr/local/lib/python3.5/dist-packages/niftynet/engine/sampler_uniform.py", line 151, in rand_spatial_coordinates
raise NotImplementedError
NotImplementedError

The dimensions after the first error line are different for every training run and for every network. I use the should_stop function using -a "niftynet.application.set_iteration_update()". This error message usually ends up after a certain amount of iterations, around 150 to 250 iterations depening on the network used. I checked all the datafiles for an inconsistent file but there wasnt any. All the images have an image spacing of [1,1,1]. The spatial window size is the same as the config file of the network provides. I checked the sizes of the volumes with their respective labels and they are all the same as well. The results after this error message are saved: I get logs, tfevents, models and a setting_train.txt.

I am unsure how to go about this error message. Any help is much appreciated.

spatial_window_size Question

In the Input Data section of the Configuration file, does spatial_window_size refer to the sliding convolution window? If not, then what exactly is it referring to?

Also, why do the values have to be a multiple of 8 when using some of the applications (e.g. VNet, UNet)?

Thanks

Gradient implementation of Dice loss function

Hello everyone, I have been reviewing the Dice loss for segmentation implemented in this platform, but I could not find the gradient implementation found in the original paper[1] which is the derivation of the Dice loss:

gradient
[1] V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation

Also, on application/segmentation_application.py it directly uses the self.optimiser.compute_gradients(loss) function, so is this derivation done automatically? Any insights on this would be very appreciated.

running slower and slower ?

Hi,

I tried to run demo models. One iteration took a few seconds in the beginning, and a few hundred of seconds after an hour of running. Any idea of what happened?

Thanks a lot.

fine tuning

Hi,

is it possible to fine-tune the model on a custom dataset?

raise error when running promise2012 demo

I run promise 2012 with the following command
python net_segment.py train -c demos/PROMISE12/promise12_demo_train_config.ini
However, following error occurred:

2018-01-23 18:03:38.991667: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
2018-01-23 18:03:38.991780: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
2018-01-23 18:03:38.991886: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
INFO:niftynet: Cleaning up...
INFO:niftynet: iter 142 saved: /home/liver/Documents/Edward/NiftyNet/promise12_model/models/model.ckpt
INFO:niftynet: stopping sampling threads
INFO:niftynet: SegmentationApplication stopped (time in second 491.49).
Traceback (most recent call last):
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1323, in _do_call
    return fn(*args)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
    status, run_metadata)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
	 [[Node: worker_0/loss_function/Mean_2/_141 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_3410_worker_0/loss_function/Mean_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/__init__.py", line 140, in main
    app_driver.run_application()
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/engine/application_driver.py", line 238, in run_application
    self._training_loop(session, loop_status)
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/engine/application_driver.py", line 432, in _training_loop
    self.run_vars(sess, iter_msg)
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/engine/application_driver.py", line 394, in run_vars
    graph_output = sess.run(vars_to_run, feed_dict=message.data_feed_dict)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 889, in run
    run_metadata_ptr)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1120, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1317, in _do_run
    options, run_metadata)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1336, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
	 [[Node: worker_0/loss_function/Mean_2/_141 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_3410_worker_0/loss_function/Mean_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

Caused by op 'worker_0/loss_function/mul', defined at:
  File "net_segment.py", line 8, in <module>
    sys.exit(main())
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/__init__.py", line 140, in main
    app_driver.run_application()
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/engine/application_driver.py", line 224, in run_application
    self.graph = self._create_graph(self.graph)
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/engine/application_driver.py", line 292, in _create_graph
    self.gradients_collector)
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/application/segmentation_application.py", line 281, in connect_data_and_network
    weight_map=data_dict.get('weight', None))
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/layer/base_layer.py", line 34, in __call__
    return self._op(*args, **kwargs)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/template.py", line 268, in __call__
    result = self._call_func(args, kwargs, check_for_new_variables=False)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/template.py", line 217, in _call_func
    result = self._func(*args, **kwargs)
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/layer/loss_segmentation.py", line 113, in layer_op
    loss_batch.append(self._data_loss_func(**loss_params))
  File "/home/liver/Documents/Edward/NiftyNet/niftynet/layer/loss_segmentation.py", line 410, in dice
    one_hot * prediction, reduction_axes=[0])
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 905, in binary_op_wrapper_sparse
    name=name), sp_x.dense_shape)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_sparse_ops.py", line 852, in sparse_dense_cwise_mul
    sp_shape=sp_shape, dense=dense, name=name)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/home/liver/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
	 [[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
	 [[Node: worker_0/loss_function/Mean_2/_141 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_3410_worker_0/loss_function/Mean_2", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

would it be possible for you to tell me how to solve this problem.
Looking forward to your reply.
Best wishes,
Edward

How can I use dicom data as input data?

I have some dicom data for training and test, but I don't kown how to use this data as input. If I should convert this data as NIFTI type or I just modify the config file?

Dynamic Window Size

Dear All,

I'm trying to use dynamic window size for segmentation, which should be at -1.
But I can't understand why sometimes it's working and sometimes it's not.

When it doesn't work, I get the following message
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

What's the requirement for dynamic sizing?

out-of-bounds w.r.t. dense side with broadcasted shape issue during promise12 demo training

When I run training with default settings of promise12 demo. The process fails with "out-of-bounds w.r.t. dense side with broadcasted shape" after couple of hundreds iterations.
This problem disappears if I switch off data augmentation :
#rotation_angle = (-10.0, 10.0)
#scaling_percentage = (-10.0, 10.0)
#random_flipping_axes= 1

Python libraries are as described in requirements and tensorflow in version 1.3. This problem is present in default branch of Niftynet as of Oct 26, 2017 . It was also seen 1 month ago.

This is full log of the issue:
INFO:niftynet: iter 234, dice_loss=0.5082721710205078 (1.068s)
2017-10-26 10:57:30.556125: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
2017-10-26 10:57:30.556195: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
2017-10-26 10:57:30.556216: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
INFO:niftynet: Cleaning up...
INFO:niftynet: iter 235 saved: /home/ladislav/temp/promise12_model/models/model.ckpt
INFO:niftynet: stopping sampling threads
INFO:niftynet: SegmentationApplication stopped (time in second 1073.88).
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1327, in _do_call
return fn(*args)
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1306, in _run_fn
status, run_metadata)
File "/usr/lib64/python3.5/contextlib.py", line 66, in exit
next(self.gen)
File "/usr/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
[[Node: worker_0/gradients/AddN/_1901 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_6703_worker_0/gradients/AddN", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ladislav/NiftyNet/net_segment.py", line 7, in
sys.exit(main())
File "/home/ladislav/NiftyNet/niftynet/init.py", line 83, in main
app_driver.run_application()
File "/home/ladislav/NiftyNet/niftynet/engine/application_driver.py", line 183, in run_application
self._training_loop(session, loop_status)
File "/home/ladislav/NiftyNet/niftynet/engine/application_driver.py", line 352, in _training_loop
graph_output = sess.run(vars_to_run)
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 895, in run
run_metadata_ptr)
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1124, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
options, run_metadata)
File "/usr/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
[[Node: worker_0/gradients/AddN/_1901 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_6703_worker_0/gradients/AddN", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]]

Caused by op 'worker_0/loss_function/mul', defined at:
File "/home/ladislav/NiftyNet/net_segment.py", line 7, in
sys.exit(main())
File "/home/ladislav/NiftyNet/niftynet/init.py", line 83, in main
app_driver.run_application()
File "/home/ladislav/NiftyNet/niftynet/engine/application_driver.py", line 169, in run_application
self.graph = self._create_graph(self.graph)
File "/home/ladislav/NiftyNet/niftynet/engine/application_driver.py", line 236, in _create_graph
self.gradients_collector)
File "/home/ladislav/NiftyNet/niftynet/application/segmentation_application.py", line 237, in connect_data_and_network
weight_map=data_dict.get('weight', None))
File "/home/ladislav/NiftyNet/niftynet/layer/base_layer.py", line 32, in call
return self._op(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/tensorflow/python/ops/template.py", line 268, in call
result = self._call_func(args, kwargs, check_for_new_variables=False)
File "/usr/lib/python3.5/site-packages/tensorflow/python/ops/template.py", line 217, in _call_func
result = self._func(*args, **kwargs)
File "/home/ladislav/NiftyNet/niftynet/layer/loss_segmentation.py", line 61, in layer_op
pred, ground_truth, weight_map))
File "/home/ladislav/NiftyNet/niftynet/layer/loss_segmentation.py", line 343, in dice
dice_numerator = 2.0 * tf.sparse_reduce_sum(one_hot * prediction,
File "/usr/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 876, in binary_op_wrapper_sparse
name=name), sp_x.dense_shape)
File "/usr/lib/python3.5/site-packages/tensorflow/python/ops/gen_sparse_ops.py", line 601, in sparse_dense_cwise_mul
dense=dense, name=name)
File "/usr/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/usr/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1204, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape
[[Node: worker_0/loss_function/mul = SparseDenseCwiseMul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](worker_0/loss_function/stack, worker_0/loss_function/ones_like, worker_0/loss_function/ToInt64_2, worker_0/loss_function/Softmax)]]
[[Node: worker_0/gradients/AddN/_1901 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_6703_worker_0/gradients/AddN", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]]

Simple 3D segmentation with U-Net example

Hi,
First, thanks for a nice package. I had no problems running some of the pre-trained BRATS models.

However, when I was trying to use net_segment.py to train using some of my own data, I ran into roadblocks.

I get something to the effect of
sh$ net_segment -c train_myconfig.ini

NiftyNet version 0.2.0.post1.dev481
usage: net_segment [-h] [--cuda_devices] [--num_threads] [--num_gpus]
[--model_dir]
{train,inference}
net_segment: error: too few arguments

train_myconfig.ini is directly copied from:
https://github.com/NifTK/NiftyNet/blob/dev/config/unet_config.ini
and filepaths are updated to reflect my local system. I am on a MacBook OSX10.12.6 (No GPU) : File contents pasted below

[T1]
path_to_search = /Users/bilwaj/Dropbox/DeepVertebra/train/img
filename_contains = img
filename_not_contains =
spatial_window_size = (3, 64, 64)
pixdim = (1.0, 1.0, 1.0)
axcodes=(A, R, S)
interp_order = 3

[parcellation]
path_to_search = /Users/bilwaj/Dropbox/DeepVertebra/train/mask
filename_contains = img
filename_not_contains =
spatial_window_size = (3, 64, 64)
pixdim = (1.0, 1.0, 1.0)
axcodes=(A, R, S)
interp_order = 0

[SYSTEM]
cuda_devices = ""
num_threads = 2
num_gpus = 1
model_dir = /Users/bilwaj/Dropbox/DeepVertebra/niftynet

[NETWORK]
name = unet
activation_function = prelu
batch_size = 1
decay = 0
reg_type = L2

############################### volume level preprocessing
volume_padding_size = 0
############################# histogram normalisation
histogram_ref_file = ./label_mapping.txt
norm_type = percentile
cutoff = (0.01, 0.99)
normalisation = True
whitening = True
normalise_foreground_only=True
foreground_type = otsu_plus
multimod_foreground_type = and

queue_length = 128
window_sampling = uniform

[TRAINING]
sample_per_volume = 32
rotation_angle = (-10.0, 10.0)
scaling_percentage = (-10.0, 10.0)
lr = 0.01
loss_type = Dice
starting_iter = 0
save_every_n = 5
max_iter = 10
max_checkpoints = 20

[INFERENCE]
border = (0, 0, 0)
#inference_iter = 10
save_seg_dir = ./output/unet
output_interp_order = 0
spatial_window_size = (3, 64, 64)

############################ custom configuration sections
[SEGMENTATION]
image = T1
label = parcellation
output_prob = False
num_classes = 2
label_normalisation = True

net_download fail

I'm currently trying to try out the net_download command, but I am getting the following error.

Accessing: https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNetExampleServer
Warning: updating the examples file from the server caused an error: [Errno socket error] [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:661)
highres3dnet_brain_parcellation_model_zoo: FAIL.
Cannot download the examples configuration file. Is the server down?

What can I do?

Does the project support train batch norm in multiple gpus?

I have 4 gpus and I want to train my network that includes batch norm layer on the machine. As we know, the segmention performance will increase if we consider a larger batch size and train the batch norm
However, the tensorflow did not support to syn. batch norm on multiple gpus. Does this project support it? Thanks

Add some comments about DenseVNet

Dear NiftyNet team,
NiftyNet is really an excellent work. Thank you very much.
When I read the dense_vnet.py, I couldn't understand the network architecture very well. For instance, where are the upsampling blocks?
Would it be possible for you to add some comments to dense_vnet.py.

By the way, when the preprint of "Automatic multi-organ segmentation on abdominal CT with dense V-networks" can be available?

Looking forward to your reply!
Best,
Edward.

A question about sample_per_volume and resize in promise2012 demo

Dear all,
In the demos/PROMISE12/promise12_demo_train_config.ini, the two parameters are set as window_sampling = resize and sample_per_volume = 4.
In this case, what is the sampler_resize output?
It seems the sample_per_volume is useless in this case. Because in def initialise_resize_sampler(self):, sampler_resize is not used.

    def initialise_resize_sampler(self):
        self.sampler = [[ResizeSampler(
            reader=reader,
            data_param=self.data_param,
            batch_size=self.net_param.batch_size,
            shuffle_buffer=self.is_training,
            queue_length=self.net_param.queue_length) for reader in
            self.readers]]

Besides, what is the role of sampler_resize in segmentation_application? For a segmentation task, I'm confused why resizing the input image (such as a 512*512*125 volume) into a 64*64*64 spatial window? Instead, sampling some 64*64*64 image patches from an image volume seems more reasonable.
And the segmentation results in the test dataset do not match very well. Would it be possible for you to tell me what is the possible reason?
Following are some results of case4.

  • Markdown
  • Markdown

Looking forward to your reply.
Best wishes,
Edward

Inference Segmentation to 1, sampling problem?

Dear all,

while training a VNet I see that the Dice loss is stuck at 0.5 and the resulting segmentation from the inference is label 1 everywhere.

I suppose it has to do with the uniform sampling: given that the labels are quite sparse most of the sampling result in chunk of the original image with only one label.

Is there a way to keep the label distribution in consideration while sampling?

Question about samplers

Hi NiftyNet team,

From what I understand by looking at the sampler codes, the uniform sampler randomly selects a location from the entire volume and crops the desired window size. I guess there's no guarantee that the training volumes are fully covered/used by the end of the training process. Is there a way to train a 3D network with an overlapping sliding window approach (grid sampler is not overlapping) that keeps track of what windows have been used so far for each data? Such a sampler would be useful to make sure we're using every single pixel in training.

Thanks

error: argument --axcodes: list of strings expected

I have just started exploring NiftyNet, which I think will help me in my project.

I am trying to train a network for segmentation using the segmentation_application. However I built my own config.ini file and when running net_run.py I receive the error:

error: argument --axcodes: list of strings expected, for each list element the allowed characters: [ a-zA-Z0-9_-], but received ' '

I am following the configuration file requirements setting axcodes=A,R,S. I also tried different lists of strings ('A','R','S'; [A,R,S]; (A,R,S); ...)

My config.ini file states:

[T2]
csv_file = /home/jose/niftynet/data/uNet/test_data/data_file.csv
spatial_window_size = (257,257,30)
pixdim = (1.0, 1.0, 1.0)
axcodes= A,R,S
interp_order=1

What am I doing wrong?

Labels of multi-classes segmentation using holisticnet

Dear all,
I used holisticnet_config.ini for BRATS segmentation, but the output has 2 value: 0,1 ( for BG and Foreground). My histogram_ref_file file is :
labellabelto 0 1 2 3 4
labellabelfrom 0 1 1 1 1
I would like to see the output with labels of each class. Do you know something wrong with my setup? Thanks.

NiftyNetExamples server is not running

When executing the following command on my MacBookPro (macOS High Sierra v. 10.13.3):
net_download highres3dnet_brain_parcellation_model_zoo

this message is displayed:
Accessing: https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNetExampleServer
The NiftyNetExamples server is not running

When I run the same command on an Ubuntu stand-alone server and on an EC2 instance it works fine. A previous post mentioned this same issue in the context of an SSL connection error, but it seemed to be resolved. Is this a problem for macOS? Is there something I need to do on my end to fix it?

Thank you!

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.