NifTK / NiftyNet

[unmaintained] An open-source convolutional neural networks platform for research in medical image analysis and image-guided therapy
http://niftynet.io
Apache License 2.0
1.37k stars 404 forks source link

Error : Don't know how to generate sampling locations: Spatial dimensions of the grouped input sources are not consistent. #170

Closed yshvrdhn closed 6 years ago

yshvrdhn commented 6 years ago

Hi I am running a task on deep medic which has 14 classes : I am getting an error in uniform sampling layer : I tried debugging the shapes that are passed to _infer_spatial_size function which are shown in the output below. Any help would be greatly appreciated. How is the images and label sample size generatd : {'image': (477, 451, 187, 1, 1), 'label': (391, 369, 147, 1, 1)} that causes the error ?

CRITICAL:niftynet: Don't know how to generate sampling locations: Spatial dimensions of the grouped input sources are not consistent. {(477, 451, 187), (391, 369, 147)}
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/image_window_buffer.py", line 148, in _push
    for output_dict in self():
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 81, in layer_op
    self.window.n_samples)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 151, in _spatial_coordinates_generator
    _infer_spatial_size(img_sizes, win_sizes)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 238, in _infer_spatial_size
    raise NotImplementedError
NotImplementedError

The whole output is given below :

[CUSTOM]
-- num_classes: 14
-- output_prob: True
-- label_normalisation: True
-- softmax: True
-- min_sampling_ratio: 0
-- compulsory_labels: (0, 1)
-- rand_samples: 0
-- min_numb_labels: 1
-- proba_connect: True
-- evaluation_units: foreground
-- image: ('images',)
-- label: ('label',)
-- weight: ()
-- sampler: ()
-- inferred: ()
-- name: net_segment
[CONFIG_FILE]
-- path: /home/ubuntu/niftynet/extensions/deepmedic/deepmedic_all_task_renambed_labels.ini
[IMAGES]
-- csv_file:
-- path_to_search: /home/ubuntu/med_deacthalon/Task_all_same_names/imagesTr_1
-- filename_contains: ()
-- filename_not_contains: ('_lung_',)
-- interp_order: 3
-- loader: None
-- pixdim: (1.0, 1.0, 1.0)
-- axcodes: ('A', 'R', 'S')
-- spatial_window_size: (51, 51, 51)
[LABEL]
-- csv_file:
-- path_to_search: /home/ubuntu/med_deacthalon/Task_all_same_names/labelsTr_1
-- filename_contains: ()
-- filename_not_contains: ('_lung_',)
-- interp_order: 3
-- loader: None
-- pixdim: (1.0, 1.0, 1.0)
-- axcodes: ('A', 'R', 'S')
-- spatial_window_size: (9, 9, 9)
[SYSTEM]
-- cuda_devices: ""
-- num_threads: 2
-- num_gpus: 1
-- model_dir: /home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels
-- dataset_split_file: ./dataset_split.csv
-- action: train
[NETWORK]
-- name: deepmedic
-- activation_function: relu
-- batch_size: 32
-- decay: 0.0
-- reg_type: L2
-- volume_padding_size: (21, 21, 21)
-- volume_padding_mode: minimum
-- window_sampling: uniform
-- queue_length: 128
-- multimod_foreground_type: and
-- histogram_ref_file: histogram_standardisation_alltask.txt
-- norm_type: percentile
-- cutoff: (0.01, 0.99)
-- foreground_type: otsu_plus
-- normalisation: False
-- whitening: True
-- normalise_foreground_only: True
-- weight_initializer: he_normal
-- bias_initializer: zeros
-- keep_prob: 1.0
-- weight_initializer_args: {}
-- bias_initializer_args: {}
[TRAINING]
-- optimiser: adam
-- sample_per_volume: 32
-- rotation_angle: (-10.0, 10.0)
-- rotation_angle_x: ()
-- rotation_angle_y: ()
-- rotation_angle_z: ()
-- scaling_percentage: (-10.0, 10.0)
-- random_flipping_axes: -1
-- do_elastic_deformation: False
-- num_ctrl_points: 4
-- deformation_sigma: 15
-- proportion_to_deform: 0.5
-- lr: 0.001
-- loss_type: Dice
-- starting_iter: 0
-- save_every_n: 45
-- tensorboard_every_n: 20
-- max_iter: 10
-- max_checkpoints: 20
-- validation_every_n: -1
-- validation_max_iter: 1
-- exclude_fraction_for_validation: 0.0
-- exclude_fraction_for_inference: 0.0
[INFERENCE]
-- spatial_window_size: (57, 57, 57)
-- inference_iter: -1
-- dataset_to_infer:
-- save_seg_dir: ./deepmedic/alltask_newname
-- output_postfix: _niftynet_out
-- output_interp_order: 0
-- border: (36, 36, 36)
INFO:niftynet: Import [SegmentationApplication] from /home/ubuntu/niftynet/NiftyNet/niftynet/application/segmentation_application.py.
INFO:niftynet: starting segmentation application
INFO:niftynet: `csv_file = ` not found, writing to "/home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/images.csv" instead.
INFO:niftynet: Overwriting existing: "/home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/images.csv".
INFO:niftynet: [images] search file folders, writing csv file /home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/images.csv
INFO:niftynet: `csv_file = ` not found, writing to "/home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/label.csv" instead.
INFO:niftynet: Overwriting existing: "/home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/label.csv".
INFO:niftynet: [label] search file folders, writing csv file /home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/label.csv
WARNING:niftynet: Loading from existing partitioning file /home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/dataset_split.csv, ignoring partitioning ratios.
INFO:niftynet:

Number of subjects 6, input section names: ['subject_id', 'images', 'label']
Dataset partitioning:
-- Training 112 cases (1866.67%),
-- Validation 28 cases (466.67%),
-- Inference 0 cases (0.00%).

INFO:niftynet: Image reader: loading 5 subjects from sections ('images',) as input [image]
INFO:niftynet: Image reader: loading 5 subjects from sections ('label',) as input [label]
INFO:niftynet: label mapping ready for label:('label',), 14 classes
INFO:niftynet: reading size of preprocessed images
INFO:niftynet: initialised window instance
INFO:niftynet: buffering with 128 windows
INFO:niftynet: initialised sampler output {'image': (32, 51, 51, 51, 1, 1), 'image_location': (32, 7), 'label': (32, 9, 9, 9, 1, 1), 'label_location': (32, 7)}
2018-07-25 04:34:12.962405: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-07-25 04:34:13.081655: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-07-25 04:34:13.082100: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1344] Found device 0 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0000:00:1e.0
totalMemory: 15.77GiB freeMemory: 15.36GiB
2018-07-25 04:34:13.082133: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0
2018-07-25 04:34:13.398041: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-25 04:34:13.398107: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0
2018-07-25 04:34:13.398121: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N
2018-07-25 04:34:13.398525: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14869 MB memory) -> physical GPU (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:1e.0, compute capability: 7.0)
INFO:niftynet: Starting preprocessing threads...
INFO:niftynet: New thread: 0
INFO:niftynet: New thread: 1
INFO:niftynet: Filling queues (this can take a few minutes)
2018-07-25 04:34:13.549514: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0
2018-07-25 04:34:13.549584: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-25 04:34:13.549602: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0
2018-07-25 04:34:13.549618: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N
2018-07-25 04:34:13.549776: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/device:GPU:0 with 14869 MB memory) -> physical GPU (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:1e.0, compute capability: 7.0)
INFO:niftynet: Import [DeepMedic] from /home/ubuntu/niftynet/NiftyNet/niftynet/network/deepmedic.py.
INFO:niftynet: Import [HeNormal] from /home/ubuntu/niftynet/NiftyNet/niftynet/engine/application_initializer.py.
INFO:niftynet: Import [Zeros] from /home/ubuntu/niftynet/NiftyNet/niftynet/engine/application_initializer.py.
INFO:niftynet: using DeepMedic
2018-07-25 04:34:13.599446: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0
2018-07-25 04:34:13.599508: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-25 04:34:13.599523: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0
2018-07-25 04:34:13.599537: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N
2018-07-25 04:34:13.599687: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/device:GPU:0 with 14869 MB memory) -> physical GPU (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:1e.0, compute capability: 7.0)
[51, 51, 51]
[51, 51, 51]
[51, 51, 51]
[Layer] DeepMedic/cropping_input
[Layer] DeepMedic/constant_downsample_input
[Layer] DeepMedic/normal_conv_bn_relu [Trainable] conv_/w, bn_/beta, bn_/gamma (870)
[Layer] DeepMedic/downsample_conv_bn_relu [Trainable] conv_/w, bn_/beta, bn_/gamma (870)
[Layer] DeepMedic/normal_conv_bn_relu_1 [Trainable] conv_/w, bn_/beta, bn_/gamma (24360)
[Layer] DeepMedic/downsample_conv_bn_relu_1 [Trainable] conv_/w, bn_/beta, bn_/gamma (24360)
[Layer] DeepMedic/normal_conv_bn_relu_2 [Trainable] conv_/w, bn_/beta, bn_/gamma (32480)
[Layer] DeepMedic/downsample_conv_bn_relu_2 [Trainable] conv_/w, bn_/beta, bn_/gamma (32480)
[Layer] DeepMedic/normal_conv_bn_relu_3 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/downsample_conv_bn_relu_3 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/normal_conv_bn_relu_4 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/downsample_conv_bn_relu_4 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/normal_conv_bn_relu_5 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/downsample_conv_bn_relu_5 [Trainable] conv_/w, bn_/beta, bn_/gamma (43280)
[Layer] DeepMedic/normal_conv_bn_relu_6 [Trainable] conv_/w, bn_/beta, bn_/gamma (54100)
[Layer] DeepMedic/downsample_conv_bn_relu_6 [Trainable] conv_/w, bn_/beta, bn_/gamma (54100)
[Layer] DeepMedic/normal_conv_bn_relu_7 [Trainable] conv_/w, bn_/beta, bn_/gamma (67600)
image_id :  1
image_shapes :  {'image': (97, 66, 73, 1, 1), 'label': (97, 66, 73, 1, 1)} static_window_shapes : {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)}
subject_id :  1
img_sizes {'image': (97, 66, 73, 1, 1), 'label': (97, 66, 73, 1, 1)} win_sizes :  {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)} n_samples :  32
[Layer] DeepMedic/downsample_conv_bn_relu_7 [Trainable] conv_/w, bn_/beta, bn_/gamma (67600)
[Layer] DeepMedic/conv_1x1x1_150_bn_relu [Trainable] conv_/w, bn_/beta, bn_/gamma (15300)
[Layer] DeepMedic/conv_1x1x1_150_bn_relu_1 [Trainable] conv_/w, bn_/beta, bn_/gamma (22800)
[Layer] DeepMedic/conv_1x1x1_14_bn_relu [Trainable] conv_/w, bn_/beta, bn_/gamma (2128)
INFO:niftynet: Import [Adam] from /home/ubuntu/niftynet/NiftyNet/niftynet/engine/application_optimiser.py.
INFO:niftynet: Import [dice] from /home/ubuntu/niftynet/NiftyNet/niftynet/layer/loss_segmentation.py.
INFO:niftynet: starting from iter 0
INFO:niftynet: Parameters from random initialisations ...
image_id :  2
image_shapes :  {'image': (477, 451, 187, 1, 1), 'label': (391, 369, 147, 1, 1)} static_window_shapes : {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)}
subject_id :  2
img_sizes {'image': (477, 451, 187, 1, 1), 'label': (391, 369, 147, 1, 1)} win_sizes :  {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)} n_samples :  32
CRITICAL:niftynet: Don't know how to generate sampling locations: Spatial dimensions of the grouped input sources are not consistent. {(477, 451, 187), (391, 369, 147)}
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/image_window_buffer.py", line 148, in _push
    for output_dict in self():
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 81, in layer_op
    self.window.n_samples)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 151, in _spatial_coordinates_generator
    _infer_spatial_size(img_sizes, win_sizes)
  File "/home/ubuntu/niftynet/NiftyNet/niftynet/engine/sampler_uniform.py", line 238, in _infer_spatial_size
    raise NotImplementedError
