def _add_gt_annotations(self, entry): """Add ground truth annotation metadata to an roidb entry.""" count = 0 #for k in self.category_to_id_map: # imgs = self.COCO.getImgIds(catIds=(self.category_to_id_map[k])) # count += len(imgs) ann_ids = self.COCO.getAnnIds(imgIds=entry['id'], iscrowd=None) objs = self.COCO.loadAnns(ann_ids) # Sanitize bboxes -- some are invalid valid_objs = [] valid_segms = [] width = entry['width'] height = entry['height'] for obj in objs: if isinstance(obj['segmentation'], list): # Valid polygons have >= 3 points, so require >= 6 coordinates obj['segmentation'] = [ p for p in obj['segmentation'] if len(p) >= 6 ] if obj['area'] < cfg.TRAIN.gt_min_area: continue if 'ignore' in obj and obj['ignore'] == 1: continue # Convert form (x1, y1, w, h) to (x1, y1, x2, y2) x1, y1, x2, y2 = box_utils.xywh_to_xyxy(obj['bbox']) x1, y1, x2, y2 = box_utils.clip_xyxy_to_image( x1, y1, x2, y2, height, width) # Require non-zero seg area and more than 1x1 box size if obj['area'] > 0 and x2 > x1 and y2 > y1: obj['clean_bbox'] = [x1, y1, x2, y2] valid_objs.append(obj) valid_segms.append(obj['segmentation']) num_valid_objs = len(valid_objs) gt_boxes = np.zeros((num_valid_objs, 4), dtype=entry['gt_boxes'].dtype) gt_id = np.zeros((num_valid_objs), dtype=np.int32) gt_classes = np.zeros((num_valid_objs), dtype=entry['gt_classes'].dtype) is_crowd = np.zeros((num_valid_objs), dtype=entry['is_crowd'].dtype) for ix, obj in enumerate(valid_objs): cls = self.json_category_id_to_contiguous_id[obj['category_id']] gt_boxes[ix, :] = obj['clean_bbox'] gt_classes[ix] = cls gt_id[ix] = np.int32(obj['id']) is_crowd[ix] = obj['iscrowd'] entry['gt_boxes'] = np.append(entry['gt_boxes'], gt_boxes, axis=0) entry['gt_classes'] = np.append(entry['gt_classes'], gt_classes) entry['gt_id'] = np.append(entry['gt_id'], gt_id) entry['is_crowd'] = np.append(entry['is_crowd'], is_crowd) entry['segms'].extend(valid_segms)
def _add_gt_annotations(self, entry): """Add ground truth annotation metadata to an roidb entry""" ann_ids = self.COCO.getAnnIds(imgIds=entry['id'], iscrowd=None) objs = self.COCO.loadAnns(ann_ids) valid_objs = [] width = entry['width'] height = entry['height'] for obj in objs: if obj['area'] < cfg.TRAIN.gt_min_area: continue if 'ignore' in obj and obj['ignore'] == 1: continue x1, y1, x2, y2 = box_utils.xywh_to_xyxy(obj['bbox']) x1, y1, x2, y2 = box_utils.clip_xyxy_to_image( x1, y1, x2, y2, height, width) # require non-zero seg area and more than 1x1 box size if obj['area'] > 0 and x2 > x1 and y2 > y1: obj['clean_bbox'] = [x1, y1, x2, y2] valid_objs.append(obj) num_valid_objs = len(valid_objs) gt_boxes = np.zeros((num_valid_objs, 4), dtype=entry['gt_boxes'].dtype) gt_id = np.zeros((num_valid_objs), dtype=np.int64) gt_classes = np.zeros((num_valid_objs), dtype=entry['gt_classes'].dtype) is_crowd = np.zeros((num_valid_objs), dtype=entry['is_crowd'].dtype) for ix, obj in enumerate(valid_objs): cls = self.json_category_id_to_contiguous_id[obj['category_id']] gt_boxes[ix, :] = obj['clean_bbox'] gt_classes[ix] = cls gt_id[ix] = np.int64(obj['id']) is_crowd[ix] = obj['iscrowd'] entry['gt_boxes'] = np.append(entry['gt_boxes'], gt_boxes, axis=0) entry['gt_classes'] = np.append(entry['gt_classes'], gt_classes) entry['gt_id'] = np.append(entry['gt_id'], gt_id) entry['is_crowd'] = np.append(entry['is_crowd'], is_crowd)