Mask_rcnn: all_points_y error when training or generating data

Created on 30 Apr 2018  路  10Comments  路  Source: matterport/Mask_RCNN

I am trying to train Mask RCNN on my own data but I get the errors below when training or loading the mini mask or using the modellib.data_generator.

Anyone else had this problem?

ERROR:root:Error processing image {'id': 'location-494-270.jpg', 'source': 'flowers', 'path': '/home/ubuntu/ssl/notebooks/Mask_RCNN/Mask_RCNN/datasets/flowers/train/file2.jpg', 'width': 640, 'height': 400, 'polygons': [{'name': 'rect', 'x': 301, 'y': 178, 'width': 40, 'height': 93}]}
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 1692, in data_generator
use_mini_mask=config.USE_MINI_MASK)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 1207, in load_image_gt
mask, class_ids = dataset.load_mask(image_id)
File "flowers.py", line 158, in load_mask
rr, cc = skimage.draw.polygon(p['all_points_y'], p['all_points_x'])
KeyError: 'all_points_y'Epoch 1/30

Most helpful comment

I suggest you just simply replace all of the rectangles with polygons using VIA tools for example.

Or you can try to modify the via_region_data.json file, replace the "x" and "y" with "all_points_x" and "all_points_y"(and you need to calculate the x[1] and y[1] with "width" and "height") in the file, remove the "width" and "height"(add them into x[1] and y[1]), then change the "name" from rect to polygon.

All 10 comments

Hi, there.
Maybe it's because of you annotated your training images with rectangles but not polygons? Check the region_data.json which the annotation tools produced, you will find out there is no "all_points_y" for rectangles. The sample in this repo is using polygons for annotations, "skimage.draw.polygon" said.

I am having this problem too, I have rectangles and polygons on my annotations. How can I solve this problem?

I suggest you just simply replace all of the rectangles with polygons using VIA tools for example.

Or you can try to modify the via_region_data.json file, replace the "x" and "y" with "all_points_x" and "all_points_y"(and you need to calculate the x[1] and y[1] with "width" and "height") in the file, remove the "width" and "height"(add them into x[1] and y[1]), then change the "name" from rect to polygon.

Yes @chohaku84 replacing all rectangles with polygons removed the error.

@chohaku84 why all_points_y stand the first rather than all_points_x? And also:
height, width = image.shape[:2]
Width should be first, isnt it?

@mia2mia I'm glad it helped.
@Oktai15 In the region_data.json VIA tools produced, there are points_x stands before points_y, as same as width stands before height for rectangle objects.
While skimage.draw API defines the first param to be "row coordinates" ndarray and the second param to be "column coordinates" ndarray.
So in this case, 'all_points_y' for row coordinates, 'all_points_x' for column coordinates are passed into "skimage.draw.polygon".

I am working on Mask R-CNN, I am training images. I have 1 + 1 class.In my JSON I have 2 shape: 'rect ' and 'polygon'. My not working when I added 'rect' also on same data set. Let how to handle the different shapes. My program only works with polygon shapes

@chohaku84 I have circles and rectangles in my json instead of polygons.
From the previous comments, converting rect to polygon is possible.
But what do you do when you have circle. In circle it has cx, cy , r.

I am also have the same problem @chohaku84 did you find any solution for that.

Hey, I am getting the same error even after changing all annotations to polygon. My code trains fine for first 100 iterations in first epoch and then it shows the following error:
Traceback (most recent call last):
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(args, *kwds))
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/utils/data_utils.py", line 626, in next_sample
return six.next(_SHARED_SEQUENCES[uid])
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 1710, in data_generator
use_mini_mask=config.USE_MINI_MASK)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 1213, in load_image_gt
mask, class_ids = dataset.load_mask(image_id)
File "cancer.py", line 173, in load_mask
rr, cc = skimage.draw.polygon(p['all_points_y'], p['all_points_x'])
KeyError: 'all_points_y'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "cancer.py", line 533, in
train(model)
File "cancer.py", line 259, in train
layers='heads')
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/mask_rcnn-2.1-py3.6.egg/mrcnn/model.py", line 2375, in train
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(args, *kwargs)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/engine/training.py", line 1418, in fit_generator
initial_epoch=initial_epoch)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/engine/training_generator.py", line 234, in fit_generator
workers=0)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(args, *kwargs)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/engine/training.py", line 1472, in evaluate_generator
verbose=verbose)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/engine/training_generator.py", line 330, in evaluate_generator
generator_output = next(output_generator)
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/utils/data_utils.py", line 709, in get
six.reraise(*sys.exc_info())
File "/home/dipesh/.local/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/keras/utils/data_utils.py", line 685, in get
inputs = self.queue.get(block=True).get()
File "/home/dipesh/anaconda3/envs/maskrcnn/lib/python3.6/multiprocessing/pool.py", line 670, in get
raise self._value
KeyError: 'all_points_y'

Using Linux 18.04
Python 3.7.0

Was this page helpful?
0 / 5 - 0 ratings