update unposing smpl code based on other script
This commit is contained in:
+11
-10
@@ -22,7 +22,7 @@ eval_joints = {
|
|||||||
|
|
||||||
class SMPL:
|
class SMPL:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, path):
|
||||||
self.J_regressor = []
|
self.J_regressor = []
|
||||||
self.v_template = []
|
self.v_template = []
|
||||||
self.shapedirs = []
|
self.shapedirs = []
|
||||||
@@ -30,7 +30,7 @@ class SMPL:
|
|||||||
self.weights = []
|
self.weights = []
|
||||||
# Load SMPL models
|
# Load SMPL models
|
||||||
# path = os.path.abspath(os.path.dirname(__file__))
|
# path = os.path.abspath(os.path.dirname(__file__))
|
||||||
with open(os.path.join('custom_utils/super_model_f.pkl'), 'rb') as f:
|
with open(os.path.join(path, 'super_model_f.pkl'), 'rb') as f:
|
||||||
if sys.version_info[0]<3:
|
if sys.version_info[0]<3:
|
||||||
female = pickle.load(f)
|
female = pickle.load(f)
|
||||||
else:
|
else:
|
||||||
@@ -40,7 +40,7 @@ class SMPL:
|
|||||||
self.posedirs.append(tf.constant(female['posedirs'], dtype=np.float32))
|
self.posedirs.append(tf.constant(female['posedirs'], dtype=np.float32))
|
||||||
self.shapedirs.append(tf.constant(female['shapedirs'], dtype=np.float32))
|
self.shapedirs.append(tf.constant(female['shapedirs'], dtype=np.float32))
|
||||||
self.weights.append(tf.constant(female['weights'], dtype=np.float32))
|
self.weights.append(tf.constant(female['weights'], dtype=np.float32))
|
||||||
with open(os.path.join('custom_utils/super_model_m.pkl'), 'rb') as f:
|
with open(os.path.join(path, 'super_model_m.pkl'), 'rb') as f:
|
||||||
if sys.version_info[0]<3:
|
if sys.version_info[0]<3:
|
||||||
male = pickle.load(f)
|
male = pickle.load(f)
|
||||||
else:
|
else:
|
||||||
@@ -63,11 +63,11 @@ class SMPL:
|
|||||||
self.weights_one_hot = tf.one_hot(self.weights_one_hot, 24)
|
self.weights_one_hot = tf.one_hot(self.weights_one_hot, 24)
|
||||||
|
|
||||||
# Topology no head/hands/feet
|
# Topology no head/hands/feet
|
||||||
F = sio.loadmat('custom_utils/ssmpl_faces.mat')
|
F = sio.loadmat(path + '/ssmpl_faces.mat')
|
||||||
self.f = np.array(F['faces_default'])
|
self.f = np.array(F['faces_default'])
|
||||||
self.f_skirt = np.array(F['faces_skirt'])
|
self.f_skirt = np.array(F['faces_skirt'])
|
||||||
self.nn = np.array(sio.loadmat('custom_utils/NN.mat'))
|
self.nn = np.array(sio.loadmat(path + '/NN.mat'))
|
||||||
self.to_keep = sio.loadmat(os.path.join('custom_utils/keep_remove.mat'))['keep'].reshape(-1)
|
self.to_keep = sio.loadmat(os.path.join(path, 'keep_remove.mat'))['keep'].reshape(-1)
|
||||||
|
|
||||||
self.weights = tf.gather(self.weights, self.to_keep, axis=1)
|
self.weights = tf.gather(self.weights, self.to_keep, axis=1)
|
||||||
# self.shapedirs = tf.gather(self.shapedirs, self.to_keep, axis=1)
|
# self.shapedirs = tf.gather(self.shapedirs, self.to_keep, axis=1)
|
||||||
@@ -246,14 +246,13 @@ class SMPL:
|
|||||||
return J
|
return J
|
||||||
|
|
||||||
|
|
||||||
def run_garment(self, pose, betas, gender, v_cloth, filter=None):
|
def run_garment(self, R, betas, gender, v_cloth, filter_idx=None):
|
||||||
batch_size = v_cloth.shape[0]
|
batch_size = v_cloth.shape[0]
|
||||||
|
|
||||||
J = self.get_joints_template(betas, gender, batch_size)
|
J = self.get_joints_template(betas, gender, batch_size)
|
||||||
R = self.run_rodrigues(pose)
|
|
||||||
|
|
||||||
if filter is not None:
|
if filter_idx is not None:
|
||||||
weights = tf.boolean_mask(self.weights, filter, axis=1)
|
weights = tf.gather(self.weights, filter_idx, axis=1)
|
||||||
|
|
||||||
R_cube_big = R
|
R_cube_big = R
|
||||||
results = []
|
results = []
|
||||||
@@ -274,6 +273,8 @@ class SMPL:
|
|||||||
v = tf.reshape(v, (batch_size, -1, 4))[:, :, :3]
|
v = tf.reshape(v, (batch_size, -1, 4))[:, :, :3]
|
||||||
|
|
||||||
J_out = tf.squeeze(J)
|
J_out = tf.squeeze(J)
|
||||||
|
if J.shape[0] == 1:
|
||||||
|
J_out = J_out[tf.newaxis, :, :]
|
||||||
J0 = tf.reshape(J_out[:,0,:], (-1, 1, 3))
|
J0 = tf.reshape(J_out[:,0,:], (-1, 1, 3))
|
||||||
J_out = tf.subtract(J_out, J0)
|
J_out = tf.subtract(J_out, J0)
|
||||||
T_out = tf.subtract(v, J0)
|
T_out = tf.subtract(v, J0)
|
||||||
|
|||||||
Reference in New Issue
Block a user