PyTorch-Pose

January 4, 2019 ยท View on GitHub

PyTorch-Pose is a PyTorch implementation of the general pipeline for 2D single human pose estimation. The aim is to provide the interface of the training/inference/evaluation, and the dataloader with various data augmentation options for the most popular human pose databases (e.g., the MPII human pose, LSP and FLIC).

Some codes for data preparation and augmentation are brought from the Stacked hourglass network. Thanks to the original author.

Models

Modelin_resfeatrues# of WeightsHeadShoulderElbowWristHipKneeAnkleMeanLink
hg_s2_b12561286.73m95.7494.5187.6881.7087.8180.8876.8386.58GoogleDrive
hg_s2_b1_mobile2561282.31m95.8093.6185.5079.6386.1377.8273.6284.69GoogleDrive
hg_s2_b1_tiny1921282.31m94.9592.8784.5978.1984.6877.7073.0783.88GoogleDrive

Installation

  1. Create a virtualenv

    virtualenv -p /usr/bin/python2.7 posevenv
    
  2. Install all dependencies in virtualenv

    source posevenv/bin/activate
    pip install -r requirements.txt
    
  3. Clone the repository with submodule

    git clone --recursive https://github.com/yuanyuanli85/pytorch-pose.git
    
  4. Create a symbolic link to the images directory of the MPII dataset:

    ln -s PATH_TO_MPII_IMAGES_DIR data/mpii/images
    
  5. Disable cudnn for batchnorm layer to solve bug in pytorch0.4.0

    sed -i "1194s/torch\.backends\.cudnn\.enabled/False/g" ./pose_venv/lib/python2.7/site-packages/torch/nn/functional.py
    

Training

  • Normal network configuration, in_res 256, features 128
python example/mpii.py -a hg --stacks 2 --blocks 1 --checkpoint checkpoint/hg_s2_b1/ --in_res 256 --features 256
  • Mobile network configuration, in_res 256, features 128
python example/mpii.py -a hg --stacks 2 --blocks 1 --checkpoint checkpoint/hg_s2_b1_mobile/ --mobile True --in_res 256 --features 256
  • Tiny network configuration, in_res 192, features 128
python example/mpii.py -a hg --stacks 2 --blocks 1 --checkpoint checkpoint/hg_s2_b1_tiny/ --mobile True --in_res 192 --features 128

Evaluation

Run evaluation to generate mat file

python example/mpii.py -a hg --stacks 2 --blocks 1 --checkpoint checkpoint/hg_s2_b1/ --resume checkpoint/hg_s2_b1/model_best.pth.tar -e
  • --resume_checkpoint is the checkpoint want to evaluate

Run evaluation/eval_PCKh.py to get val score

Export pytorch checkpoint to onnx

python tools/mpii_export_to_onxx.py -a hg -s 2 -b 1 --num-classes 16 --mobile True --in_res 256  --checkpoint checkpoint/model_best.pth.tar 
--out_onnx checkpoint/model_best.onnx 

Here

  • --checkpoint is the checkpoint want to export
  • --out_onnx is the exported onnx file