nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

3D segmentation issue : IndexError: index 2 is out of bounds for axis 0 with size 2

Open kgh6784 opened this issue 1 year ago • 1 comments

I am currently attempting 3D segmentation, but I am encountering an IndexError: index 2 is out of bounds for axis 0 with size 2. This error persists and I am unable to resolve it. Below is the configuration of my data environment.

Dataset: MRI T1

Size:

IMG: (depth, 256, 256, 1) Mask: (depth, 256, 256, 1) The reason to add 1 channel is related to --verify_dataset_integrity Voxel Spacing: (1.0, 1.0, 1.0, 1.0) dataset.json file configuration:

{
    "name": "Dataset777_surgical",
    "description": "Surgical region segmentation dataset",
    "tensorImageSize": "3D",
    "channel_names": {
        "0": "MRI"
    },
    "modality": {
        "0": "noNorm"
    },
    "labels": {
        "background": 0,
        "Surgical_region": 1
    },
    "numTraining": 75,
    "numTest": 9,
    "file_ending": ".nii.gz"
}

nnUNetv2_plan_and_preprocess -d 777 -pl ExperimentPlanner -c 3d_fullres -np 2 nnUNetv2_plan_and_preprocess -d 777 -pl ExperimentPlanner -c 3d_lowres -np 2 I have tried adjusting the shape of the image, but the issue persists. When I remove the channel (1) from the shape to resolve the voxel spacing issue, an integrity error occurs.

The error occurs in the fullres_spacing_transposed = fullres_spacing[transpose_forward] area of the default_experiment_planner.py code.

I tried --verify_dataset_integrity and it's ok now. And above index error still existed.

How can I resolve this issue? Direct access to nnUNet's default_experiment_planner.py seems difficult. I already tried a lot of things to change image shape, dataset.json file information changes... Thank you.

Above info is header example

Header:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr      : 348
data_type       : b''
db_name         : b''
extents         : 0
session_error   : 0
regular         : b''
dim_info        : 0
dim             : [  4 130 256 256   1   1   1   1]
intent_p1       : 0.0
intent_p2       : 0.0
intent_p3       : 0.0
intent_code     : none
datatype        : uint8
bitpix          : 8
slice_start     : 0
pixdim          : [1. 1. 1. 1. 1. 1. 1. 1.]
vox_offset      : 0.0
scl_slope       : nan
scl_inter       : nan
slice_end       : 0
slice_code      : unknown
xyzt_units      : 0
cal_max         : 0.0
cal_min         : 0.0
slice_duration  : 0.0
toffset         : 0.0
glmax           : 0
glmin           : 0
descrip         : b''
aux_file        : b''
qform_code      : unknown
sform_code      : aligned
quatern_b       : 0.0
quatern_c       : 0.0
quatern_d       : 0.0
qoffset_x       : 0.0
qoffset_y       : 0.0
qoffset_z       : 0.0
srow_x          : [1. 0. 0. 0.]
srow_y          : [0. 1. 0. 0.]
srow_z          : [0. 0. 1. 0.]
intent_name     : b''
magic           : b'n+1'
Affine:
[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

kgh6784 avatar Jul 26 '24 15:07 kgh6784

Hi @kgh6784, Sorry for the late reply!

The issue is that nnU-Net expects the data to be formatted without a channel dimension.

Therefore: IMG: (depth, 256, 256, 1) would need to be (depth, 256, 256) Mask: (depth, 256, 256, 1) would need to be (depth, 256, 256)

For further information regarding the expected dataset format I refer you to the Documentation

Best regards, Carsten

sten2lu avatar Aug 13 '24 07:08 sten2lu