Skip to main content

Fast C++ 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.2-cp312-cp312-win_amd64.whl (23.7 MB view details)

Uploaded CPython 3.12Windows x86-64

heatmaps_to_keypoints-0.0.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

heatmaps_to_keypoints-0.0.2-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.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

heatmaps_to_keypoints-0.0.2-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.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (73.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

heatmaps_to_keypoints-0.0.2-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.2-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.2-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.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4d42c0cc6fe9245780e78ad5299edcfb6a02e9b3e286f5a1b344a4a934c85cc5
MD5 76cec729feb27c9aad98ef89bda90592
BLAKE2b-256 e8e6696e4572c3e9838800c5045734a27b4c5a43ecc711cdeb9bed280703f475

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7479fe25c7e54f747ed06f28e7d2ca2d74d817646cbb9744c5469e9c87793c61
MD5 f56eb1b00e7ba986cb6cdc85207dfb21
BLAKE2b-256 b52c4fffc075d4b0aa8c270b9a88300c7e27ef4bfe7d54d28066e20229e45f9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ce85c651ee99db0823f417524c7a9c7d694622b193f1388bde5cfcca06294b9a
MD5 6ee313dd05cd80fd4db17fc7e6613279
BLAKE2b-256 52582b6f1265fcf1cc77506444769d390fb918a759042da4149e5694e8701c00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09ba42fc520ab22498135e8953b71312bc6db64fd2204895c0a2526700a5dff6
MD5 3777f04e62065a49f4d64f9c2cfe24f6
BLAKE2b-256 1270db9e7f56f415762060a7eee61edc253a847d605c0d2bcb7a470b4c321e39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fa8cc9aa9231807d6ac0991228bdca74d801b98fe3da6ba26f4bc9ba5c06910c
MD5 8bc9cc032a4a2251fa3e405e2a3dff17
BLAKE2b-256 606a2ff1fd952c6fd16060474c6ef0d0296796c2fddc705b6834305c888d3fd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2e24cfbe05474804390abe7171851d59d5c2d63c6995e2a57a12fe09c606a9a1
MD5 bd8932a413624fc7aba0fdf0aeb193f8
BLAKE2b-256 446ab26f0b3684b1663d53d3340ce279a177a91d6ff7b4f82440545617f97562

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 369c9b069529930427de6542a508fda407e79641a9e8c3c6dfa23e8540314dbe
MD5 f44699c695408e76fbd9da2538d38a93
BLAKE2b-256 1a85be85305caf1becc30d8479e47f0b88880653ee96ac45d63ab32a92ab7579

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65065aaa764ec1abd58e9f7e3e9f176ab87092d335f80634ce21b91526ec77f1
MD5 b67b908dda4ca05fe90c48bde28e8508
BLAKE2b-256 e38b0eaa2b8e75020b27d6460f70b7c23167b802245cf2ff9d8cea060f5387a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fb874cbe5b7511298ffed43706a5c42012c2ecf372459d0619a822d3c08b0934
MD5 5f539fa72b84b7cc7bafde733e0c9c8c
BLAKE2b-256 e868568a98e909cd77cda281eb3eb8ce0526c614534007fad1c928d5b90204bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 05d4be24617bc79eac826d9f79600714e6bc018a7554be822d056c82a12dc656
MD5 a81cf3f044b9855a6037f4f6629818b4
BLAKE2b-256 8abe7d2d47b62692913ac804bc958831fcb840147214530a078a8a6540a569db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0453d5719cd21f09c710732f5b88dca65bf1534efc90c5c8fe223af6979b8126
MD5 0281c54e6c8bbd2a6bb17097aeea70fd
BLAKE2b-256 d3eb9f3ed2f79d6a8618449d25544acc1c49ed34da383295952a9562fdf15be5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b172f96b490a7e958d5ac5e1e33fa229ed253ab5776e3f03e1e6fd2e24cd7668
MD5 09add90ee703c34f1dfee86107440617
BLAKE2b-256 36c3a056009ef96e58548682d291a3461bd67541a32500db98e3b8fcfb0b8cec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 efbe79fb02a17cae56af82149596ae3ea0c01b3e886ff7b9a04a686e8da58a32
MD5 9842c3d5d503e3a8c00acf7c9fdabfd0
BLAKE2b-256 c1cc09937a327086a291f8151949571cc3404ddde566f561c2279ca0f1a99a9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65ce8f6abcb628e441e48ef3211d027556af1fde5be8741878d5b6e5dd9615e4
MD5 0e3303c8a469b894ff213b1dcb9f450f
BLAKE2b-256 4022b07c2b793805926c5a6f17d432601c41ea054a59df0296a0ca648c90ac0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3893dd010b7b2866f1a152277aca1b0fdf68f8029de023081a122041decb1ab5
MD5 84d652088c6d3363489e342f4081500e
BLAKE2b-256 d00ebd583c8943b379f3f4f73ce797f7ca8600c9d5a559345c0ed8eff6f2d288

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for heatmaps_to_keypoints-0.0.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c01d80fc81a8b7f5daf9b7d8226e5a895871fbe5eb727c9161e8aa0ddaf454c
MD5 8392d6a8af570e1c00001105435d7010
BLAKE2b-256 33d7d3c5872da3609907f7c561d9a280f0045b2e8b2fac6f400bea1483ba4008

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