Mask_rcnn: IndexError: boolean index did not match indexed array along dimension 0; dimension is 0 but corresponding boolean dimension is 20

Created on 7 Jun 2018  Â·  30Comments  Â·  Source: matterport/Mask_RCNN

(Conv2D)
rpn_class_raw          (Conv2D)
rpn_bbox_pred          (Conv2D)

mrcnn_mask_conv1 (TimeDistributed)
mrcnn_mask_bn1 (TimeDistributed)
mrcnn_mask_conv2 (TimeDistributed)
mrcnn_mask_bn2 (TimeDistributed)
mrcnn_class_conv1 (TimeDistributed)
mrcnn_class_bn1 (TimeDistributed)
mrcnn_mask_conv3 (TimeDistributed)
mrcnn_mask_bn3 (TimeDistributed)
mrcnn_class_conv2 (TimeDistributed)
mrcnn_class_bn2 (TimeDistributed)
mrcnn_mask_conv4 (TimeDistributed)
mrcnn_mask_bn4 (TimeDistributed)
mrcnn_bbox_fc (TimeDistributed)
mrcnn_mask_deconv (TimeDistributed)
mrcnn_class_logits (TimeDistributed)
mrcnn_mask (TimeDistributed)
/home/yu/.local/lib/python3.5/site-packages/tensorflow/python/ops/gradients_impl.py:96: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
/home/yu/.local/lib/python3.5/site-packages/keras/engine/training.py:2039: UserWarning: Using a generator with use_multiprocessing=True and multiple workers may duplicate your data. Please consider using thekeras.utils.Sequence class. UserWarning('Using a generator withuse_multiprocessing=True`'
image_id 2
image_id 2
image_id 0
image_id 2
image_id 1
image_id 2
image_id 1
image_id 2
image_id 0
image_id 0
image_id 1
image_id 2
image_id 2
image_id 2
image_id 0
image_id 1
image_id 1
image_id 2
image_id 2
image_id 1
image_id 1
image_id 2
image_id 1
image_id 0
image_id 0
image_id 1
image_id 0
image_id 2
image_id 0
image_id 0
image_id 2
image_id 2
image_id 2
image_id 2
image_id 2
image_id 2
Epoch 1/10
image_id 2
image_id 2
image_id 2
image_id 2
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
class_ids-----------> []
/home/yu/.local/lib/python3.5/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
ERROR:root:Error processing image {'height': 300, 'yaml_path': '/home/yu/Mask_RCNN/test/total/0_json/info.yaml', 'source': 'shapes', 'id': 0, 'width': 400, 'path': '/home/yu/Mask_RCNN/test/fish/0.jpg', 'mask_path': '/home/yu/Mask_RCNN/test/mask/0.png'}
Traceback (most recent call last):
File "/home/yu/Mask_RCNN/samples/shapes/model.py", line 1695, in data_generator
use_mini_mask=config.USE_MINI_MASK)
File "/home/yu/Mask_RCNN/samples/shapes/model.py", line 1263, in load_image_gt
class_ids = class_ids[_idx]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 0 but corresponding boolean dimension is 20

Most helpful comment

