This is a third-party TensorFlow implementation for BlazePose.
The original paper is "BlazePose: On-device Real-time Body Pose tracking" by Valentin Bazarevsky, Ivan Grishchenko, Karthik Raveendran, Tyler Zhu, Fan Zhang, and Matthias Grundmann. Available on arXiv.
Since I do not have the full settings provided by the original author. There might be something different from the original paper. Please forgive me if I write something wrong.
Works are in process. The current version does not stand for the full functions.
It is highly recommended to run this code on Ubuntu 20.04 with an Anaconda environment. Python 3.7.9 and 3.8.5 has been tested. CUDA version has been tested with 10.1
and 11.1
.
tensorflow >= 2.3
numpy
matplotlib
scipy
-
Download LSP dataset. (If you already have, just skip this step)
If you are the first time to run this code on Linux platform, the LSP dataset will be downloaded.
However, if you are using Microsoft Windows 10, please download and unzip the dataset manually.
-
Pre-train the heatmap branch.
Edit training settings in
config.py
. Settrain_mode = 0
andcontinue_train = 0
.Then, run
python3 train.py
. -
Fine-tune for the joint regression branch.
Set
train_mode = 1
,continue_train = 0
andbest_pre_train
with the num of epoch where the training loss drops but testing accuracy achieve the optimal.Then, run
python3 train.py
.
If you have just suffered from an unexpected power off or press Ctrl + C
to cut up training, and then you want to continue your work, follow the following steps:
-
Edit
config.py
, modifycontinue_train
to the epoch where you want to start with.For continue pre-train, simply set the value of
continue_train
.For fine-tuning, set
train_mode = 1
, andcontinue_train
to num of epoches where the training loss drops but testing accuracy achieve the optimal. -
Run
python3 train.py
. -
If you are running pre-train just now, after that, just set
train_mode = 1
,continue_train = 0
, andbest_pre_train
with the num of epoches where the training loss drops but testing accuracy achieve the optimal, and runpython3 train.py
.
-
Edit
config.py
.If you want to see the visualized heatmaps, set
train_mode = 0
.For skeleton joint results, set
train_mode = 1
. -
Set
epoch_to_test
to the epoch you would like to test. -
If you set
train_mode = 0
, you should also setvis_img_id
to select an image. -
For
train_mode = 1
, evaluation mode should be set.Set
eval_mode = 1
if you want to get PCKh@0.5 score, oreval_mode = 0
if you want to get the result images. -
If you are the first time to set
train_mode = 1
andeval_mode = 0
, open terminal:mkdir result
-
Run
python3 test.py
.For
train_mode = 0
, you will see the heatmap.For
train_mode = 1
andeval_mode = 0
, the tested images will be written inresult
dictionary.For
train_mode = 1
andeval_mode = 1
, PCKh@0.5 scores of each joint and the average score will be shown.
-
Install YOLOv4 package using
pip3 install yolov4
. The trained model of YOLOv4 should also be downloaded. -
Finish training on your dataset.
-
Set
train_mode = 1
and connect to a USB camera. -
Run
python3 demo.py
. You should allow one or a few person(s) standing in front of the camera.
-
Basic code for network model BlazePose.
- Implementation of Channel Attention layer.
-
Functions
-
Two-stage training (pre-train and fine-tune).
-
Continue training from a custom epoch of checkpoint.
-
Save the training record (loss and accuracy for training and validation set) to json file.
-
More explicit training settings (for fine-tune and continue training).
-
Calculate PCKh@0.5 scores.
-
-
Dataset and preprocess.
-
LSP dataset train and validation.
-
LSPET dataset.
-
Custom dataset.
-
-
Implementation of pose tracking on video.
-
Online camera demo.
If the original paper helps your research, you can cite this paper in the LaTex file with:
@article{Bazarevsky2020BlazePoseOR,
title={BlazePose: On-device Real-time Body Pose tracking},
author={Valentin Bazarevsky and I. Grishchenko and K. Raveendran and Tyler Lixuan Zhu and Fangfang Zhang and M. Grundmann},
journal={ArXiv},
year={2020},
volume={abs/2006.10204}
}
Please feel free to submit an issue or pull a request.