matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.68k stars 11.7k forks source link

all_points_y error when training or generating data #503

Open mia2mia opened 6 years ago

mia2mia commented 6 years ago

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

chohaku84 commented 6 years ago

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.

jmarrr commented 6 years ago

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

chohaku84 commented 6 years ago

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.

mia2mia commented 6 years ago

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

Oktai15 commented 6 years ago

@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?

chohaku84 commented 6 years ago

@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".

daoud commented 6 years ago

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

aakashkodes commented 6 years ago

@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.

naresh-nishad commented 6 years ago

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

janvib27 commented 5 years ago

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