Rename smpl->smplpytorch.
This commit is contained in:
0
smplpytorch/native/__init__.py
Normal file
0
smplpytorch/native/__init__.py
Normal file
1
smplpytorch/native/models/README.md
Normal file
1
smplpytorch/native/models/README.md
Normal file
@ -0,0 +1 @@
|
||||
Here copy the .pkl model files.
|
||||
0
smplpytorch/native/webuser/__init__.py
Normal file
0
smplpytorch/native/webuser/__init__.py
Normal file
31
smplpytorch/native/webuser/posemapper.py
Normal file
31
smplpytorch/native/webuser/posemapper.py
Normal file
@ -0,0 +1,31 @@
|
||||
import chumpy as ch
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
class Rodrigues(ch.Ch):
|
||||
dterms = 'rt'
|
||||
|
||||
def compute_r(self):
|
||||
return cv2.Rodrigues(self.rt.r)[0]
|
||||
|
||||
def compute_dr_wrt(self, wrt):
|
||||
if wrt is self.rt:
|
||||
return cv2.Rodrigues(self.rt.r)[1].T
|
||||
|
||||
|
||||
def lrotmin(p):
|
||||
if isinstance(p, np.ndarray):
|
||||
p = p.ravel()[3:]
|
||||
return np.concatenate([(cv2.Rodrigues(np.array(pp))[0] - np.eye(3)).ravel() for pp in p.reshape((-1, 3))]).ravel()
|
||||
if p.ndim != 2 or p.shape[1] != 3:
|
||||
p = p.reshape((-1, 3))
|
||||
p = p[1:]
|
||||
return ch.concatenate([(Rodrigues(pp) - ch.eye(3)).ravel() for pp in p]).ravel()
|
||||
|
||||
|
||||
def posemap(s):
|
||||
if s == 'lrotmin':
|
||||
return lrotmin
|
||||
else:
|
||||
raise Exception('Unknown posemapping: %s' % (str(s),))
|
||||
39
smplpytorch/native/webuser/serialization.py
Normal file
39
smplpytorch/native/webuser/serialization.py
Normal file
@ -0,0 +1,39 @@
|
||||
def ready_arguments(fname_or_dict):
|
||||
import numpy as np
|
||||
import pickle
|
||||
import chumpy as ch
|
||||
from chumpy.ch import MatVecMult
|
||||
from smplpytorch.native.webuser.posemapper import posemap
|
||||
|
||||
if not isinstance(fname_or_dict, dict):
|
||||
dd = pickle.load(open(fname_or_dict, 'rb'), encoding='latin1')
|
||||
# dd = pickle.load(open(fname_or_dict, 'rb'))
|
||||
else:
|
||||
dd = fname_or_dict
|
||||
|
||||
want_shapemodel = 'shapedirs' in dd
|
||||
nposeparms = dd['kintree_table'].shape[1] * 3
|
||||
|
||||
if 'trans' not in dd:
|
||||
dd['trans'] = np.zeros(3)
|
||||
if 'pose' not in dd:
|
||||
dd['pose'] = np.zeros(nposeparms)
|
||||
if 'shapedirs' in dd and 'betas' not in dd:
|
||||
dd['betas'] = np.zeros(dd['shapedirs'].shape[-1])
|
||||
|
||||
for s in ['v_template', 'weights', 'posedirs', 'pose', 'trans', 'shapedirs', 'betas', 'J']:
|
||||
if (s in dd) and not hasattr(dd[s], 'dterms'):
|
||||
dd[s] = ch.array(dd[s])
|
||||
|
||||
if want_shapemodel:
|
||||
dd['v_shaped'] = dd['shapedirs'].dot(dd['betas']) + dd['v_template']
|
||||
v_shaped = dd['v_shaped']
|
||||
J_tmpx = MatVecMult(dd['J_regressor'], v_shaped[:, 0])
|
||||
J_tmpy = MatVecMult(dd['J_regressor'], v_shaped[:, 1])
|
||||
J_tmpz = MatVecMult(dd['J_regressor'], v_shaped[:, 2])
|
||||
dd['J'] = ch.vstack((J_tmpx, J_tmpy, J_tmpz)).T
|
||||
dd['v_posed'] = v_shaped + dd['posedirs'].dot(posemap(dd['bs_type'])(dd['pose']))
|
||||
else:
|
||||
dd['v_posed'] = dd['v_template'] + dd['posedirs'].dot(posemap(dd['bs_type'])(dd['pose']))
|
||||
|
||||
return dd
|
||||
Reference in New Issue
Block a user