Mask_rcnn: Exception: Invalid bounding box with area of zero

Created on 3 Dec 2017  路  10Comments  路  Source: matterport/Mask_RCNN

Problems happen when run the demo in train_shapes.ipynb.

When IMAGE_MAX_DIM = 128, the demo is OK.
But the warning happens when I set IMAGE_MAX_DIM = 1024.

Most helpful comment

masks = [m for m in masks if set(np.unique(m).flatten()) != {0}]

If there are only 0 values in the mask matrix than it's "useless", completely black.

All 10 comments

When training with the cityscapes dataset this also frequently happens.
The zero bounding boxes come from utils.py->extract_bboxes

# No mask for this instance. Might happen due to
# resizing or cropping. Set bbox to zeros
 x1, x2, y1, y2 = 0, 0, 0, 0

If the resulting exception is ignored, it will fail on many ends e.g.
y1y2 = np.random.randint(r_y1, r_y2, (rois_per_box * 2, 2)) because occasionally r_y1==r_y2
and in build_detection_targets.

@waleedka What is the disadvantage of not extracting such zero bounding boxes altogether?

@zhang-qiang-github have you found a solution to this problem ?! I am trying to train Mask RCNN on my own data and found that problem. by the way, my images dimensions are (1280 * 720)...
@jmtatsch do you have any suggestions to solve this issue?

I am having the same issue. Invalid bounding box with area of zero

Is there a solution for that?

I got this problem on my own dataset. In my case, I have some 'blank mask' with all '0' value. which would cause this error. I just double check my mask, and it works now.

I got same issue, but I checked my dataset, there is no blank masks.

Update: my assumption would be the resized masks contain blank masks. (need to confirm)

Just confirmed, some small masks are lost. Remove those masks, the issue is gone.

@NoahDragon how do you check which masks are lost? Manually or you added some code lines? I am guessing my mask become totally black when they are resized to mini mask. My two ideas are:
Change USE_MINI_MASK to False. But it is computational expensive.
Remove those masks as you mentioned. But my problem is how to efficiently find them.

masks = [m for m in masks if set(np.unique(m).flatten()) != {0}]

If there are only 0 values in the mask matrix than it's "useless", completely black.

I had the same issue and it's caused by bad mask/annotations as mentioned above. I'ts recomended to do a final check on your dataset to see if any data has made it past your sanity checkpoints. Easiest way to do that is to execute this right after your data generator

for i in range(len(dataset_training.image_ids)):
    print(i)
    _, _ = next(g)

You can also print the image ID by adding a print line in model.py inside load_image_gt. In my case I added

print(dataset.image_info[image_id]['annotations'][0]['id']) 

Once you find the offending image just remove it

masks = [m for m in masks if set(np.unique(m).flatten()) != {0}]

If there are only 0 values in the mask matrix than it's "useless", completely black.

This hack may also throw an error about list having no shape attribute (happened in my case).
If that happens, just add another line for conversion to numpy arrays:
mask = np.asarray(mask)

Was this page helpful?
0 / 5 - 0 ratings