-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathcommon.py
executable file
·135 lines (119 loc) · 4.13 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from enum import Enum
import tensorflow as tf
import cv2
regularizer_conv = 0.004
regularizer_dsconv = 0.0004
batchnorm_fused = True
activation_fn = tf.nn.relu
class CocoPart(Enum):
Nose = 0
Neck = 1
RShoulder = 2
RElbow = 3
RWrist = 4
LShoulder = 5
LElbow = 6
LWrist = 7
RHip = 8
RKnee = 9
RAnkle = 10
LHip = 11
LKnee = 12
LAnkle = 13
REye = 14
LEye = 15
REar = 16
LEar = 17
Background = 18
class MPIIPart(Enum):
RAnkle = 0
RKnee = 1
RHip = 2
LHip = 3
LKnee = 4
LAnkle = 5
RWrist = 6
RElbow = 7
RShoulder = 8
LShoulder = 9
LElbow = 10
LWrist = 11
Neck = 12
Head = 13
@staticmethod
def from_coco(human):
# t = {
# MPIIPart.RAnkle: CocoPart.RAnkle,
# MPIIPart.RKnee: CocoPart.RKnee,
# MPIIPart.RHip: CocoPart.RHip,
# MPIIPart.LHip: CocoPart.LHip,
# MPIIPart.LKnee: CocoPart.LKnee,
# MPIIPart.LAnkle: CocoPart.LAnkle,
# MPIIPart.RWrist: CocoPart.RWrist,
# MPIIPart.RElbow: CocoPart.RElbow,
# MPIIPart.RShoulder: CocoPart.RShoulder,
# MPIIPart.LShoulder: CocoPart.LShoulder,
# MPIIPart.LElbow: CocoPart.LElbow,
# MPIIPart.LWrist: CocoPart.LWrist,
# MPIIPart.Neck: CocoPart.Neck,
# MPIIPart.Nose: CocoPart.Nose,
# }
t = [
(MPIIPart.Head, CocoPart.Nose),
(MPIIPart.Neck, CocoPart.Neck),
(MPIIPart.RShoulder, CocoPart.RShoulder),
(MPIIPart.RElbow, CocoPart.RElbow),
(MPIIPart.RWrist, CocoPart.RWrist),
(MPIIPart.LShoulder, CocoPart.LShoulder),
(MPIIPart.LElbow, CocoPart.LElbow),
(MPIIPart.LWrist, CocoPart.LWrist),
(MPIIPart.RHip, CocoPart.RHip),
(MPIIPart.RKnee, CocoPart.RKnee),
(MPIIPart.RAnkle, CocoPart.RAnkle),
(MPIIPart.LHip, CocoPart.LHip),
(MPIIPart.LKnee, CocoPart.LKnee),
(MPIIPart.LAnkle, CocoPart.LAnkle),
]
pose_2d_mpii = []
visibilty = []
for mpi, coco in t:
if coco.value not in human.body_parts.keys():
pose_2d_mpii.append((0, 0))
visibilty.append(False)
continue
pose_2d_mpii.append((human.body_parts[coco.value].x, human.body_parts[coco.value].y))
visibilty.append(True)
return pose_2d_mpii, visibilty
CocoPairs = [
(1, 2), (1, 5), (2, 3), (3, 4), (5, 6), (6, 7), (1, 8), (8, 9), (9, 10), (1, 11),
(11, 12), (12, 13), (1, 0), (0, 14), (14, 16), (0, 15), (15, 17), (2, 16), (5, 17)
] # = 19
CocoPairsRender = CocoPairs[:-2]
# CocoPairsNetwork = [
# (12, 13), (20, 21), (14, 15), (16, 17), (22, 23), (24, 25), (0, 1), (2, 3), (4, 5),
# (6, 7), (8, 9), (10, 11), (28, 29), (30, 31), (34, 35), (32, 33), (36, 37), (18, 19), (26, 27)
# ] # = 19
CocoColors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0],
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]
def read_imgfile(path, width=None, height=None):
val_image = cv2.imread(path, cv2.IMREAD_COLOR)
if width is not None and height is not None:
val_image = cv2.resize(val_image, (width, height))
return val_image
def get_sample_images(w, h):
val_image = [
read_imgfile('../images/p1.jpg', w, h),
read_imgfile('../images/p2.jpg', w, h),
read_imgfile('../images/p3.jpg', w, h),
read_imgfile('../images/golf.jpg', w, h),
read_imgfile('../images/hand1.jpg', w, h),
read_imgfile('../images/hand2.jpg', w, h),
read_imgfile('../images/apink1_crop.jpg', w, h),
read_imgfile('../images/ski.jpg', w, h),
read_imgfile('../images/apink2.jpg', w, h),
read_imgfile('../images/apink3.jpg', w, h),
read_imgfile('../images/handsup1.jpg', w, h),
read_imgfile('../images/p3_dance.png', w, h),
]
return val_image