Get keypoint predictions from score maps. Note: batch_size: N num_keypoints: K heatmap height: H heatmap width: W Args: heatmaps (np.ndarray[N, K, H, W]): model predicted heatmaps. Returns: tuple: A tuple containing aggregated results.
(heatmaps)
| 372 | |
| 373 | |
| 374 | def _get_max_preds(heatmaps): |
| 375 | """Get keypoint predictions from score maps. |
| 376 | |
| 377 | Note: |
| 378 | batch_size: N |
| 379 | num_keypoints: K |
| 380 | heatmap height: H |
| 381 | heatmap width: W |
| 382 | |
| 383 | Args: |
| 384 | heatmaps (np.ndarray[N, K, H, W]): model predicted heatmaps. |
| 385 | |
| 386 | Returns: |
| 387 | tuple: A tuple containing aggregated results. |
| 388 | |
| 389 | - preds (np.ndarray[N, K, 2]): Predicted keypoint location. |
| 390 | - maxvals (np.ndarray[N, K, 1]): Scores (confidence) of the keypoints. |
| 391 | """ |
| 392 | assert isinstance(heatmaps, np.ndarray), "heatmaps should be numpy.ndarray" |
| 393 | assert heatmaps.ndim == 4, "batch_images should be 4-ndim" |
| 394 | |
| 395 | N, K, _, W = heatmaps.shape |
| 396 | heatmaps_reshaped = heatmaps.reshape((N, K, -1)) |
| 397 | idx = np.argmax(heatmaps_reshaped, 2).reshape((N, K, 1)) |
| 398 | maxvals = np.amax(heatmaps_reshaped, 2).reshape((N, K, 1)) |
| 399 | |
| 400 | preds = np.tile(idx, (1, 1, 2)).astype(np.float32) |
| 401 | preds[:, :, 0] = preds[:, :, 0] % W |
| 402 | preds[:, :, 1] = preds[:, :, 1] // W |
| 403 | |
| 404 | preds = np.where(np.tile(maxvals, (1, 1, 2)) > 0.0, preds, -1) |
| 405 | return preds, maxvals |
| 406 | |
| 407 | |
| 408 | def _get_max_preds_3d(heatmaps): |
no outgoing calls
no test coverage detected