Convert Figma logo to code with AI

microsoft logohuman-pose-estimation.pytorch

The project is an official implement of our ECCV2018 paper "Simple Baselines for Human Pose Estimation and Tracking(https://arxiv.org/abs/1804.06208)"

2,933
601
2,933
100

Top Related Projects

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.

30,786

OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation

5,562

OpenMMLab Pose Estimation Toolbox and Benchmark.

Pretrained models for TensorFlow.js

Quick Overview

Microsoft's human-pose-estimation.pytorch is an open-source project for human pose estimation using PyTorch. It implements state-of-the-art deep learning models for detecting and tracking human body keypoints in images and videos. The repository provides pre-trained models, training scripts, and evaluation tools for researchers and developers working on human pose estimation tasks.

Pros

  • High accuracy and performance on standard pose estimation benchmarks
  • Supports both 2D and 3D pose estimation
  • Includes pre-trained models for quick deployment
  • Comprehensive documentation and example usage

Cons

  • Requires significant computational resources for training
  • Limited to human pose estimation (not suitable for other object types)
  • Dependency on specific versions of PyTorch and other libraries
  • May require fine-tuning for specific use cases or datasets

Code Examples

  1. Loading a pre-trained model:
from models.pose_resnet import get_pose_net
model = get_pose_net(cfg, is_train=False)
model.load_state_dict(torch.load('path/to/pretrained_model.pth'))
  1. Performing inference on an image:
from utils.transforms import get_affine_transform
input = cv2.imread('path/to/image.jpg')
input = cv2.cvtColor(input, cv2.COLOR_BGR2RGB)
input = get_affine_transform(input, center, scale, rotation, cfg.MODEL.IMAGE_SIZE)
input = torch.from_numpy(input).unsqueeze(0).float()
output = model(input)
  1. Visualizing the detected keypoints:
from utils.vis import save_batch_image_with_joints
save_batch_image_with_joints(input, output, 'output_image.jpg')

Getting Started

  1. Clone the repository:

    git clone https://github.com/microsoft/human-pose-estimation.pytorch.git
    cd human-pose-estimation.pytorch
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Download pre-trained models:

    mkdir models
    wget https://download.pytorch.org/models/resnet50-19c8e357.pth -O models/resnet50-19c8e357.pth
    
  4. Run inference on an image:

    python tools/inference.py --cfg experiments/coco/resnet50/256x192_d256x3_adam_lr1e-3.yaml --checkpoint models/pytorch/pose_coco/pose_resnet_50_256x192.pth.tar --image examples/demo.jpg
    

Competitor Comparisons

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.

Pros of Detectron2

  • Broader scope: Supports multiple computer vision tasks beyond pose estimation
  • More active development: Frequent updates and larger community
  • Modular architecture: Easier to extend and customize

Cons of Detectron2

  • Steeper learning curve: More complex due to its broader scope
  • Higher resource requirements: May need more powerful hardware

Code Comparison

Human-pose-estimation.pytorch:

from models.pose_resnet import get_pose_net

model = get_pose_net(cfg, is_train=False)
model.load_state_dict(torch.load(model_path))

Detectron2:

from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml"))
predictor = DefaultPredictor(cfg)

Human-pose-estimation.pytorch focuses specifically on pose estimation, making it more straightforward for this task. Detectron2 offers a more comprehensive framework for various computer vision tasks, including pose estimation, object detection, and instance segmentation. The code comparison shows that Detectron2 requires more setup but provides a more flexible configuration system.

30,786

OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation

Pros of openpose

  • More comprehensive body keypoint detection, including face and hand keypoints
  • Real-time performance on CPU and GPU
  • Extensive documentation and community support

Cons of openpose

  • Larger model size and higher computational requirements
  • Less flexibility in terms of customization and fine-tuning

Code comparison

openpose:

#include <openpose/flags.hpp>
#include <openpose/headers.hpp>

