Args: target (dict): COCO target json annotation as a python dict height (int): height width (int): width Returns: a list containing lists of bounding boxes [bbox coords, class idx]
(self, target, width, height)
| 47 | self.label_map = get_label_map(osp.join(COCO_ROOT, 'coco_labels.txt')) |
| 48 | |
| 49 | def __call__(self, target, width, height): |
| 50 | """ |
| 51 | Args: |
| 52 | target (dict): COCO target json annotation as a python dict |
| 53 | height (int): height |
| 54 | width (int): width |
| 55 | Returns: |
| 56 | a list containing lists of bounding boxes [bbox coords, class idx] |
| 57 | """ |
| 58 | scale = np.array([width, height, width, height]) |
| 59 | res = [] |
| 60 | for obj in target: |
| 61 | if 'bbox' in obj: |
| 62 | bbox = obj['bbox'] |
| 63 | bbox[2] += bbox[0] |
| 64 | bbox[3] += bbox[1] |
| 65 | label_idx = self.label_map[obj['category_id']] - 1 |
| 66 | final_box = list(np.array(bbox)/scale) |
| 67 | final_box.append(label_idx) |
| 68 | res += [final_box] # [xmin, ymin, xmax, ymax, label_idx] |
| 69 | else: |
| 70 | print("no bbox problem!") |
| 71 | |
| 72 | return res # [[xmin, ymin, xmax, ymax, label_idx], ... ] |
| 73 | |
| 74 | |
| 75 | class COCODetection(data.Dataset): |
nothing calls this directly
no outgoing calls
no test coverage detected