import os import pickle import torch import numpy as np from psbody.mesh.sphere import Sphere # to_params = lambda x: torch.from_numpy(x).float().to(self.device).requires_grad_(True) # to_torch = lambda x: torch.from_numpy(x).float().to(self.device) def to_params(x, device): return x.to(device).requires_grad_(True) def to_torch(x, device): return torch.from_numpy(x).float().to(device) def to_numpy(x): return x.detach().cpu().numpy() def load_smpl_seq(smpl_seq_path, gender=None, straighten_hands=False): if not os.path.exists(smpl_seq_path): raise Exception('Path does not exist: {}'.format(smpl_seq_path)) if smpl_seq_path.endswith('.pkl'): data_dict = pickle.load(open(smpl_seq_path, 'rb')) elif smpl_seq_path.endswith('.npz'): data_dict = np.load(smpl_seq_path, allow_pickle=True) if data_dict.files == ['pred_smpl_parms', 'verts', 'pred_cam_t']: data_dict = data_dict['pred_smpl_parms'].item()# ['global_orient', 'body_pose', 'body_pose_axis_angle', 'global_orient_axis_angle', 'betas'] else: data_dict = {key: data_dict[key] for key in data_dict.keys()} # convert to python dict else: raise Exception('Unknown file format: {}. Supported formats are .pkl and .npz'.format(smpl_seq_path)) # Instanciate a dictionary with the keys expected by the fitter data_fixed = {} # Get gender if 'gender' not in data_dict: assert gender is not None, f"The provided SMPL data dictionary does not contain gender, you need to pass it in command line" data_fixed['gender'] = gender elif not isinstance(data_dict['gender'], str): # In some npz, the gender type happens to be: array('male', dtype='