op::Wrapper opWrapper{op::ThreadManagerMode::Asynchronous};
opWrapper.start();

human-pose-estimation.pytorch:

from models.pose_resnet import get_pose_net
model = get_pose_net(cfg, is_train=False)
model.eval()

The openpose example shows C++ code for initializing the wrapper, while human-pose-estimation.pytorch uses Python to create and evaluate the model. openpose offers a higher-level API, while human-pose-estimation.pytorch provides more direct access to the underlying model.

5,562

OpenMMLab Pose Estimation Toolbox and Benchmark.

Pros of mmpose

  • More comprehensive, supporting a wider range of pose estimation tasks and models
  • Actively maintained with frequent updates and new features
  • Modular design allowing for easy customization and extension

Cons of mmpose

  • Steeper learning curve due to its more complex architecture
  • Potentially higher computational requirements for some models

Code Comparison

mmpose:

from mmpose.apis import inference_top_down_pose_model, init_pose_model

model = init_pose_model(config, checkpoint)
results = inference_top_down_pose_model(model, image, person_results)

human-pose-estimation.pytorch:

from pose_estimation import get_pose_net

model = get_pose_net(cfg, is_train=False)
model.load_state_dict(torch.load(model_path))
output = model(input_image)

Both repositories provide implementations for human pose estimation, but mmpose offers a more extensive framework with additional features and flexibility. While human-pose-estimation.pytorch is simpler and easier to get started with, mmpose provides a more robust solution for complex pose estimation tasks and research. The code comparison shows that mmpose has a more structured API, while human-pose-estimation.pytorch offers a more straightforward approach to model initialization and inference.

Pretrained models for TensorFlow.js

Pros of tfjs-models

  • Runs in web browsers, enabling client-side inference
  • Supports multiple model types beyond pose estimation
  • Easier integration with web applications

Cons of tfjs-models

  • Generally slower performance compared to PyTorch implementation
  • May have lower accuracy for complex pose estimation tasks
  • Limited customization options for advanced users

Code Comparison

human-pose-estimation.pytorch:

from models.pose_resnet import get_pose_net
model = get_pose_net(cfg, is_train=False)
model.load_state_dict(torch.load(model_path))

tfjs-models:

const net = await posenet.load();
const pose = await net.estimateSinglePose(imageElement);

The PyTorch implementation offers more flexibility in model architecture and training, while the TensorFlow.js version provides a simpler API for quick integration in web applications. The PyTorch code allows for more customization, whereas the TensorFlow.js code is more straightforward for basic pose estimation tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Simple Baselines for Human Pose Estimation and Tracking

News

Introduction

This is an official pytorch implementation of Simple Baselines for Human Pose Estimation and Tracking. This work provides baseline methods that are surprisingly simple and effective, thus helpful for inspiring and evaluating new ideas for the field. State-of-the-art results are achieved on challenging benchmarks. On COCO keypoints valid dataset, our best single model achieves 74.3 of mAP. You can reproduce our results using this repo. All models are provided for research purpose.

Main Results

Results on MPII val

ArchHeadShoulderElbowWristHipKneeAnkleMeanMean@0.1
256x256_pose_resnet_50_d256d256d25696.35195.32988.98983.17688.42083.96079.59488.53233.911
384x384_pose_resnet_50_d256d256d25696.65895.75489.79084.61488.52384.66679.28789.06638.046
256x256_pose_resnet_101_d256d256d25696.86295.87389.51884.37688.43784.48680.70389.13134.020
384x384_pose_resnet_101_d256d256d25696.96595.90790.26885.78089.59785.93582.09890.00338.860
256x256_pose_resnet_152_d256d256d25697.03395.94190.04684.97689.16485.31181.27189.62035.025
384x384_pose_resnet_152_d256d256d25696.79495.61890.08086.22589.70086.86282.85390.20039.433

Note:

  • Flip test is used.

