Skip to content
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

IndexError: index 255 is out of bounds for axis 1 with size 3 #93

Open
Qcatbot opened this issue Jul 16, 2021 · 5 comments
Open

IndexError: index 255 is out of bounds for axis 1 with size 3 #93

Qcatbot opened this issue Jul 16, 2021 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@Qcatbot
Copy link

Qcatbot commented Jul 16, 2021

Hello, I use MIScnn repo to segment medical images.
My data come from 2018 Atrial Segmentation Challenge. I follow exactly the same way the tutorial says, however, I get the error. Could you please give a clue why this error comes when I test it?

Thank you.

@Qcatbot
Copy link
Author

Qcatbot commented Jul 17, 2021

My dataset does not contain multi-class segmentation. Only the left atrial of human heart.

My segmentation mask like follows;

case_00090 [ 0. 255.]
case_00091 [ 0. 255.]
case_00092 [ 0. 255.]
case_00093 [ 0. 255.]
case_00094 [ 0. 255.]
case_00095 [ 0. 255.]
case_00096 [ 0. 255.]
case_00097 [ 0. 255.]
case_00098 [ 0. 255.]
case_00099 [ 0. 255.]
[[[[0.]
[0.]
[0.]
...
[0.]
[0.]
[0.]]
Its not very clear whats the problem. Much appreciate if you could guide me. Thank you!

@muellerdo muellerdo self-assigned this Jul 20, 2021
@muellerdo muellerdo added the question Further information is requested label Jul 20, 2021
@muellerdo muellerdo added this to Support/Bugs in Development of MIScnn via automation Jul 20, 2021
@muellerdo
Copy link
Member

muellerdo commented Jul 20, 2021

Hey @Qcatbot,

you have to preprocess your data to be sparse categorical.

This mean that your segmentation mask should have only increasing class values like 0 (for class 0), 1 (for class 1), ...
This grayscale mask [0, 255] instead of [0,1] can not be processed by MIScnn.

Also I'm quite confused why the error states "for axis 1 with size 3". Sounds like keras found more 3 classes instead of 2.
Could you provide the full error log and a reproducible example in google colab?

Cheers,
Dominik

@leonieburg
Copy link

Hi @Qcatbot,
I had the same problem.
For some reason MIScnn needs to have consecutive values for the classes when training. So I created a subfunction for preprocessing where I changed all values from 255 to 1.

class ChangeValues(Abstract_Subfunction):
   #---------------------------------------------#
   #                Initialization               #
   #---------------------------------------------#
  def __init__(self, val_to_change, change_in):
    self.val_to_change = val_to_change
    self.change_in = change_in
    #---------------------------------------------#
    #                Preprocessing                #
    #---------------------------------------------#
  def preprocessing(self, sample, training=True):
    seg_temp = sample.seg_data
    if(sample.seg_data is not None):
      sample.seg_data = np.where(seg_temp == self.val_to_change, self.change_in, seg_temp)
    #---------------------------------------------#
    #               Postprocessing                #
    #---------------------------------------------#
  def postprocessing(self, sample, prediction):
    pred = prediction
    if prediction is not None:
      prediction = np.where(pred == self.change_in, self.val_to_change, pred)
    return prediction

After that you have to call the function
sf_change = ChangeValues(val_to_change=255, change_in=1)
and pass sf_change with the other subfunctions you want to use to the Preprocessor.

I hope this solves your problem,
Leonie

@Qcatbot
Copy link
Author

Qcatbot commented Jul 23, 2021

Hi Muellerdo & Leonie,
I will modify according to your suggestions and get back here. Please dont close this discussion.
Thank you!

@hinatanvir
Copy link

hi @leonieburg ,
i have encountered the same error however i do not understand clearly how to apply the solution you have proposed. i know i have a label -> -1 is my images that is often treated as 255 , other than that i have 19 classes of interest from 0 to 18.
I use a preprocess function that converts label to-catgorical. this is where the problem is occuring. I cannot understand where to position this solution subfunction that you proposed.
error
preprocess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Development of MIScnn
  
Support/Bugs
Development

No branches or pull requests

4 participants