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: Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape #273

Closed qianjiangcn closed 5 years ago

qianjiangcn commented 5 years ago

I have been running into the error trying to use niftynet highRes2Dnet to perform 3D segmentation:

InvalidArgumentError (see above for traceback): Provided indices are out-of-bounds w.r.t. dense side with broadcasted shape [[{{node worker_0/loss_function/map/while/mul}} = SparseDenseCwiseMul[T=DT_FLOAT, _class=["loc:@worke...tackPushV2"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](worker_0/loss_function/map/while/SparseReshape, worker_0/loss_function/map/while/ones_like, worker_0/loss_function/map/while/SparseReshape:1, worker_0/loss_function/map/while/Softmax)]]

As one issue stated, this could happen when the largest voxel value in the discrete segmentation maps is greater than num_classes in the config file. what do you mean largest voxel value in the discrete segmentation maps? my spatial window is 32 and the num_classes in the config is 160. Here is the config info and the size of input data is 128256256

[T1]
path_to_search = ../Training/Training_E2E
filename_contains = T1
filename_not_contains =
spatial_window_size = (32, 32, 32)
interp_order = 0
pixdim = (1.0, 1.0, 1.0)
axcodes = (R, A, S)

[parcellation]
path_to_search = ../Training/Training_E2E
filename_contains = Label
filename_not_contains =
spatial_window_size = (32, 32, 32)
interp_order = 0
pixdim = (1.0, 1.0, 1.0)
axcodes = (R, A, S)

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

[NETWORK]
name = highres3dnet
batch_size = 1
activation_function = prelu
volume_padding_size = 10

whitening = False
normalisation = True
normalise_foreground_only=True
foreground_type = mean_plus
histogram_ref_file = ./example_volumes/monomodal_parcellation/standardisation_models.txt
cutoff = (0.001, 0.999)

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

############################ custom configuration sections
[SEGMENTATION]
image = T1
label = parcellation
output_prob = False
num_classes = 160
label_normalisation = True
tomvars commented 5 years ago

Hi! This is likely because you haven't changed the histogram_ref_file. Please refer to this stack overflow post https://stackoverflow.com/questions/46831160/niftynet-indices-are-out-of-bounds-error and this section of the read the docs https://niftynet.readthedocs.io/en/dev/config_spec.html#histogram-ref-file for more information

qianjiangcn commented 5 years ago

Hi! This is likely because you haven't changed the histogram_ref_file. Please refer to this stack overflow post https://stackoverflow.com/questions/46831160/niftynet-indices-are-out-of-bounds-error and this section of the read the docs https://niftynet.readthedocs.io/en/dev/config_spec.html#histogram-ref-file for more information

Hi, thank you very much for your answer. Yes I did not change the histogram_ref_file and it seems to generate a new one by ''normalisation histogram training |----------| 2.8%'' And I am still not sure how to set up the normalisation_file? Should I write a txt file indicating number of labels ? I referred to the config file and there has not been much information. Thank you very much!

Zach-ER commented 5 years ago

Hi there,

Apologies for the confusion: First of all, make sure that num_classes is set in the [SEGMENTATION] section of the config file to however many classes are present in your images (e.g. 2 for binary segmentation).

After this, run the network. If it crashes after the histogram training, look at the last two lines of histogram training. Make sure the label-from and label-to are set correctly. For example, in this example I've taken from BRaTS, I've mapped label 4.0 to 3 to make the labels sequential.

[name-of-label-field]_label-from 0.0 1.0 2.0 4.0 
[name-of-label-field]_label-to 0 1 2 3 

Does this help?

ericspod commented 5 years ago

If there isn't any more action on this I will close it.