| 374 | |
| 375 | |
| 376 | class EvaluatorModelWrapper(object): |
| 377 | |
| 378 | def __init__(self, opt): |
| 379 | |
| 380 | if opt.dataset_name == 't2m': |
| 381 | opt.dim_pose = 263 |
| 382 | elif opt.dataset_name == 'kit': |
| 383 | opt.dim_pose = 251 |
| 384 | else: |
| 385 | raise KeyError('Dataset not Recognized!!!') |
| 386 | |
| 387 | opt.dim_word = 300 |
| 388 | opt.max_motion_length = 196 |
| 389 | opt.dim_pos_ohot = len(POS_enumerator) |
| 390 | opt.dim_motion_hidden = 1024 |
| 391 | opt.max_text_len = 20 |
| 392 | opt.dim_text_hidden = 512 |
| 393 | opt.dim_coemb_hidden = 512 |
| 394 | |
| 395 | self.text_encoder, self.motion_encoder, self.movement_encoder = build_models(opt) |
| 396 | self.opt = opt |
| 397 | self.device = opt.device |
| 398 | |
| 399 | self.text_encoder.to(opt.device) |
| 400 | self.motion_encoder.to(opt.device) |
| 401 | self.movement_encoder.to(opt.device) |
| 402 | |
| 403 | self.text_encoder.eval() |
| 404 | self.motion_encoder.eval() |
| 405 | self.movement_encoder.eval() |
| 406 | |
| 407 | # Please note that the results does not following the order of inputs |
| 408 | def get_co_embeddings(self, word_embs, pos_ohot, cap_lens, motions, m_lens): |
| 409 | with torch.no_grad(): |
| 410 | word_embs = word_embs.detach().to(self.device).float() |
| 411 | pos_ohot = pos_ohot.detach().to(self.device).float() |
| 412 | motions = motions.detach().to(self.device).float() |
| 413 | |
| 414 | align_idx = np.argsort(m_lens.data.tolist())[::-1].copy() |
| 415 | motions = motions[align_idx] |
| 416 | m_lens = m_lens[align_idx] |
| 417 | |
| 418 | '''Movement Encoding''' |
| 419 | movements = self.movement_encoder(motions[..., :-4]).detach() |
| 420 | m_lens = m_lens // self.opt.unit_length |
| 421 | motion_embedding = self.motion_encoder(movements, m_lens) |
| 422 | |
| 423 | '''Text Encoding''' |
| 424 | text_embedding = self.text_encoder(word_embs, pos_ohot, cap_lens) |
| 425 | text_embedding = text_embedding[align_idx] |
| 426 | return text_embedding, motion_embedding |
| 427 | |
| 428 | # Please note that the results does not following the order of inputs |
| 429 | def get_motion_embeddings(self, motions, m_lens): |
| 430 | with torch.no_grad(): |
| 431 | motions = motions.detach().to(self.device).float() |
| 432 | |
| 433 | align_idx = np.argsort(m_lens.data.tolist())[::-1].copy() |