|
a |
|
b/dummy_pose_estimation.py |
|
|
1 |
import numpy as np |
|
|
2 |
import matplotlib as mpl |
|
|
3 |
mpl.use('Agg') |
|
|
4 |
import matplotlib.pyplot as plt |
|
|
5 |
from scipy.misc import imresize, imread |
|
|
6 |
|
|
|
7 |
from human_pose_nn import HumanPoseIRNetwork |
|
|
8 |
|
|
|
9 |
net_pose = HumanPoseIRNetwork() |
|
|
10 |
net_pose.restore('models/MPII+LSP.ckpt') |
|
|
11 |
|
|
|
12 |
img = imread('images/dummy.jpg') |
|
|
13 |
img = imresize(img, [299, 299]) |
|
|
14 |
img_batch = np.expand_dims(img, 0) |
|
|
15 |
|
|
|
16 |
y, x, a = net_pose.estimate_joints(img_batch) |
|
|
17 |
y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a) |
|
|
18 |
|
|
|
19 |
joint_names = [ |
|
|
20 |
'right ankle ', |
|
|
21 |
'right knee ', |
|
|
22 |
'right hip', |
|
|
23 |
'left hip', |
|
|
24 |
'left knee', |
|
|
25 |
'left ankle', |
|
|
26 |
'pelvis', |
|
|
27 |
'thorax', |
|
|
28 |
'upper neck', |
|
|
29 |
'head top', |
|
|
30 |
'right wrist', |
|
|
31 |
'right elbow', |
|
|
32 |
'right shoulder', |
|
|
33 |
'left shoulder', |
|
|
34 |
'left elbow', |
|
|
35 |
'left wrist' |
|
|
36 |
] |
|
|
37 |
|
|
|
38 |
# Print probabilities of each estimation |
|
|
39 |
for i in range(16): |
|
|
40 |
print('%s: %.02f%%' % (joint_names[i], a[i] * 100)) |
|
|
41 |
|
|
|
42 |
# Create image |
|
|
43 |
colors = ['r', 'r', 'b', 'm', 'm', 'y', 'g', 'g', 'b', 'c', 'r', 'r', 'b', 'm', 'm', 'c'] |
|
|
44 |
for i in range(16): |
|
|
45 |
if i < 15 and i not in {5, 9}: |
|
|
46 |
plt.plot([x[i], x[i + 1]], [y[i], y[i + 1]], color = colors[i], linewidth = 5) |
|
|
47 |
|
|
|
48 |
plt.imshow(img) |
|
|
49 |
plt.savefig('images/dummy_pose.jpg') |