Skip to content

Commit 65b7008

Browse files
committed
initial commit
0 parents  commit 65b7008

22 files changed

+7377
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
model/**/*.caffemodel
2+
model/**/*.h5
3+
model/**/*.npy
4+
dataset/train2017
5+
dataset/val2017
6+
dataset/test2017
7+
dataset/annotations
8+
.idea
9+
__pycache__
10+
.ipynb_checkpoints

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Realtime Multi-Person Pose Estimation
2+
This is a keras version of [Realtime Multi-Person Pose Estimation](https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation) project
3+
4+
## Introduction
5+
Code repo for reproducing [2017 CVPR](https://arxiv.org/abs/1611.08050) paper using keras.
6+
7+
## Results
8+
9+
<p align="center">
10+
<img src="https://github.com/michalfaber/keras_Realtime_Multi-Person_Pose_Estimation/blob/master/readme/dance.gif", width="720">
11+
</p>
12+
13+
<div align="center">
14+
<img src="https://github.com/michalfaber/keras_Realtime_Multi-Person_Pose_Estimation/blob/master/sample_images/ski.jpg", width="300", height="300">
15+
&nbsp;
16+
<img src="https://github.com/michalfaber/keras_Realtime_Multi-Person_Pose_Estimation/blob/master/readme/result.png", width="300", height="300">
17+
</div>
18+
19+
20+
## Contents
21+
1. [Converting caffe model](#converting-caffe-model-to-keras-model)
22+
2. [Testing](#testing-steps)
23+
3. [Training](#training-steps)
24+
25+
## Require
26+
1. [Keras](https://keras.io/)
27+
2. [Caffe - docker](https://hub.docker.com/r/bvlc/caffe/) required if you would like to convert caffe model to keras model. You
28+
don't have to compile/install caffe on your local machine.
29+
30+
## Converting Caffe model to Keras model
31+
Authors of [original implementation](https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation) released already trained caffe model
32+
which you can use to extract weights data.
33+
34+
- Download caffe model `cd model; sh get_caffe_model.sh`
35+
- Dump caffe layers to numpy data `cd ..; docker run -v [absolute path to your keras_Realtime_Multi-Person_Pose_Estimation folder]:/workspace -it bvlc/caffe:cpu python dump_caffe_layers.py`
36+
Note that docker accepts only absolute paths so you have to set the full path to the folder containing this project.
37+
- Convert caffe model (from numpy data) to keras model `python caffe_to_keras.py`
38+
39+
## Testing steps
40+
- Convert caffe model to keras model or download already converted keras model https://www.dropbox.com/s/llpxd14is7gyj0z/model.h5
41+
- Run the notebook `demo.ipynb`.
42+
- `python demo_image.py --image sample_images\ski.jpg` to run the picture demo. Result will be stored in the file result.png. You can use
43+
any image file as an input.
44+
- `python demo_camera.py` to run the web demo.
45+
46+
## Training steps
47+
- Install gsutil `curl https://sdk.cloud.google.com | bash`. This is a really helpful tool for downloading large datasets.
48+
- Download the data set (~25 GB) `cd dataset; sh get_dataset.sh`,
49+
- Download [COCO official toolbox](https://github.com/pdollar/coco) in `dataset/coco/` .
50+
- `cd coco/PythonAPI; sudo python setup.py install` to install pycocotools.
51+
- Run `cd ../..; python train_pose.py` to start training.
52+
53+
## Related repository
54+
- CVPR'16, [Convolutional Pose Machines](https://github.com/shihenw/convolutional-pose-machines-release).
55+
- CVPR'17, [Realtime Multi-Person Pose Estimation](https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation).
56+
57+
## Citation
58+
Please cite the paper in your publications if it helps your research:
59+
60+
@InProceedings{cao2017realtime,
61+
title = {Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields},
62+
author = {Zhe Cao and Tomas Simon and Shih-En Wei and Yaser Sheikh},
63+
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
64+
year = {2017}
65+
}
66+

caffe_to_keras.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from model import get_model
2+
import numpy as np
3+
import os
4+
5+
CAFFE_LAYERS_DIR = "model/caffe/layers"
6+
KERAS_MODEL_FILE = "model/keras/model.h5"
7+
8+
m = get_model()
9+
10+
for layer in m.layers:
11+
layer_name = layer.name
12+
if (os.path.exists(os.path.join(CAFFE_LAYERS_DIR, "W_%s.npy" % layer_name))):
13+
w = np.load(os.path.join(CAFFE_LAYERS_DIR, "W_%s.npy" % layer_name))
14+
b = np.load(os.path.join(CAFFE_LAYERS_DIR, "b_%s.npy" % layer_name))
15+
16+
w = np.transpose(w, (2, 3, 1, 0))
17+
18+
layer_weights = [w, b]
19+
layer.set_weights(layer_weights)
20+
21+
m.save_weights(KERAS_MODEL_FILE)
22+
23+
print("Done !")

config

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[param]
2+
3+
# CPU mode or GPU mode
4+
use_gpu = 1
5+
6+
# GPU device number (doesn't matter for CPU mode)
7+
GPUdeviceNumber = 0
8+
9+
# Select model (default: 1)
10+
modelID = 1
11+
12+
# Look in matlab counterpart for explanation
13+
octave = 3
14+
starting_range = 0.8
15+
ending_range = 2
16+
scale_search = 0.5, 1, 1.5, 2
17+
thre1 = 0.1
18+
thre2 = 0.05
19+
thre3 = 0.5
20+
min_num = 4
21+
mid_num = 10
22+
crop_ratio = 2.5
23+
bbox_ratio = 0.25
24+
25+
[models]
26+
## don't edit this part
27+
28+
[[1]]
29+
caffemodel = './model/_trained_COCO/pose_iter_440000.caffemodel'
30+
deployFile = './model/_trained_COCO/pose_deploy.prototxt'
31+
description = 'COCO Pose56 Two-level Linevec'
32+
boxsize = 368
33+
padValue = 128
34+
np = 12
35+
stride = 8
36+
part_str = [nose, neck, Rsho, Relb, Rwri, Lsho, Lelb, Lwri, Rhip, Rkne, Rank, Lhip, Lkne, Lank, Leye, Reye, Lear, Rear, pt19]

config_reader.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from configobj import ConfigObj
2+
import numpy as np
3+
4+
5+
def config_reader():
6+
config = ConfigObj('config')
7+
8+
param = config['param']
9+
model_id = param['modelID']
10+
model = config['models'][model_id]
11+
model['boxsize'] = int(model['boxsize'])
12+
model['stride'] = int(model['stride'])
13+
model['padValue'] = int(model['padValue'])
14+
#param['starting_range'] = float(param['starting_range'])
15+
#param['ending_range'] = float(param['ending_range'])
16+
param['octave'] = int(param['octave'])
17+
param['use_gpu'] = int(param['use_gpu'])
18+
param['starting_range'] = float(param['starting_range'])
19+
param['ending_range'] = float(param['ending_range'])
20+
param['scale_search'] = map(float, param['scale_search'])
21+
param['thre1'] = float(param['thre1'])
22+
param['thre2'] = float(param['thre2'])
23+
param['thre3'] = float(param['thre3'])
24+
param['mid_num'] = int(param['mid_num'])
25+
param['min_num'] = int(param['min_num'])
26+
param['crop_ratio'] = float(param['crop_ratio'])
27+
param['bbox_ratio'] = float(param['bbox_ratio'])
28+
param['GPUdeviceNumber'] = int(param['GPUdeviceNumber'])
29+
30+
return param, model
31+
32+
if __name__ == "__main__":
33+
config_reader()

dataset/coco/INFO

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Folder for https://github.com/pdollar/coco files

dataset/get_dataset.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Install gsutil which provides tools for efficiently accessing datasets
4+
# without unzipping large files.
5+
# Install gsutil via:curl https://sdk.cloud.google.com | bash
6+
7+
mkdir train2017
8+
mkdir val2017
9+
mkdir test2017
10+
mkdir annotations
11+
12+
echo "Downloading train2017..."
13+
gsutil -m rsync gs://images.cocodataset.org/train2017 train2017
14+
15+
echo "Downloading val2017..."
16+
gsutil -m rsync gs://images.cocodataset.org/val2017 val2017
17+
18+
echo "Downloading test2017..."
19+
gsutil -m rsync gs://images.cocodataset.org/test2017 test2017
20+
21+
echo "Downloading annotations..."
22+
gsutil -m rsync gs://images.cocodataset.org/annotations annotations
23+

0 commit comments

Comments
 (0)