| 54 | |
| 55 | @ARCHITECTURES.register_module() |
| 56 | class MotionDiffusion(BaseArchitecture): |
| 57 | |
| 58 | def __init__(self, |
| 59 | model=None, |
| 60 | loss_recon=None, |
| 61 | loss_reduction="frame", |
| 62 | diffusion_train=None, |
| 63 | diffusion_test=None, |
| 64 | sampler_type='uniform', |
| 65 | init_cfg=None, |
| 66 | inference_type='ddpm', |
| 67 | **kwargs): |
| 68 | super().__init__(init_cfg=init_cfg, **kwargs) |
| 69 | self.model = build_submodule(model) |
| 70 | self.loss_recon = build_loss(loss_recon) |
| 71 | self.diffusion_train = build_diffusion(diffusion_train) |
| 72 | self.diffusion_test = build_diffusion(diffusion_test) |
| 73 | self.sampler = create_named_schedule_sampler(sampler_type, |
| 74 | self.diffusion_train) |
| 75 | self.inference_type = inference_type |
| 76 | self.loss_reduction = loss_reduction |
| 77 | |
| 78 | def forward(self, **kwargs): |
| 79 | motion = kwargs['motion'].float() |
| 80 | motion_mask = kwargs['motion_mask'].float() |
| 81 | motion_length = kwargs['motion_length'] |
| 82 | num_intervals = kwargs.get('num_intervals', 1) |
| 83 | sample_idx = kwargs.get('sample_idx', None) |
| 84 | clip_feat = kwargs.get('clip_feat', None) |
| 85 | B, T = motion.shape[:2] |
| 86 | text = [] |
| 87 | for i in range(B): |
| 88 | text.append(kwargs['motion_metas'][i]['text']) |
| 89 | |
| 90 | if self.training: |
| 91 | t, _ = self.sampler.sample(B, motion.device) |
| 92 | output = self.diffusion_train.training_losses(model=self.model, |
| 93 | x_start=motion, |
| 94 | t=t, |
| 95 | model_kwargs={ |
| 96 | 'motion_mask': |
| 97 | motion_mask, |
| 98 | 'motion_length': |
| 99 | motion_length, |
| 100 | 'text': |
| 101 | text, |
| 102 | 'clip_feat': |
| 103 | clip_feat, |
| 104 | 'sample_idx': |
| 105 | sample_idx, |
| 106 | 'num_intervals': |
| 107 | num_intervals |
| 108 | }) |
| 109 | pred, target = output['pred'], output['target'] |
| 110 | recon_loss = self.loss_recon(pred, |
| 111 | target, |
| 112 | reduction_override='none') |
| 113 |
nothing calls this directly
no outgoing calls
no test coverage detected