(motions, outdir='test_vis', device_id=0, name=None, render_video=False)
| 46 | return P |
| 47 | |
| 48 | def render(motions, outdir='test_vis', device_id=0, name=None, render_video=False): |
| 49 | frames, njoints, nfeats = motions.shape |
| 50 | MINS = motions.min(axis=0).min(axis=0) |
| 51 | MAXS = motions.max(axis=0).max(axis=0) |
| 52 | |
| 53 | height_offset = MINS[1] |
| 54 | motions[:, :, 1] -= height_offset |
| 55 | trajec = motions[:, 0, [0, 2]] |
| 56 | |
| 57 | j2s = joints2smpl(num_frames=frames, device_id=device_id, cuda=True) |
| 58 | rot2xyz = Rotation2xyz(device=torch.device(f"cuda:{device_id}")) |
| 59 | faces = rot2xyz.smpl_model.faces |
| 60 | |
| 61 | pt_output_path = os.path.join(outdir, f'{name}.pt') |
| 62 | video_output_path = os.path.join(outdir, f'{name}.mp4') |
| 63 | |
| 64 | smplify_time = 0 |
| 65 | if not os.path.exists(pt_output_path): |
| 66 | print(f'Running SMPLify, it may take a few minutes.') |
| 67 | smplify_start = time.time() |
| 68 | |
| 69 | pred_pose, motion_tensor, opt_dict = j2s.joint2smpl(motions) # [nframes, njoints, 3] |
| 70 | |
| 71 | vertices = rot2xyz(motion_tensor.clone().detach(), mask=None, |
| 72 | pose_rep='rot6d', translation=True, glob=True, |
| 73 | jointstype='vertices', |
| 74 | vertstrans=True) |
| 75 | |
| 76 | pred_pose_save = pred_pose.reshape(-1, 24, 3).cpu() |
| 77 | vertices_save = vertices.squeeze(0).permute(2, 0, 1).cpu() |
| 78 | data_to_save = { |
| 79 | 'pose': pred_pose_save, |
| 80 | 'joints': motions, |
| 81 | 'vertices': vertices_save |
| 82 | } |
| 83 | torch.save(data_to_save, pt_output_path) |
| 84 | |
| 85 | smplify_time = time.time() - smplify_start |
| 86 | print(f'SMPLify completed in {smplify_time:.2f} seconds') |
| 87 | else: |
| 88 | print(f'Loading existing SMPLify results from {pt_output_path}') |
| 89 | if render_video: |
| 90 | vertices = torch.load(pt_output_path)['vertices'] |
| 91 | vertices = vertices.permute(1, 2, 0).unsqueeze(0) |
| 92 | |
| 93 | render_time = 0 |
| 94 | if render_video: |
| 95 | print(f'Starting video rendering for {frames} frames...') |
| 96 | render_start = time.time() |
| 97 | |
| 98 | frames = vertices.shape[3] |
| 99 | MINS = torch.min(torch.min(vertices[0], axis=0)[0], axis=1)[0] |
| 100 | MAXS = torch.max(torch.max(vertices[0], axis=0)[0], axis=1)[0] |
| 101 | |
| 102 | # Pre-compute static elements |
| 103 | minx = MINS[0] - 0.5 |
| 104 | maxx = MAXS[0] + 0.5 |
| 105 | minz = MINS[2] - 0.5 |
no outgoing calls
no test coverage detected