Args: add_gt: whether to add ground truth bounding box annotations to the dicts add_mask: whether to also add ground truth mask Returns: a list of dict, each has keys including: 'image_id', 'file_name', and (if add
(self, add_gt=True, add_mask=False)
| 91 | return ret |
| 92 | |
| 93 | def load(self, add_gt=True, add_mask=False): |
| 94 | """ |
| 95 | Args: |
| 96 | add_gt: whether to add ground truth bounding box annotations to the dicts |
| 97 | add_mask: whether to also add ground truth mask |
| 98 | |
| 99 | Returns: |
| 100 | a list of dict, each has keys including: |
| 101 | 'image_id', 'file_name', |
| 102 | and (if add_gt is True) 'boxes', 'class', 'is_crowd', and optionally |
| 103 | 'segmentation'. |
| 104 | """ |
| 105 | with timed_operation('Load annotations for {}'.format( |
| 106 | os.path.basename(self.annotation_file))): |
| 107 | img_ids = self.coco.getImgIds() |
| 108 | img_ids.sort() |
| 109 | # list of dict, each has keys: height,width,id,file_name |
| 110 | imgs = self.coco.loadImgs(img_ids) |
| 111 | |
| 112 | for idx, img in enumerate(tqdm.tqdm(imgs)): |
| 113 | img['image_id'] = img.pop('id') |
| 114 | img['file_name'] = os.path.join(self._imgdir, img['file_name']) |
| 115 | if idx == 0: |
| 116 | # make sure the directories are correctly set |
| 117 | assert os.path.isfile(img["file_name"]), img["file_name"] |
| 118 | if add_gt: |
| 119 | self._add_detection_gt(img, add_mask) |
| 120 | return imgs |
| 121 | |
| 122 | def _add_detection_gt(self, img, add_mask): |
| 123 | """ |
no test coverage detected