(self, idx: int)
| 96 | return gt_instances |
| 97 | |
| 98 | def _pre_single_frame(self, idx: int): |
| 99 | img_path = self.img_files[idx] |
| 100 | label_path = self.label_files[idx] |
| 101 | if 'crowdhuman' in img_path: |
| 102 | img_path = img_path.replace('.jpg', '.png') |
| 103 | img = Image.open(img_path) |
| 104 | targets = {} |
| 105 | w, h = img._size |
| 106 | assert w > 0 and h > 0, "invalid image {} with shape {} {}".format(img_path, w, h) |
| 107 | if osp.isfile(label_path): |
| 108 | labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 6) |
| 109 | |
| 110 | # normalized cewh to pixel xyxy format |
| 111 | labels = labels0.copy() |
| 112 | labels[:, 2] = w * (labels0[:, 2] - labels0[:, 4] / 2) |
| 113 | labels[:, 3] = h * (labels0[:, 3] - labels0[:, 5] / 2) |
| 114 | labels[:, 4] = w * (labels0[:, 2] + labels0[:, 4] / 2) |
| 115 | labels[:, 5] = h * (labels0[:, 3] + labels0[:, 5] / 2) |
| 116 | else: |
| 117 | raise ValueError('invalid label path: {}'.format(label_path)) |
| 118 | video_name = '/'.join(label_path.split('/')[:-1]) |
| 119 | obj_idx_offset = self.video_dict[video_name] * 1000000 # 1000000 unique ids is enough for a video. |
| 120 | if 'crowdhuman' in img_path: |
| 121 | targets['dataset'] = 'CrowdHuman' |
| 122 | elif 'MOT17' in img_path: |
| 123 | targets['dataset'] = 'MOT17' |
| 124 | else: |
| 125 | raise NotImplementedError() |
| 126 | targets['boxes'] = [] |
| 127 | targets['area'] = [] |
| 128 | targets['iscrowd'] = [] |
| 129 | targets['labels'] = [] |
| 130 | targets['obj_ids'] = [] |
| 131 | targets['image_id'] = torch.as_tensor(idx) |
| 132 | targets['size'] = torch.as_tensor([h, w]) |
| 133 | targets['orig_size'] = torch.as_tensor([h, w]) |
| 134 | for label in labels: |
| 135 | targets['boxes'].append(label[2:6].tolist()) |
| 136 | targets['area'].append(label[4] * label[5]) |
| 137 | targets['iscrowd'].append(0) |
| 138 | targets['labels'].append(0) |
| 139 | obj_id = label[1] + obj_idx_offset if label[1] >= 0 else label[1] |
| 140 | targets['obj_ids'].append(obj_id) # relative id |
| 141 | |
| 142 | targets['area'] = torch.as_tensor(targets['area']) |
| 143 | targets['iscrowd'] = torch.as_tensor(targets['iscrowd']) |
| 144 | targets['labels'] = torch.as_tensor(targets['labels']) |
| 145 | targets['obj_ids'] = torch.as_tensor(targets['obj_ids']) |
| 146 | targets['boxes'] = torch.as_tensor(targets['boxes'], dtype=torch.float32).reshape(-1, 4) |
| 147 | # targets['boxes'][:, 0::2].clamp_(min=0, max=w) |
| 148 | # targets['boxes'][:, 1::2].clamp_(min=0, max=h) |
| 149 | return img, targets |
| 150 | |
| 151 | def _get_sample_range(self, start_idx): |
| 152 |
no outgoing calls
no test coverage detected