MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / keypoints_from_heatmaps

Function keypoints_from_heatmaps

tools/preprocess/pose2d_utils.py:773–897  ·  view source on GitHub ↗

Get final keypoint predictions from heatmaps and transform them back to the image. Note: - batch size: N - num keypoints: K - heatmap height: H - heatmap width: W Args: heatmaps (np.ndarray[N, K, H, W]): model predicted heatmaps. center (

(heatmaps, center, scale, unbiased=False, post_process="default", kernel=11, valid_radius_factor=0.0546875, use_udp=False, target_type="GaussianHeatmap")

Source from the content-addressed store, hash-verified

771
772
773def keypoints_from_heatmaps(heatmaps, center, scale, unbiased=False, post_process="default", kernel=11, valid_radius_factor=0.0546875, use_udp=False, target_type="GaussianHeatmap"):
774 """Get final keypoint predictions from heatmaps and transform them back to
775 the image.
776
777 Note:
778 - batch size: N
779 - num keypoints: K
780 - heatmap height: H
781 - heatmap width: W
782
783 Args:
784 heatmaps (np.ndarray[N, K, H, W]): model predicted heatmaps.
785 center (np.ndarray[N, 2]): Center of the bounding box (x, y).
786 scale (np.ndarray[N, 2]): Scale of the bounding box
787 wrt height/width.
788 post_process (str/None): Choice of methods to post-process
789 heatmaps. Currently supported: None, 'default', 'unbiased',
790 'megvii'.
791 unbiased (bool): Option to use unbiased decoding. Mutually
792 exclusive with megvii.
793 Note: this arg is deprecated and unbiased=True can be replaced
794 by post_process='unbiased'
795 Paper ref: Zhang et al. Distribution-Aware Coordinate
796 Representation for Human Pose Estimation (CVPR 2020).
797 kernel (int): Gaussian kernel size (K) for modulation, which should
798 match the heatmap gaussian sigma when training.
799 K=17 for sigma=3 and k=11 for sigma=2.
800 valid_radius_factor (float): The radius factor of the positive area
801 in classification heatmap for UDP.
802 use_udp (bool): Use unbiased data processing.
803 target_type (str): 'GaussianHeatmap' or 'CombinedTarget'.
804 GaussianHeatmap: Classification target with gaussian distribution.
805 CombinedTarget: The combination of classification target
806 (response map) and regression target (offset map).
807 Paper ref: Huang et al. The Devil is in the Details: Delving into
808 Unbiased Data Processing for Human Pose Estimation (CVPR 2020).
809
810 Returns:
811 tuple: A tuple containing keypoint predictions and scores.
812
813 - preds (np.ndarray[N, K, 2]): Predicted keypoint location in images.
814 - maxvals (np.ndarray[N, K, 1]): Scores (confidence) of the keypoints.
815 """
816 # Avoid being affected
817 heatmaps = heatmaps.copy()
818
819 # detect conflicts
820 if unbiased:
821 assert post_process not in [False, None, "megvii"]
822 if post_process in ["megvii", "unbiased"]:
823 assert kernel > 0
824 if use_udp:
825 assert not post_process == "megvii"
826
827 # normalize configs
828 if post_process is False:
829 warnings.warn("post_process=False is deprecated, please use post_process=None instead", DeprecationWarning)
830 post_process = None

Callers 1

forwardMethod · 0.90

Calls 7

_gaussian_blurFunction · 0.85
_get_max_predsFunction · 0.85
post_dark_udpFunction · 0.85
_taylorFunction · 0.85
transform_predsFunction · 0.85
copyMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected