Skip to main content

Fast heatmap-to-keypoints decoder for 2D human pose estimation.

Project description

HeatmapToKeypoints

A high-performance C++/PyTorch extension for decoding 2D heatmaps into precise keypoint coordinates.

This library is designed for human pose estimation and keypoint detection workflows. It accepts standard NCHW heatmap tensors (e.g., from HRNet, SimpleBaseline, or KD-student models) and efficiently converts them into normalized (x, y) coordinates with confidence scores using sub-pixel refinement.

Problem Statement

Pose estimation models typically output a 4D tensor of shape [N, K, H, W]:

  • N: Batch size
  • K: Number of keypoints
  • H, W: Heatmap spatial dimensions

Each channel K contains a 2D Gaussian distribution where the peak represents the predicted location of a specific body part. Converting these heatmaps into coordinates requires finding the peak and refining it to achieve sub-pixel accuracy. Doing this efficiently on CPU for large batches can be slow in pure Python.

Solution

HeatmapToKeypoints provides a direct C++ binding to PyTorch that:

  1. Scans Memory Linearly: Optimizes memory access patterns for NCHW layout.
  2. Refines Coordinates: Uses Taylor expansion (Hessian matrix inversion) to compute sub-pixel offsets from the discrete peak.
  3. Outputs Normalized Data: Returns coordinates in [0.0, 1.0] range, independent of resolution.

Installation

Ensure you have a C++17 compatible compiler and PyTorch installed.

pip install .

Usage

The library exposes a single function decode_heatmaps.

Input format

  • Type: torch.Tensor (float32)
  • Shape: [Batch, Keypoints, Height, Width]
  • Device: CPU
  • Memory: Contiguous

Python Example

import torch
import heatmaps_to_keypoints

# Example Tensor: Batch=8, Keypoints=17, Height=96, Width=72
heatmaps = torch.randn(8, 17, 96, 72)

# Decode
# Returns a list of lists: results[batch_index][keypoint_index]
results = heatmaps_to_keypoints.decode_heatmaps(heatmaps)

# Access data for the first image in batch, first keypoint
landmark = results[0][0]

print(f"X: {landmark.x}")     # Normalized [0-1]
print(f"Y: {landmark.y}")     # Normalized [0-1]
print(f"Score: {landmark.score}") # Heatmap peak value

Algorithm Details

For each keypoint heatmap, the decoder performs:

  1. Global Argmax: Finds the discrete pixel $(p_x, p_y)$ with the maximum value.
  2. Taylor Expansion: Uses the 2nd-order Taylor series approximation around the peak to find the true sub-pixel maximum. $$ \Delta = -H^{-1} \nabla $$ Where $H$ is the Hessian matrix and $\nabla$ is the gradient vector computed from neighbors.
  3. Coordinate Normalization: $$ x_{final} = \frac{p_x + \Delta_x}{W}, \quad y_{final} = \frac{p_y + \Delta_y}{H} $$

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

heatmaps_to_keypoints-0.0.4-cp312-cp312-win_amd64.whl (23.7 MB view details)

Uploaded CPython 3.12Windows x86-64

heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_x86_64.whl (15.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_aarch64.whl (7.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

heatmaps_to_keypoints-0.0.4-cp312-cp312-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

heatmaps_to_keypoints-0.0.4-cp311-cp311-win_amd64.whl (23.7 MB view details)

Uploaded CPython 3.11Windows x86-64

heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_x86_64.whl (15.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_aarch64.whl (7.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

heatmaps_to_keypoints-0.0.4-cp311-cp311-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

heatmaps_to_keypoints-0.0.4-cp310-cp310-win_amd64.whl (23.7 MB view details)

Uploaded CPython 3.10Windows x86-64

heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_x86_64.whl (15.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_aarch64.whl (7.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

heatmaps_to_keypoints-0.0.4-cp310-cp310-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

heatmaps_to_keypoints-0.0.4-cp39-cp39-win_amd64.whl (23.7 MB view details)

Uploaded CPython 3.9Windows x86-64

heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_x86_64.whl (15.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_aarch64.whl (7.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ ARM64

heatmaps_to_keypoints-0.0.4-cp39-cp39-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 73171cda669258e73af437ddeaab5d06a8c2b7804dcdcba6a5126eeb5e428ab5
MD5 a58d6ca26427bdf634e2f4adb8be494f
BLAKE2b-256 02480d84d3f8f2b2fc9f3450fcfbdcd5cf405e0dacf6779ea4ac25fd14431dc7

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 80105ce9f7413052b0165f0ceaad4326935043d73052389dd395e8a7765dc070
MD5 e1200b3153843324587fc2410dc390aa
BLAKE2b-256 c37a8307cede689af5c48461907bdc2a8e93a717d7de1f9df5ff9bdaaba082a1

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 93b69ecc6c2e765ef57b84e2895b9def8f4cbeb56c8e88f9480be2769844e6ef
MD5 2d56ed2c31c2fff52fcc04c0f756269b
BLAKE2b-256 6c98a03cbd40bd52c100d96b349c8bc050866dca4754fa5e4abfc132c45e8055

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a73599336170c28be222a39f63678ada39b7a3efcc9af38fd33f0a842f40b0a
MD5 a9f9612b19deafed7b88a02c98fdcd52
BLAKE2b-256 3efdb1607fb5d499db398ae3d0f3da60750d6911b7a3790fd80b7c089cb101c8

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ed692c5dbd29b2a58b208537ee192c0b8fd2376079457e9521924c85fd9ecd61
MD5 d07bba989f7f73551e494e453f7fdec2
BLAKE2b-256 ba07383ed3906e3ba97e8844bd52cdd93c2730a942a5b0c31326d2c7c855a717

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 abd209446c5d8faa0f35573ba070fad495b763224557991abeb24c533fe9d69c
MD5 e04a759bcc91dd896aa234521028222a
BLAKE2b-256 2b4c45fd8d72e4afc046ea55e1dd8027e6943f24bb64b2ba4641d17841243ef2

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5aafc5b747ad0c8c3f2236d22f6b0ec7250c0b13507c402a5bb519b0fd9bf050
MD5 987d818c5029ce4d327e4d88d6331026
BLAKE2b-256 51320ef5ec15c2f32f4232000316f4400e640556783bbd31824edf0ff5675e6b

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24c0446db529544b9eac9dedac9a1f19bd2ccea60ef6e10596fe9f2e64f9ff5a
MD5 6b475b403dfb394a73a6e54dc0e3eee4
BLAKE2b-256 0a6eb725d4dc397371c0cafcd9073683592854f51bc2dd699f66c3e5f82e092e

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7b5b7c8b9bb8d0bcab5f57df6e99b8ec035ab59f72acd8ffcdc678e2eb44b746
MD5 b52f2c5686fdd5766fc4d47f3a04e5ff
BLAKE2b-256 adbd47f087e79e44979d0ea1872ce223037fb531d0a23883ba5b9b9ad504cab9

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f5e20340e555cc846fb159491931fb03a52f0b311ebf81d693e837562091c3b
MD5 e15550613241650a4d7cd6d6f19e1d31
BLAKE2b-256 2843feb1ee0fcf92d99f0b2b789a98b8b840bd5d1b0515117b50835f069ce117

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e62f70168ccf253ab9e14086c00ce7698e4176854c4767511573ffee7953d7ff
MD5 11da3f21efc5a4ac904eb1a5dc85a021
BLAKE2b-256 cd813c04b2c3c1466de36abee18605e943086e6f62750181c0a922b99e110cd9

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f5d5664c561145561e651dae3ac0e0ed49661e5d6569fe80e624cbca39dacf2
MD5 05050971ee3065c44f7c5fddd21027cc
BLAKE2b-256 2be14f0211e09fd4531447a2d5b3935d1df5b8fad05153c55415024c226c42e9

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 704fdef9fa7ba46c5b8cb17c065b36fe1308ee4f1ed41c3a8788bedef7fc69f0
MD5 6214a301257e36e7786ac79468dc0729
BLAKE2b-256 f9385df781ae6849754234965556892bf5a6f08722a48645d98bf2b1ce03df9d

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b725ae5bc5b9ba159d8d5f562a6ca69a0679898f8415976e7368d0ffdc824094
MD5 76b1a202ad69146011bbe2351b130c76
BLAKE2b-256 782f95f5a0bf7fb83ef9b9736ca9f8695de11bbf110120710fafc77abd9fbe76

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 00d457f8fe95b78d8969d78b82c36a7a8f202ff588b26869410394ca1c0ff74d
MD5 68686ad19a994c2940b5f2c6801606f4
BLAKE2b-256 bff0a2e4eab711f50a415d3ff4fb5a1834fcbfc3d50c94b561c1428eda12f694

See more details on using hashes here.

File details

Details for the file heatmaps_to_keypoints-0.0.4-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dfbf4156a836ea79e23b00b82294e9ab5ce2cca834fc0e8ccb63accfeecc8a8a
MD5 57773c16d9cb649d2d1fe58df326a611
BLAKE2b-256 7f9d1571d3490b5d85794a47b3b7e6b9492642c34d6e89b41473602faf6b45d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page