forked from CalciferZh/SMPL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
55 lines (41 loc) · 1.3 KB
/
test.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
import smpl_tf
import smpl_np
import numpy as np
import tensorflow as tf
def compute_diff(a, b):
"""
Compute the max relative difference between ndarray a and b element-wisely.
Parameters:
----------
a, b: ndarrays to be compared of same shape.
Return:
------
The max relative difference.
"""
return np.max(np.abs(a - b) / np.minimum(a, b))
def tf_wrapper(beta, pose, trans):
beta = tf.constant(beta, dtype=tf.float64)
trans = tf.constant(trans, dtype=tf.float64)
pose = tf.constant(pose, dtype=tf.float64)
output, _ = smpl_tf.smpl_model('./model.pkl', beta, pose, trans)
sess = tf.Session()
result = sess.run(output)
return result
def np_wrapper(beta, pose, trans):
smpl = smpl_np.SMPLModel('./model.pkl')
result = smpl.set_params(pose=pose, beta=beta, trans=trans)
return result
if __name__ == '__main__':
pose_size = 72
beta_size = 10
np.random.seed(9608)
pose = (np.random.rand(pose_size) - 0.5) * 0.4
beta = (np.random.rand(beta_size) - 0.5) * 0.06
trans = np.zeros(3)
tf_result = tf_wrapper(beta, pose, trans)
np_result = np_wrapper(beta, pose, trans)
if np.allclose(np_result, tf_result):
print('Bingo!')
else:
print('Failed')
print(compute_diff(tf_result, np_result))