Constructor of Microsoft COCO helper class for reading and visualizing annotations. :param annotation_file (str): location of annotation file :param image_folder (str): location to the folder that hosts images. :return:
(self, annotation_file=None, test_index=None, ann_data=None)
| 27 | |
| 28 | class PetrelCOCO(COCO): |
| 29 | def __init__(self, annotation_file=None, test_index=None, ann_data=None): |
| 30 | """ |
| 31 | Constructor of Microsoft COCO helper class for reading and visualizing annotations. |
| 32 | :param annotation_file (str): location of annotation file |
| 33 | :param image_folder (str): location to the folder that hosts images. |
| 34 | :return: |
| 35 | """ |
| 36 | self.dataset,self.anns,self.cats,self.imgs = dict(),dict(),dict(),dict() |
| 37 | self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list) |
| 38 | self.anno_file = [annotation_file] |
| 39 | self.test_index = test_index |
| 40 | if not annotation_file == None: |
| 41 | print('loading annotations into memory...') |
| 42 | tic = time.time() |
| 43 | # https://github.com/cocodataset/cocoapi/pull/453/ |
| 44 | if ann_data == None: |
| 45 | dataset = PetrelHelper.load_json(annotation_file) |
| 46 | else: |
| 47 | dataset = ann_data |
| 48 | assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset)) |
| 49 | print('Done (t={:0.2f}s)'.format(time.time()- tic)) |
| 50 | self.dataset = dataset |
| 51 | self.createIndex() |
| 52 | if 'annotations' in self.dataset: |
| 53 | for i in range(len(self.dataset['annotations'])): |
| 54 | if self.test_index is not None: |
| 55 | keypoints = np.array(self.dataset['annotations'][i]['keypoints']).reshape([-1, 3]) |
| 56 | keypoints = keypoints[self.test_index, :] |
| 57 | self.dataset['annotations'][i]['keypoints'] = keypoints.reshape([-1]).tolist() |
| 58 | if 'iscrowd' not in self.dataset['annotations'][i]: |
| 59 | self.dataset['annotations'][i]['iscrowd'] = False |
| 60 | |
| 61 | class COCOPosDatasetDev(Dataset): |
| 62 | def __init__(self, |
nothing calls this directly
no outgoing calls
no test coverage detected