Results on COCO val2017 with detector having human AP of 56.4 on COCO val2017 dataset

ArchAPAp .5AP .75AP (M)AP (L)ARAR .5AR .75AR (M)AR (L)
256x192_pose_resnet_50_d256d256d2560.7040.8860.7830.6710.7720.7630.9290.8340.7210.824
384x288_pose_resnet_50_d256d256d2560.7220.8930.7890.6810.7970.7760.9320.8380.7280.846
256x192_pose_resnet_101_d256d256d2560.7140.8930.7930.6810.7810.7710.9340.8400.7300.832
384x288_pose_resnet_101_d256d256d2560.7360.8960.8030.6990.8110.7910.9360.8510.7450.858
256x192_pose_resnet_152_d256d256d2560.7200.8930.7980.6870.7890.7780.9340.8460.7360.839
384x288_pose_resnet_152_d256d256d2560.7430.8960.8110.7050.8160.7970.9370.8580.7510.863

Results on Caffe-style ResNet

ArchAPAp .5AP .75AP (M)AP (L)ARAR .5AR .75AR (M)AR (L)
256x192_pose_resnet_50_caffe_d256d256d2560.7040.9140.7820.6770.7440.7350.9210.8050.7040.783
256x192_pose_resnet_101_caffe_d256d256d2560.7200.9150.8030.6930.7640.7530.9280.8210.7200.802
256x192_pose_resnet_152_caffe_d256d256d2560.7280.9250.8040.7020.7660.7600.9310.8280.7290.806

Note:

  • Flip test is used.
  • Person detector has person AP of 56.4 on COCO val2017 dataset.
  • Difference between PyTorch-style and Caffe-style ResNet is the position of stride=2 convolution

Environment

The code is developed using python 3.6 on Ubuntu 16.04. NVIDIA GPUs are needed. The code is developed and tested using 4 NVIDIA P100 GPU cards. Other platforms or GPU cards are not fully tested.

Quick start

Installation

  1. Install pytorch >= v0.4.0 following official instruction.

  2. Disable cudnn for batch_norm:

    # PYTORCH=/path/to/pytorch
    # for pytorch v0.4.0
    sed -i "1194s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
    # for pytorch v0.4.1
    sed -i "1254s/torch\.backends\.cudnn\.enabled/False/g" ${PYTORCH}/torch/nn/functional.py
    

    Note that instructions like # PYTORCH=/path/to/pytorch indicate that you should pick a path where you'd like to have pytorch installed and then set an environment variable (PYTORCH in this case) accordingly.

  3. Clone this repo, and we'll call the directory that you cloned as ${POSE_ROOT}.

  4. Install dependencies:

    pip install -r requirements.txt
    
  5. Make libs:

    cd ${POSE_ROOT}/lib
    make
    
  6. Install COCOAPI:

    # COCOAPI=/path/to/clone/cocoapi
    git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
    cd $COCOAPI/PythonAPI
    # Install into global site-packages
    make install
    # Alternatively, if you do not have permissions or prefer
    # not to install the COCO API into global site-packages
    python3 setup.py install --user
    

    Note that instructions like # COCOAPI=/path/to/install/cocoapi indicate that you should pick a path where you'd like to have the software cloned and then set an environment variable (COCOAPI in this case) accordingly.

  7. Download pytorch imagenet pretrained models from pytorch model zoo and caffe-style pretrained models from GoogleDrive.

  8. Download mpii and coco pretrained models from OneDrive or GoogleDrive. Please download them under ${POSE_ROOT}/models/pytorch, and make them look like this:

    ${POSE_ROOT}
     `-- models
         `-- pytorch
             |-- imagenet
             |   |-- resnet50-19c8e357.pth
             |   |-- resnet50-caffe.pth.tar
             |   |-- resnet101-5d3b4d8f.pth
             |   |-- resnet101-caffe.pth.tar
             |   |-- resnet152-b121ed2d.pth
             |   `-- resnet152-caffe.pth.tar
             |-- pose_coco
             |   |-- pose_resnet_101_256x192.pth.tar
             |   |-- pose_resnet_101_384x288.pth.tar
             |   |-- pose_resnet_152_256x192.pth.tar
             |   |-- pose_resnet_152_384x288.pth.tar
             |   |-- pose_resnet_50_256x192.pth.tar
             |   `-- pose_resnet_50_384x288.pth.tar
             `-- pose_mpii
                 |-- pose_resnet_101_256x256.pth.tar
                 |-- pose_resnet_101_384x384.pth.tar
                 |-- pose_resnet_152_256x256.pth.tar
                 |-- pose_resnet_152_384x384.pth.tar
                 |-- pose_resnet_50_256x256.pth.tar
                 `-- pose_resnet_50_384x384.pth.tar
    
    
  9. Init output(training model output directory) and log(tensorboard log directory) directory:

    mkdir output 
    mkdir log
    

    Your directory tree should look like this:

    ${POSE_ROOT}
    ├── data
    ├── experiments
    ├── lib
    ├── log
    ├── models
    ├── output
    ├── pose_estimation
    ├── README.md
    └── requirements.txt
    

