Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kgh6784 opened this issue Jul 26, 2024 · 1 comment
Assignees

Comments

@kgh6784
Copy link

kgh6784 commented Jul 26, 2024

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.]]
@sten2lu
Copy link
Contributor

sten2lu commented Aug 13, 2024

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 sten2lu closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants