MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / _prepare_input_pose

Function _prepare_input_pose

detrsmpl/core/visualization/visualize_smpl.py:204–249  ·  view source on GitHub ↗

Prepare input pose data as tensor and ensure correct temporal slice.

(verts, poses, betas, transl)

Source from the content-addressed store, hash-verified

202
203
204def _prepare_input_pose(verts, poses, betas, transl):
205 """Prepare input pose data as tensor and ensure correct temporal slice."""
206 if verts is None and poses is None:
207 raise ValueError('Please input valid poses or verts.')
208 elif (verts is not None) and (poses is not None):
209 warnings.warn('Redundant input, will take verts and ignore poses & '
210 'betas & transl.')
211 poses = None
212 transl = None
213 betas = None
214 elif isinstance(poses, dict):
215 transl = poses.get('transl', transl)
216 betas = poses.get('betas', betas)
217
218 if isinstance(verts, np.ndarray):
219 verts = torch.Tensor(verts)
220 num_frames = verts.shape[0]
221 elif isinstance(verts, torch.Tensor):
222 num_frames = verts.shape[0]
223
224 if isinstance(poses, np.ndarray):
225 poses = torch.Tensor(poses)
226 num_frames = poses.shape[0]
227 elif isinstance(poses, torch.Tensor):
228 num_frames = poses.shape[0]
229 elif isinstance(poses, dict):
230 for k, v in poses.items():
231 if isinstance(v, np.ndarray):
232 poses[k] = torch.tensor(v)
233 num_frames = poses['body_pose'].shape[0]
234
235 if isinstance(betas, np.ndarray):
236 betas = torch.Tensor(betas)
237
238 if betas is not None:
239 if betas.shape[0] != num_frames:
240 times = num_frames // betas.shape[0]
241 if betas.ndim == 2:
242 betas = betas.repeat(times, 1)[:num_frames]
243 elif betas.ndim == 3:
244 betas = betas.repeat(times, 1, 1)[:num_frames]
245 print(f'betas will be repeated by dim 0 for {times} times.')
246 if isinstance(transl, np.ndarray):
247 transl = torch.Tensor(transl)
248
249 return verts, poses, betas, transl
250
251
252def _prepare_mesh(poses, betas, transl, verts, start, end, body_model):

Callers 1

render_smplFunction · 0.85

Calls 3

printFunction · 0.50
getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected