Fast C++ heatmap-to-keypoints decoder for 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 sizeK: Number of keypointsH, 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:
- Scans Memory Linearly: Optimizes memory access patterns for NCHW layout.
- Refines Coordinates: Uses Taylor expansion (Hessian matrix inversion) to compute sub-pixel offsets from the discrete peak.
- 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:
- Global Argmax: Finds the discrete pixel $(p_x, p_y)$ with the maximum value.
- 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.
- 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 95.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85ce11f292242d6d34faa9be159c35af1f31d6a03538e8e71eed0e9cbe12fda6
|
|
| MD5 |
fd7abf5641dbcce46720cfa593273fdf
|
|
| BLAKE2b-256 |
10546f34b29e1ce320b23c98d05faaf89fb107ae1b0960604051173cb878d38d
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp312-cp312-manylinux2014_x86_64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp312-cp312-manylinux2014_x86_64.whl
- Upload date:
- Size: 71.8 kB
- Tags: CPython 3.12
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ee0de97f87db0f85c3543953d1394fd6c9cacdf1fca158eea24fbf12fc402e
|
|
| MD5 |
d118d7fe0ab62468dc412bba306849bb
|
|
| BLAKE2b-256 |
28b715d9949262bc90e58f3f60a9bc7b58904f551fb7360012ea8a4fb1f208ed
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 71.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
967dcd8d08089827939cd2c650f9ffaf03864aab855eea7a38a3e9317a682910
|
|
| MD5 |
fe8d14d071b35e940e88d1e310bfb26c
|
|
| BLAKE2b-256 |
f8d986c88101057d509af00373be1d9c77b5f89fdb71a30fb24b94f4c85b6571
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 94.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a24d4e57e98d507e1a40df46dd3f6c56bafbe5c8fe6973c5214d50d4cfe28bd4
|
|
| MD5 |
f2c2db1bf4e3b74e1792588ad9eaea25
|
|
| BLAKE2b-256 |
4065980718941fba14f37e5de08321bed7ee39560305a50dfe29c531a8e2094d
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp311-cp311-manylinux2014_x86_64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp311-cp311-manylinux2014_x86_64.whl
- Upload date:
- Size: 71.5 kB
- Tags: CPython 3.11
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21bb70464a7694fe64360c7410b70c66d6e6bd2bd250dd3a9af784bd76dd05e0
|
|
| MD5 |
d9472993b5f3cc26c8002945e9199df7
|
|
| BLAKE2b-256 |
e330c5b558bb8c805581257a70a693c1842ad39a5d93d675910c013e0b51f646
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 70.8 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acce2ef48a4d08c13e4e76ca81c16e280afa324562a354a8acb8a162f445f377
|
|
| MD5 |
747cff0cfe8a7348e43a3b84e5949c01
|
|
| BLAKE2b-256 |
1f9c1e9b99794ad41800647edbc60982993739309f84e30407114841b29a32ca
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 94.1 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d8e361e24f8b2e4abf8af2a5c1ae00853ff5abc07707acfb7b52fbf77a585a
|
|
| MD5 |
a39383ee4acfc5487196d6cd09e353c5
|
|
| BLAKE2b-256 |
9892c34734544ef6af1a60e39bb62f86605aa06c559ece39c0fb0ee4f8a6320e
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp310-cp310-manylinux2014_x86_64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp310-cp310-manylinux2014_x86_64.whl
- Upload date:
- Size: 70.4 kB
- Tags: CPython 3.10
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03fe764c5a1b6d0fa5a6467458e03852409465a0a4e92fcda0c4e3d54f883345
|
|
| MD5 |
1c8cd6462c79056d7b36f50f1d11bae9
|
|
| BLAKE2b-256 |
95b6ce6ee0681d3488b059b2d22ffa33a228a4259cd003e778c07b79ccdfaf70
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 69.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6682d1f1c5c8b2e6cffa2fd1f1604a6cbf9bce07f5ae33fedf511386cb5b2ae
|
|
| MD5 |
753d0e33a024402664b8190428b40b6e
|
|
| BLAKE2b-256 |
45ff41f593171c16a14cb5342e8ef29c81988243335b51a42fa3a92b4bf9cd9b
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 87.2 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba231deb4e3c7b16adc9b91927bb77c790f37f54681146668714303966df3631
|
|
| MD5 |
0c7db3c87875ccc3776755abae652874
|
|
| BLAKE2b-256 |
4aa3b21d8d366c6b90aa2198aeaf9d68da8566831dd55cdba31956a76b38094c
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp39-cp39-manylinux2014_x86_64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 70.5 kB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ad52627513ee21a9e9a50249cf3381c5788cc0ce9250ef02b3f58da4a8fb563
|
|
| MD5 |
32683c80cfeac77694b03db83167f937
|
|
| BLAKE2b-256 |
258a9120f10dfcec76d7bd980ea11e4aae0b5461c909bfb83eba0ae17971b354
|
File details
Details for the file heatmaps_to_keypoints-0.0.1-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: heatmaps_to_keypoints-0.0.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 60.2 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc68151808db54024d0994c5e8bed0daed57a108f0c9faba34e49d40ffbd11df
|
|
| MD5 |
a758a4179277e7a50f777a28d8974453
|
|
| BLAKE2b-256 |
a4a30a34db19c34755ea35d40551634ca31f939e062cf5fa201815842cf1ff2a
|