@zhongxing9006
Not sure if it solves the main issue but it does remove the following warning:
UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images. warn("Anti-aliasing will be enabled by default in skimage 0.15 to " class_ids----------->
Thanks for your suggestion.

Instructions for anyone looking to remove the aforementioned warning:

  1. $ pip uninstall scikit-image
  2. $ pip install scikit-image==0.13.1

All 30 comments

how to slove it? anybody help me ?Thanks!

Did you solve this?

You can try with scikit-image 0.13.1

@zhongxing9006
Not sure if it solves the main issue but it does remove the following warning:
UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images. warn("Anti-aliasing will be enabled by default in skimage 0.15 to " class_ids----------->
Thanks for your suggestion.

Instructions for anyone looking to remove the aforementioned warning:

  1. $ pip uninstall scikit-image
  2. $ pip install scikit-image==0.13.1

changing scikit-image version to 0.13.1 worked for me as well

could you tell me how to solve "class_ids = class_ids[_idx]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 0 but corresponding boolean dimension is 20"?

Thanks

@DeepWu have you solved it? I meet a same problem

Hello, I have the same problem. Does anyone know how to solve this ?

could you tell me how to solve "class_ids = class_ids[_idx]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 0 but corresponding boolean dimension is 20"?

Thanks

I met the same problem,did you find the solution?thank U

Have you solved it?

@DeepWu @jacnon @littleTaodog @ZengyuanYu Did anyone solve this issue?

In case anyone is having trouble with this (I'm not using this library, but I guess this solution works):

import warnings
# ignore warnings
...
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    # place your skimage.transform.resize here

I have solved this problem. I used

  • $ pip uninstall scikit-image
  • $ pip install scikit-image==0.13.1.

But it gave me ImportError: cannot import name '_validate_lengths'.

So I had to used

$ pip uninstall scikit-image
$ pip install scikit-image

or

pip install scikit-image --force-reinstall

@DeepWu @jacnon @littleTaodog @ZengyuanYu Did anyone solve this issue?

DO you guys solved this problem ?

Any solutions ? @qq4060

Any solutions ? @qq4060

my problem is that I didnt changge the label information so that the input image and masks are wrong .

hi @HAMZARaouia . my problem was with not correct the label in JSON file. i fixed it, and now - ok.
image

any body found solution please. IndexError: boolean index did not match indexed array along dimension 0; dimension is 2 but corresponding boolean dimension is 1

I have same problem, too.
Please someone help :(
~\Desktop\SpaceNet_MaskRCNN\mrcnn\model.py in load_image_gt(dataset, config, image_id, augment, augmentation, use_mini_mask)
1263 _idx = np.sum(mask, axis=(0, 1)) > 0
1264 mask = mask[:, :, _idx]
-> 1265 class_ids = class_ids[_idx]
1266 # Bounding boxes. Note that some boxes might be all zeros
1267 # if the corresponding mask got cropped out.

IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 650

@Mstfakts I think, this is a problem in labeling. What version of the label did u do?

Hello all,

I am not sure, but I think that I overcame the problem. In model.py - line 1274,
I only changed 'class_ids = class_ids[_idx]' to 'class_ids = class_ids[_idx[0]]'. Now, I can train my model without any problem. Please check my solution and let us know whether it works or not.

Thank you.

==========================================
Sorry all, it did not work well. I solved the problem. It was about labeling as everyone said before. My mistake was in 'def load_mask(self, image_id):' method. It should return [height, weight, number of instances], but it was returning [h,w,1].

@Mstfakts Thanks your sharing! I finally solve this issue. Everybody can follow this solution!

@Mstfakts Thanks your sharing! I finally solve this issue. Everybody can follow this solution!

Which part?
In model.py line 1274 or with load mask method. can You please share the code snippet with me?

@Mstfakts Thanks your sharing! I finally solve this issue. Everybody can follow this solution!

Which part?
In model.py line 1274 or with load mask method. can You please share the code snippet with me?

@Akash481 Yes! I only changed 'class_ids = class_ids[_idx]' to 'class_ids = class_ids[_idx[0]] in model.py file, ''the problem'' will be solved.

Do u also meet this error? Actually, I also changed some detail code in load_image and load_mask function.

Yes I also encountered this error. I am working on a face dataset which
have two classes (eye and mouth). But when I am training, it goes like
epoch 1/20 and then throw a bunch of filenames and says : filenotfound
error. I am currently resolving this issue.

Did your training started? Can you also send me your codes for reference if
you are working on similar class problems.
Thank you very much.

On Fri, 24 Apr, 2020, 1:07 pm 0922james0922, notifications@github.com
wrote:

@Mstfakts https://github.com/Mstfakts Thanks your sharing! I finally
solve this issue. Everybody can follow this solution!

Which part?
In model.py line 1274 or with load mask method. can You please share the
code snippet with me?

@Akash481 https://github.com/Akash481 Yes! I only changed 'class_ids =
class_ids[_idx]' to 'class_ids = class_ids[_idx[0]] in model.py file, ''the
problem'' will be solved.

Do u also meet this error? Actually, I also changed some detail code in
load_image and load_mask function.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/matterport/Mask_RCNN/issues/655#issuecomment-618855882,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AK3JT36QJTHB6DJEFPHEWRTROE6VBANCNFSM4FDZ4ERQ
.

I have tried all the above solutions and none of them has worked for me.
I have even checked my labels and I don't think thats the problem in my case.

This is what i get:

ERROR:root:Error processing image {'id': 'M34088', 'source': 'dataset', 'path': 'dataset/images/M34088.jpg', 'annotation': 'dataset/annots/M34088.xml'} Traceback (most recent call last): File "/home/parth/Development/minor_project/Mask_RCNN/mrcnn/model.py", line 1709, in data_generator use_mini_mask=config.USE_MINI_MASK) File "/home/parth/Development/minor_project/Mask_RCNN/mrcnn/model.py", line 1265, in load_image_gt class_ids = class_ids[_idx] IndexError: boolean index did not match indexed array along dimension 0; dimension is 198 but corresponding boolean dimension is 11

Please help!!

Are you modifying the baloon.py file for your use? If your answer is yes, then as per my knowledge you should not give ".XML" file . You have to give all annotations to a single ".json" file as annotation. On top of that, you should use via software (I used via-1.0.6) for annotation. I encountered same type of error for my dataset, then I ultimately stopped as I couldn't find any solution.
Try below steps if you cannot find solution
•You annotate 5 files for training and 5 for testing in by annotating in via software and try to train it.
•While annotating, don't write class name just add class numbers in software.
• Add class name in face.py
DON"T ANNOTATE ALL FILES UNTIL TRAINING STARTS
I referred this link, his Github repo can be found in the comment section
https://www.linkedin.com/pulse/mask-rcnn-custom-data-set-idly-vada-dosa-abhilash-reddy-yerasi/
I am attaching a file for my dataset, modify it as per your use(Rename it to face.py).
face.pdf
I hope it helps.

Good Luck!!

Thanks @Akash481 Your steps really helped me a lot, I found the mistake I was making while loading masks. I had 18 classes in my project and I was appending all the classes in the class_ids list and that to in a loop.

Now I am appending only the classes used in that particular Image whose mask I need to load, and Its working fine.

Updated Code

image

This question on StackOverflow also helped me rectify my error.

Thanks @Akash481 Your steps really helped me a lot, I found the mistake I was making while loading masks. I had 18 classes in my project and I was appending all the classes in the class_ids list and that to in a loop.

Now I am appending only the classes used in that particular Image whose mask I need to load, and Its working fine.

Updated Code

image

This question on StackOverflow also helped me rectify my error.

Hey @parth_singh71 can you provide the code structure for the multi class Mask RCNN problem? I am getting a lot errors in my code.

Hey as others have mentioned, with the newer numpy versions, using incorrect sizes is now not tolerated. Although not a fix for the underlying issue, I was able to get the code running and training by simply just re-assigning the _idx as the correct length of class ids coming in and converting them into numpy boolean types as such. This is in model.py on line 1263. Hope this helps.

_idx = np.sum(mask, axis=(0, 1)) > 0
_idx_ = np.ones(len(class_ids)).astype(np.bool) # To match the input class id array with the expected boolean array
mask = mask[:, :, _idx]
class_ids = class_ids[_idx_]
# Bounding boxes. Note that some boxes might be all zeros
# if the corresponding mask got cropped out.
# bbox: [num_instances, (y1, x1, y2, x2)]
bbox = utils.extract_bboxes(mask)

Was this page helpful?
0 / 5 - 0 ratings