Home

Awesome

Multi-person Human Pose Estimation with HRNet in PyTorch

This is an unofficial implementation of the paper Deep High-Resolution Representation Learning for Human Pose Estimation.
The code is a simplified version of the official code with the ease-of-use in mind.

The code is fully compatible with the official pre-trained weights and the results are the same of the original implementation (only slight differences on gpu due to CUDA). It supports both Windows and Linux.

This repository provides:

If you are interested in HigherHRNet, please look at simple-HigherHRNet

Examples

<table> <tr> <td align="center"><img src="./gifs/gif-01-output.gif" width="100%" height="auto" /></td> <td align="center"><img src="./gifs/gif-02-output.gif" width="100%" height="auto" /></td> </tr> </table>

Class usage

import cv2
from SimpleHRNet import SimpleHRNet

model = SimpleHRNet(48, 17, "./weights/pose_hrnet_w48_384x288.pth")
image = cv2.imread("image.png", cv2.IMREAD_COLOR)

joints = model.predict(image)

The most useful parameters of the __init__ function are:

<table> <tr> <td>c</td><td>number of channels (HRNet: 32, 48; PoseResNet: resnet size)</td> </tr> <tr> <td>nof_joints</td><td>number of joints (COCO: 17, MPII: 16)</td> </tr> <tr> <td>checkpoint_path</td><td>path of the (official) weights to be loaded</td> </tr> <tr> <td>model_name</td><td>'HRNet' or 'PoseResNet'</td> </tr> <tr> <td>resolution</td><td>image resolution, it depends on the loaded weights</td> </tr> <tr> <td>multiperson</td><td>enable multiperson prediction</td> </tr> <tr> <td>return_heatmaps</td><td>the `predict` method returns also the heatmaps</td> </tr> <tr> <td>return_bounding_boxes</td><td>the `predict` method returns also the bounding boxes (useful in conjunction with `multiperson`)</td> </tr> <tr> <td>max_batch_size</td><td>maximum batch size used in hrnet inference</td> </tr> <tr> <td>device</td><td>device (cpu or cuda)</td> </tr> </table>

Running the live demo

From a connected camera:

python scripts/live-demo.py --camera_id 0

From a saved video:

python scripts/live-demo.py --filename video.mp4

For help:

python scripts/live-demo.py --help

Extracting keypoints:

From a saved video:

python scripts/extract-keypoints.py --format csv --filename video.mp4

For help:

python scripts/extract-keypoints.py --help

Converting the model to TensorRT:

Warning: require the installation of TensorRT (see Nvidia website) and onnx. On some platforms, they can be installed with

pip install tensorrt onnx

Converting in FP16:

python scripts/export-tensorrt-model.py --device 0 --half

For help:

python scripts/export-tensorrt-model.py --help

Running the training script

python scripts/train_coco.py

For help:

python scripts/train_coco.py --help

Installation instructions

Google Colab notebook

Thanks to the great work of @basicvisual and @wuyenlin, you can also try this repository online on Google Colab. More details and the notebook URL are available in this issue.
Please make sure to make a copy on your own Google Drive and to change the Colab "Runtime type" from CPU to GPU or TPU.