(text, pre_seq, transl, motion_length)
| 51 | return trans_req |
| 52 | |
| 53 | def infer_motion_diffusion(text, pre_seq, transl, motion_length): |
| 54 | print('start diffusion!') |
| 55 | |
| 56 | motion = torch.zeros(B, motion_length, x_dim).to(device) |
| 57 | motion_mask = torch.ones(B, motion_length).to(device) |
| 58 | motion_length = torch.Tensor([motion_length] * B).long().to(device) |
| 59 | |
| 60 | input = { |
| 61 | 'motion': motion, |
| 62 | 'motion_mask': motion_mask, |
| 63 | 'motion_length': motion_length, |
| 64 | 'motion_metas': [{'text': text}] * B |
| 65 | } |
| 66 | |
| 67 | def preprocess_pre_seq(pre_seq): |
| 68 | pre_seq = (pre_seq - mean) / (std + 1e-6) |
| 69 | return torch.tensor(pre_seq).to(device) |
| 70 | |
| 71 | if pre_seq is not None: |
| 72 | pre_seq = preprocess_pre_seq(pre_seq) |
| 73 | |
| 74 | if transl is not None: |
| 75 | transl = get_transl(transl) |
| 76 | |
| 77 | with torch.no_grad(): |
| 78 | input['inference_kwargs'] = {} |
| 79 | |
| 80 | input['inference_kwargs']['pre_seq'] = pre_seq |
| 81 | input['inference_kwargs']['trans_req'] = transl |
| 82 | |
| 83 | output_new_list = [] |
| 84 | all_output = model(**input) |
| 85 | for i in range(B): |
| 86 | output_new = all_output[i]['pred_motion'] |
| 87 | output_new_list.append(output_new) |
| 88 | output_new = torch.stack(output_new_list, dim=0) |
| 89 | |
| 90 | pred_motion = output_new.cpu().detach().numpy() |
| 91 | pred_motion = pred_motion * std + mean |
| 92 | |
| 93 | return pred_motion |
no test coverage detected