Data preparation

For MPII data, please download from MPII Human Pose Dataset. The original annotation files are in matlab format. We have converted them into json format, you also need to download them from OneDrive or GoogleDrive. Extract them under {POSE_ROOT}/data, and make them look like this:

${POSE_ROOT}
|-- data
`-- |-- mpii
    `-- |-- annot
        |   |-- gt_valid.mat
        |   |-- test.json
        |   |-- train.json
        |   |-- trainval.json
        |   `-- valid.json
        `-- images
            |-- 000001163.jpg
            |-- 000003072.jpg

For COCO data, please download from COCO download, 2017 Train/Val is needed for COCO keypoints training and validation. We also provide person detection result of COCO val2017 to reproduce our multi-person pose estimation results. Please download from OneDrive or GoogleDrive. Download and extract them under {POSE_ROOT}/data, and make them look like this:

${POSE_ROOT}
|-- data
`-- |-- coco
    `-- |-- annotations
        |   |-- person_keypoints_train2017.json
        |   `-- person_keypoints_val2017.json
        |-- person_detection_results
        |   |-- COCO_val2017_detections_AP_H_56_person.json
        `-- images
            |-- train2017
            |   |-- 000000000009.jpg
            |   |-- 000000000025.jpg
            |   |-- 000000000030.jpg
            |   |-- ... 
            `-- val2017
                |-- 000000000139.jpg
                |-- 000000000285.jpg
                |-- 000000000632.jpg
                |-- ... 

Valid on MPII using pretrained models

python pose_estimation/valid.py \
    --cfg experiments/mpii/resnet50/256x256_d256x3_adam_lr1e-3.yaml \
    --flip-test \
    --model-file models/pytorch/pose_mpii/pose_resnet_50_256x256.pth.tar

Training on MPII

python pose_estimation/train.py \
    --cfg experiments/mpii/resnet50/256x256_d256x3_adam_lr1e-3.yaml

Valid on COCO val2017 using pretrained models

python pose_estimation/valid.py \
    --cfg experiments/coco/resnet50/256x192_d256x3_adam_lr1e-3.yaml \
    --flip-test \
    --model-file models/pytorch/pose_coco/pose_resnet_50_256x192.pth.tar

Training on COCO train2017

python pose_estimation/train.py \
    --cfg experiments/coco/resnet50/256x192_d256x3_adam_lr1e-3.yaml

Other Implementations

Citation

If you use our code or models in your research, please cite with:

@inproceedings{xiao2018simple,
    author={Xiao, Bin and Wu, Haiping and Wei, Yichen},
    title={Simple Baselines for Human Pose Estimation and Tracking},
    booktitle = {European Conference on Computer Vision (ECCV)},
    year = {2018}
}