Spaces:
Build error
Build error
Create core/constants.py
Browse files- lib/pymaf/core/constants.py +153 -0
lib/pymaf/core/constants.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This script is borrowed and extended from https://github.com/nkolot/SPIN/blob/master/constants.py
|
2 |
+
FOCAL_LENGTH = 5000.
|
3 |
+
IMG_RES = 224
|
4 |
+
|
5 |
+
# Mean and standard deviation for normalizing input image
|
6 |
+
IMG_NORM_MEAN = [0.485, 0.456, 0.406]
|
7 |
+
IMG_NORM_STD = [0.229, 0.224, 0.225]
|
8 |
+
"""
|
9 |
+
We create a superset of joints containing the OpenPose joints together with the ones that each dataset provides.
|
10 |
+
We keep a superset of 24 joints such that we include all joints from every dataset.
|
11 |
+
If a dataset doesn't provide annotations for a specific joint, we simply ignore it.
|
12 |
+
The joints used here are the following:
|
13 |
+
"""
|
14 |
+
JOINT_NAMES = [
|
15 |
+
# 25 OpenPose joints (in the order provided by OpenPose)
|
16 |
+
'OP Nose',
|
17 |
+
'OP Neck',
|
18 |
+
'OP RShoulder',
|
19 |
+
'OP RElbow',
|
20 |
+
'OP RWrist',
|
21 |
+
'OP LShoulder',
|
22 |
+
'OP LElbow',
|
23 |
+
'OP LWrist',
|
24 |
+
'OP MidHip',
|
25 |
+
'OP RHip',
|
26 |
+
'OP RKnee',
|
27 |
+
'OP RAnkle',
|
28 |
+
'OP LHip',
|
29 |
+
'OP LKnee',
|
30 |
+
'OP LAnkle',
|
31 |
+
'OP REye',
|
32 |
+
'OP LEye',
|
33 |
+
'OP REar',
|
34 |
+
'OP LEar',
|
35 |
+
'OP LBigToe',
|
36 |
+
'OP LSmallToe',
|
37 |
+
'OP LHeel',
|
38 |
+
'OP RBigToe',
|
39 |
+
'OP RSmallToe',
|
40 |
+
'OP RHeel',
|
41 |
+
# 24 Ground Truth joints (superset of joints from different datasets)
|
42 |
+
'Right Ankle',
|
43 |
+
'Right Knee',
|
44 |
+
'Right Hip', # 2
|
45 |
+
'Left Hip',
|
46 |
+
'Left Knee', # 4
|
47 |
+
'Left Ankle',
|
48 |
+
'Right Wrist', # 6
|
49 |
+
'Right Elbow',
|
50 |
+
'Right Shoulder', # 8
|
51 |
+
'Left Shoulder',
|
52 |
+
'Left Elbow', # 10
|
53 |
+
'Left Wrist',
|
54 |
+
'Neck (LSP)', # 12
|
55 |
+
'Top of Head (LSP)',
|
56 |
+
'Pelvis (MPII)', # 14
|
57 |
+
'Thorax (MPII)',
|
58 |
+
'Spine (H36M)', # 16
|
59 |
+
'Jaw (H36M)',
|
60 |
+
'Head (H36M)', # 18
|
61 |
+
'Nose',
|
62 |
+
'Left Eye',
|
63 |
+
'Right Eye',
|
64 |
+
'Left Ear',
|
65 |
+
'Right Ear'
|
66 |
+
]
|
67 |
+
|
68 |
+
# Dict containing the joints in numerical order
|
69 |
+
JOINT_IDS = {JOINT_NAMES[i]: i for i in range(len(JOINT_NAMES))}
|
70 |
+
|
71 |
+
# Map joints to SMPL joints
|
72 |
+
JOINT_MAP = {
|
73 |
+
'OP Nose': 24,
|
74 |
+
'OP Neck': 12,
|
75 |
+
'OP RShoulder': 17,
|
76 |
+
'OP RElbow': 19,
|
77 |
+
'OP RWrist': 21,
|
78 |
+
'OP LShoulder': 16,
|
79 |
+
'OP LElbow': 18,
|
80 |
+
'OP LWrist': 20,
|
81 |
+
'OP MidHip': 0,
|
82 |
+
'OP RHip': 2,
|
83 |
+
'OP RKnee': 5,
|
84 |
+
'OP RAnkle': 8,
|
85 |
+
'OP LHip': 1,
|
86 |
+
'OP LKnee': 4,
|
87 |
+
'OP LAnkle': 7,
|
88 |
+
'OP REye': 25,
|
89 |
+
'OP LEye': 26,
|
90 |
+
'OP REar': 27,
|
91 |
+
'OP LEar': 28,
|
92 |
+
'OP LBigToe': 29,
|
93 |
+
'OP LSmallToe': 30,
|
94 |
+
'OP LHeel': 31,
|
95 |
+
'OP RBigToe': 32,
|
96 |
+
'OP RSmallToe': 33,
|
97 |
+
'OP RHeel': 34,
|
98 |
+
'Right Ankle': 8,
|
99 |
+
'Right Knee': 5,
|
100 |
+
'Right Hip': 45,
|
101 |
+
'Left Hip': 46,
|
102 |
+
'Left Knee': 4,
|
103 |
+
'Left Ankle': 7,
|
104 |
+
'Right Wrist': 21,
|
105 |
+
'Right Elbow': 19,
|
106 |
+
'Right Shoulder': 17,
|
107 |
+
'Left Shoulder': 16,
|
108 |
+
'Left Elbow': 18,
|
109 |
+
'Left Wrist': 20,
|
110 |
+
'Neck (LSP)': 47,
|
111 |
+
'Top of Head (LSP)': 48,
|
112 |
+
'Pelvis (MPII)': 49,
|
113 |
+
'Thorax (MPII)': 50,
|
114 |
+
'Spine (H36M)': 51,
|
115 |
+
'Jaw (H36M)': 52,
|
116 |
+
'Head (H36M)': 53,
|
117 |
+
'Nose': 24,
|
118 |
+
'Left Eye': 26,
|
119 |
+
'Right Eye': 25,
|
120 |
+
'Left Ear': 28,
|
121 |
+
'Right Ear': 27
|
122 |
+
}
|
123 |
+
|
124 |
+
# Joint selectors
|
125 |
+
# Indices to get the 14 LSP joints from the 17 H36M joints
|
126 |
+
H36M_TO_J17 = [6, 5, 4, 1, 2, 3, 16, 15, 14, 11, 12, 13, 8, 10, 0, 7, 9]
|
127 |
+
H36M_TO_J14 = H36M_TO_J17[:14]
|
128 |
+
# Indices to get the 14 LSP joints from the ground truth joints
|
129 |
+
J24_TO_J17 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 18, 14, 16, 17]
|
130 |
+
J24_TO_J14 = J24_TO_J17[:14]
|
131 |
+
J24_TO_J19 = J24_TO_J17[:14] + [19, 20, 21, 22, 23]
|
132 |
+
J24_TO_JCOCO = [19, 20, 21, 22, 23, 9, 8, 10, 7, 11, 6, 3, 2, 4, 1, 5, 0]
|
133 |
+
|
134 |
+
# Permutation of SMPL pose parameters when flipping the shape
|
135 |
+
SMPL_JOINTS_FLIP_PERM = [
|
136 |
+
0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 15, 17, 16, 19, 18, 21,
|
137 |
+
20, 23, 22
|
138 |
+
]
|
139 |
+
SMPL_POSE_FLIP_PERM = []
|
140 |
+
for i in SMPL_JOINTS_FLIP_PERM:
|
141 |
+
SMPL_POSE_FLIP_PERM.append(3 * i)
|
142 |
+
SMPL_POSE_FLIP_PERM.append(3 * i + 1)
|
143 |
+
SMPL_POSE_FLIP_PERM.append(3 * i + 2)
|
144 |
+
# Permutation indices for the 24 ground truth joints
|
145 |
+
J24_FLIP_PERM = [
|
146 |
+
5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 12, 13, 14, 15, 16, 17, 18, 19, 21,
|
147 |
+
20, 23, 22
|
148 |
+
]
|
149 |
+
# Permutation indices for the full set of 49 joints
|
150 |
+
J49_FLIP_PERM = [0, 1, 5, 6, 7, 2, 3, 4, 8, 12, 13, 14, 9, 10, 11, 16, 15, 18, 17, 22, 23, 24, 19, 20, 21]\
|
151 |
+
+ [25+i for i in J24_FLIP_PERM]
|
152 |
+
SMPL_J49_FLIP_PERM = [0, 1, 5, 6, 7, 2, 3, 4, 8, 12, 13, 14, 9, 10, 11, 16, 15, 18, 17, 22, 23, 24, 19, 20, 21]\
|
153 |
+
+ [25+i for i in SMPL_JOINTS_FLIP_PERM]
|