def visualize_top_predicted_bbox(self, pred_sample, coco_image_dir):
   """Visualize the top predicted bounding box."""
   assert 'annotation_id' in pred_sample, 'Object annotation id missing!'
   assert 'predicted_bounding_boxes' in pred_sample, \
          'list of predicted bounding boxes missing!'
   if not pred_sample['predicted_bounding_boxes']:
     print 'Empty predicted bounding boxes.'
     return
     
   bbox_pred_top = pred_sample['predicted_bounding_boxes'][0]
   ann_id = pred_sample['annotation_id']
   ann = self.refexp_dataset.loadAnns(ids=[ann_id])[0]
   image_id = ann['image_id']
   img_coco = self.refexp_dataset.loadImgs(ids=[image_id])[0]
   iou = cu.iou_bboxes(bbox_pred_top, ann['bbox'])
   
   if 'refexp' in pred_sample or 'refexp_id' in pred_sample:
     print 'The Referring expression input to the model is:'
     if 'refexp' in pred_sample:
       print '  ' + pred_sample['refexp']
     else:
       refexp_tmp = self.refexp_dataset.loadRefexps(ids=pred_sample['refexp_id'])[0]
       print '  ' + refexp_tmp['raw']
   
   I = misc.imread(os.path.join(coco_image_dir, (img_coco['file_name'])))
   ax = plt.imshow(I)
   ax = plt.axis('off')
   ax = plt.title('IoU: %.3f, green bbox: GT, red bbox: predicted' % iou)
   cu.draw_bbox(plt.gca(), ann['bbox'], edge_color='green')
   cu.draw_bbox(plt.gca(), bbox_pred_top, edge_color='red')
Пример #2
0
    def visualize_top_predicted_bbox(self, pred_sample, coco_image_dir):
        """Visualize the top predicted bounding box."""
        assert 'annotation_id' in pred_sample, 'Object annotation id missing!'
        assert 'predicted_bounding_boxes' in pred_sample, \
               'list of predicted bounding boxes missing!'
        if not pred_sample['predicted_bounding_boxes']:
            print 'Empty predicted bounding boxes.'
            return

        bbox_pred_top = pred_sample['predicted_bounding_boxes'][0]
        ann_id = pred_sample['annotation_id']
        ann = self.refexp_dataset.loadAnns(ids=[ann_id])[0]
        image_id = ann['image_id']
        img_coco = self.refexp_dataset.loadImgs(ids=[image_id])[0]
        iou = cu.iou_bboxes(bbox_pred_top, ann['bbox'])

        if 'refexp' in pred_sample or 'refexp_id' in pred_sample:
            print 'The Referring expression input to the model is:'
            if 'refexp' in pred_sample:
                print '  ' + pred_sample['refexp']
            else:
                refexp_tmp = self.refexp_dataset.loadRefexps(
                    ids=pred_sample['refexp_id'])[0]
                print '  ' + refexp_tmp['raw']

        I = misc.imread(os.path.join(coco_image_dir, (img_coco['file_name'])))
        ax = plt.imshow(I)
        ax = plt.axis('off')
        ax = plt.title('IoU: %.3f, green bbox: GT, red bbox: predicted' % iou)
        cu.draw_bbox(plt.gca(), ann['bbox'], edge_color='green')
        cu.draw_bbox(plt.gca(), bbox_pred_top, edge_color='red')
Пример #3
0
    def showRegionCandidates(self, image, ax=None):
        """
        Display the region candidates for the given image.
        :param imgId (int): image id for which we display region candidates
        :param ax: matplotlib axes to draw on, or if unspecified, the current axis from `plt.gca()`
        :return: None
        """
        import matplotlib.pyplot as plt
        if ax is None:
            ax = plt.gca()

        candidates = image['region_candidates']
        for candidate in candidates:
            bbox = candidate['bounding_box']
            draw_bbox(ax, bbox, edge_color='blue')
    def showRegionCandidates(self, image, ax=None):
        """
        Display the region candidates for the given image.
        :param imgId (int): image id for which we display region candidates
        :param ax: matplotlib axes to draw on, or if unspecified, the current axis from `plt.gca()`
        :return: None
        """
        import matplotlib.pyplot as plt
        if ax is None:
            ax = plt.gca()

        candidates = image['region_candidates']
        for candidate in candidates:
            bbox = candidate['bounding_box']
            draw_bbox(ax, bbox, edge_color='blue')
Пример #5
0
 def showAnn(self, ann, ax=None, printRefexps=True):
     """
     Display the bbox and referring expressions of the given annotation.
     For segmentation display refer to COCO toolkit.
     :param anns (array of object): annotations to display
     :return: None
     """
     import matplotlib.pyplot as plt
     if ax is None:
         ax = plt.gca()
     bbox = ann['bbox']
     draw_bbox(ax, bbox, edge_color='green')
     if printRefexps:
         print('Referring expressions for the object in the bounding box: ')
         for ref_id in ann['refexp_ids']:
             print(self.dataset['refexps'][ref_id]['raw'])
 def showAnn(self, ann, ax=None, printRefexps=True):
     """
     Display the bbox and referring expressions of the given annotation.
     For segmentation display refer to COCO toolkit.
     :param anns (array of object): annotations to display
     :return: None
     """
     import matplotlib.pyplot as plt
     if ax is None:
         ax = plt.gca()
     bbox = ann['bbox']
     draw_bbox(ax, bbox, edge_color='green')
     if printRefexps:
         print('Referring expressions for the object in the bounding box: ')
         for ref_id in ann['refexp_ids']:
             print(self.dataset['refexps'][ref_id]['raw'])