Evaluate coco keypoint results. The pose prediction results will be saved in `${res_folder}/result_keypoints.json`. Note: batch_size: N num_keypoints: K heatmap height: H heatmap width: W Args: outputs (list(dict))
(self)
| 158 | # note: sync if multi-gpu |
| 159 | |
| 160 | def evaluate(self): |
| 161 | """Evaluate coco keypoint results. The pose prediction results will be |
| 162 | saved in `${res_folder}/result_keypoints.json`. |
| 163 | |
| 164 | Note: |
| 165 | batch_size: N |
| 166 | num_keypoints: K |
| 167 | heatmap height: H |
| 168 | heatmap width: W |
| 169 | |
| 170 | Args: |
| 171 | outputs (list(dict)) |
| 172 | :preds (np.ndarray[N,K,3]): The first two dimensions are |
| 173 | coordinates, score is the third dimension of the array. |
| 174 | :boxes (np.ndarray[N,6]): [center[0], center[1], scale[0] |
| 175 | , scale[1],area, score] |
| 176 | :image_paths (list[str]): For example, ['data/coco/val2017 |
| 177 | /000000393226.jpg'] |
| 178 | :heatmap (np.ndarray[N, K, H, W]): model output heatmap |
| 179 | :bbox_id (list(int)). |
| 180 | res_folder (str): Path of directory to save the results. |
| 181 | metric (str | list[str]): Metric to be performed. Defaults: 'mAP'. |
| 182 | |
| 183 | Returns: |
| 184 | dict: Evaluation results for evaluation metric. |
| 185 | """ |
| 186 | metrics = self.metric if isinstance(self.metric, list) else [self.metric] |
| 187 | allowed_metrics = ['mAP'] |
| 188 | for metric in metrics: |
| 189 | if metric not in allowed_metrics: |
| 190 | raise KeyError(f'metric {metric} is not supported') |
| 191 | |
| 192 | assert self._output_dir |
| 193 | |
| 194 | os.makedirs(self._output_dir, exist_ok=True) |
| 195 | res_file = os.path.join(self._output_dir, f'result_keypoints-{time.time()}.json') |
| 196 | |
| 197 | kpts = defaultdict(list) |
| 198 | |
| 199 | for output in self.results: |
| 200 | preds = output['preds'] |
| 201 | boxes = output['boxes'] |
| 202 | image_paths = output['image_paths'] |
| 203 | bbox_ids = output['bbox_ids'] |
| 204 | |
| 205 | batch_size = len(image_paths) |
| 206 | for i in range(batch_size): |
| 207 | image_id = self.dataset.name2id[image_paths[i][len(self.dataset.img_prefix):]] |
| 208 | img_dict = { |
| 209 | 'keypoints': preds[i], |
| 210 | 'center': boxes[i][0:2], |
| 211 | 'scale': boxes[i][2:4], |
| 212 | 'area': boxes[i][4], |
| 213 | 'score': boxes[i][5], |
| 214 | 'image_id': image_id, |
| 215 | 'bbox_id': bbox_ids[i], } |
| 216 | if 'pred_logits' in output: |
| 217 | img_dict['pred_logits']=output['pred_logits'][i] |
no test coverage detected