DARK post-pocessing. Implemented by udp. Paper ref: Huang et al. The Devil is in the Details: Delving into Unbiased Data Processing for Human Pose Estimation (CVPR 2020). Zhang et al. Distribution-Aware Coordinate Representation for Human Pose Estimation (CVPR 2020). Note: -
(coords, batch_heatmaps, kernel=3)
| 635 | |
| 636 | |
| 637 | def post_dark_udp(coords, batch_heatmaps, kernel=3): |
| 638 | """DARK post-pocessing. Implemented by udp. Paper ref: Huang et al. The |
| 639 | Devil is in the Details: Delving into Unbiased Data Processing for Human |
| 640 | Pose Estimation (CVPR 2020). Zhang et al. Distribution-Aware Coordinate |
| 641 | Representation for Human Pose Estimation (CVPR 2020). |
| 642 | |
| 643 | Note: |
| 644 | - batch size: B |
| 645 | - num keypoints: K |
| 646 | - num persons: N |
| 647 | - height of heatmaps: H |
| 648 | - width of heatmaps: W |
| 649 | |
| 650 | B=1 for bottom_up paradigm where all persons share the same heatmap. |
| 651 | B=N for top_down paradigm where each person has its own heatmaps. |
| 652 | |
| 653 | Args: |
| 654 | coords (np.ndarray[N, K, 2]): Initial coordinates of human pose. |
| 655 | batch_heatmaps (np.ndarray[B, K, H, W]): batch_heatmaps |
| 656 | kernel (int): Gaussian kernel size (K) for modulation. |
| 657 | |
| 658 | Returns: |
| 659 | np.ndarray([N, K, 2]): Refined coordinates. |
| 660 | """ |
| 661 | if not isinstance(batch_heatmaps, np.ndarray): |
| 662 | batch_heatmaps = batch_heatmaps.cpu().numpy() |
| 663 | B, K, H, W = batch_heatmaps.shape |
| 664 | N = coords.shape[0] |
| 665 | assert B == 1 or B == N |
| 666 | for heatmaps in batch_heatmaps: |
| 667 | for heatmap in heatmaps: |
| 668 | cv2.GaussianBlur(heatmap, (kernel, kernel), 0, heatmap) |
| 669 | np.clip(batch_heatmaps, 0.001, 50, batch_heatmaps) |
| 670 | np.log(batch_heatmaps, batch_heatmaps) |
| 671 | |
| 672 | batch_heatmaps_pad = np.pad(batch_heatmaps, ((0, 0), (0, 0), (1, 1), (1, 1)), mode="edge").flatten() |
| 673 | |
| 674 | index = coords[..., 0] + 1 + (coords[..., 1] + 1) * (W + 2) |
| 675 | index += (W + 2) * (H + 2) * np.arange(0, B * K).reshape(-1, K) |
| 676 | index = index.astype(int).reshape(-1, 1) |
| 677 | i_ = batch_heatmaps_pad[index] |
| 678 | ix1 = batch_heatmaps_pad[index + 1] |
| 679 | iy1 = batch_heatmaps_pad[index + W + 2] |
| 680 | ix1y1 = batch_heatmaps_pad[index + W + 3] |
| 681 | ix1_y1_ = batch_heatmaps_pad[index - W - 3] |
| 682 | ix1_ = batch_heatmaps_pad[index - 1] |
| 683 | iy1_ = batch_heatmaps_pad[index - 2 - W] |
| 684 | |
| 685 | dx = 0.5 * (ix1 - ix1_) |
| 686 | dy = 0.5 * (iy1 - iy1_) |
| 687 | derivative = np.concatenate([dx, dy], axis=1) |
| 688 | derivative = derivative.reshape(N, K, 2, 1) |
| 689 | dxx = ix1 - 2 * i_ + ix1_ |
| 690 | dyy = iy1 - 2 * i_ + iy1_ |
| 691 | dxy = 0.5 * (ix1y1 - ix1 - iy1 + i_ + i_ - ix1_ - iy1_ + ix1_y1_) |
| 692 | hessian = np.concatenate([dxx, dxy, dxy, dyy], axis=1) |
| 693 | hessian = hessian.reshape(N, K, 2, 2) |
| 694 | hessian = np.linalg.inv(hessian + np.finfo(np.float32).eps * np.eye(2)) |
no test coverage detected