matterport / Mask_RCNN

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

UnboundLocalError: local variable 'fig' referenced before assignment #950

Open eyildiz-ugoe opened 6 years ago

eyildiz-ugoe commented 6 years ago

When you run detection using this code:

image_id = random.choice(dataset.image_ids)
image, image_meta, gt_class_id, gt_bbox, gt_mask =\
    modellib.load_image_gt(dataset, config, image_id, use_mini_mask=False)
info = dataset.image_info[image_id]
print("image ID: {}.{} ({}) {}".format(info["source"], info["id"], image_id, 
                                       dataset.image_reference(image_id)))

# Run object detection
results = model.detect([image], verbose=1)

# Display results
ax = get_ax(1)
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                            dataset.class_names, r['scores'], ax=ax,
                            title="Predictions")
log("gt_class_id", gt_class_id)
log("gt_bbox", gt_bbox)
log("gt_mask", gt_mask)

you face:

UnboundLocalError                         Traceback (most recent call last)
<ipython-input-10-f4f7bfabe883> in <module>()
     13 visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
     14                             dataset.class_names, r['scores'], ax=ax,
---> 15                             title="Predictions")
     16 log("gt_class_id", gt_class_id)
     17 log("gt_bbox", gt_bbox)

/usr/local/lib/python3.5/dist-packages/mask_rcnn-2.1-py3.5.egg/mrcnn/visualize.py in display_instances(image, boxes, masks, class_ids, class_names, scores, title, figsize, ax, show_mask, show_bbox, colors, captions, making_video, making_image, detect, hc, real_time)
    187         return canvas
    188     # To transform the drawn figure into ndarray X
--> 189     fig.canvas.draw()
    190     X = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
    191     X = X.reshape(fig.canvas.get_width_height()[::-1] + (3,))

UnboundLocalError: local variable 'fig' referenced before assignment

Although it does visualize an image (not sure if this is supposed to be the image though) but nevertheless the error is there.

Any thoughts for a fix?

waleedka commented 5 years ago

The code where the error is reported is not from this repo. Maybe you're using a different repo?