motion: B, T, D timesteps: [batch_size] (int)
(self, motion, timesteps, text_feat=None, **kwargs)
| 138 | return motion |
| 139 | |
| 140 | def forward(self, motion, timesteps, text_feat=None, **kwargs): |
| 141 | """ |
| 142 | motion: B, T, D |
| 143 | timesteps: [batch_size] (int) |
| 144 | """ |
| 145 | B, T, D = motion.shape |
| 146 | if text_feat is None: |
| 147 | enc_text = self.get_precompute_condition(**kwargs)['text_feat'] |
| 148 | else: |
| 149 | enc_text = text_feat |
| 150 | if self.training: |
| 151 | # T, B, D |
| 152 | motion = self.poseEmbedding(motion).permute(1, 0, 2) |
| 153 | |
| 154 | emb = self.embed_timestep(timesteps) # [1, bs, d] |
| 155 | emb += self.embed_text(self.mask_cond(enc_text, force_mask=False)) |
| 156 | |
| 157 | xseq = self.sequence_pos_encoder(torch.cat((emb, motion), axis=0)) |
| 158 | output = self.seqTransEncoder(xseq)[1:] |
| 159 | |
| 160 | # B, T, D |
| 161 | output = self.poseFinal(output).permute(1, 0, 2) |
| 162 | return output |
| 163 | else: |
| 164 | # T, B, D |
| 165 | motion = self.poseEmbedding(motion).permute(1, 0, 2) |
| 166 | |
| 167 | emb = self.embed_timestep(timesteps) # [1, bs, d] |
| 168 | emb_uncond = emb + \ |
| 169 | self.embed_text(self.mask_cond(enc_text, force_mask=True)) |
| 170 | emb_text = emb + \ |
| 171 | self.embed_text(self.mask_cond(enc_text, force_mask=False)) |
| 172 | |
| 173 | xseq = self.sequence_pos_encoder( |
| 174 | torch.cat((emb_uncond, motion), axis=0)) |
| 175 | xseq_text = self.sequence_pos_encoder( |
| 176 | torch.cat((emb_text, motion), axis=0)) |
| 177 | output = self.seqTransEncoder(xseq)[1:] |
| 178 | output_text = self.seqTransEncoder(xseq_text)[1:] |
| 179 | # B, T, D |
| 180 | output = self.poseFinal(output).permute(1, 0, 2) |
| 181 | output_text = self.poseFinal(output_text).permute(1, 0, 2) |
| 182 | scale = self.guide_scale |
| 183 | output = output + scale * (output_text - output) |
| 184 | return output |
| 185 | |
| 186 | |
| 187 | class PositionalEncoding(nn.Module): |
nothing calls this directly
no test coverage detected