NotImplementedError

INFO:niftynet: Training iter 1, loss=0.9819566607475281 (66.394510s)
INFO:niftynet: Cleaning up...
INFO:niftynet: iter 1 saved: /home/ubuntu/models_nifty/deepmedic/all_task_same_name_rename_labels/models/model.ckpt
INFO:niftynet: stopping sampling threads
INFO:niftynet: SegmentationApplication stopped (time in second 70.99).
yshvrdhn commented 6 years ago

@fepegar Can you shed some light on this issue?

fepegar commented 6 years ago

It looks like your input image and corresponding label image have different shapes:

'image': (477, 451, 187, 1, 1), 'label': (391, 369, 147, 1, 1)}

Can you check that?

yshvrdhn commented 6 years ago

@fepegar I have 6 images. Does the image id corresponds to that same row in the csv file is that how I identify which image is causing the issue? UPDATE : I checked the shapes of corresponding image and labels they have same shape but individually they have different shapes Could you help me understand how the uniform sampler generates these shapes ?

yshvrdhn commented 6 years ago

@fepegar I singled out 1 image that is causing a similar issue : So I passed only 1 image with the following dimensions :

image_id : 0 image_shapes : {'image': (359, 411, 629, 1, 1), 'label': (470, 539, 786, 1, 1)} static_window_shapes : {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)} subject_id : 0 INFO:niftynet: iter 1 saved: /home/ubuntu/models_nifty/deepmedic/single_task_labels_rename_liver_padded_3/models/model.ckpt img_sizes {'image': (359, 411, 629, 1, 1), 'label': (470, 539, 786, 1, 1)} win_sizes : {'image': (51, 51, 51, 1, 1), 'label': (9, 9, 9, 1, 1)} n_samples : 32 INFO:niftynet: stopping sampling threads CRITICAL:niftynet: Don't know how to generate sampling locations: Spatial dimensions of the grouped input sources are not consistent. {(470, 539, 786), (359, 411, 629)} INFO:niftynet: SegmentationApplication stopped (time in second 169.39).

wyli commented 6 years ago

Hi @yshvrdhn now this looks like a voxel spacing issue. In the config file you provided pixdim = (1.0, 1.0, 1.0), which means resampling all inputs from the volumes's original voxel spacing to 1.0x1.0x1.0mm spacing before feeding them to the network. Perhaps the corresponding image and labels have different voxel spacing values stored in header, and therefore different shapes after resampling? If this is the case, you could remove pixdim=(1.0, 1.0, 1.0) in the config which means using volume's original spacing.

yshvrdhn commented 6 years ago

@wyli Yep that was the issue. It fixed the error! Thank you!

zhaoxiaoqian666 commented 5 years ago

I have the same problem, but there is no pixdim in my configuration file. How can I solve it?

fepegar commented 5 years ago

@zhaoxiaoqian666 Please open a new issue specifying your configuration and output.