Encode text using CLIP model.
(text: str, clip_model, device: str)
| 43 | abs_pose = get_zero_abs_pose((1, ), device=cfg.device) |
| 44 | |
| 45 | def get_text_embedding(text: str, clip_model, device: str) -> torch.Tensor: |
| 46 | """Encode text using CLIP model.""" |
| 47 | try: |
| 48 | with torch.no_grad(): |
| 49 | import clip |
| 50 | text_tokens = clip.tokenize([text]).to(device) |
| 51 | text_embedding = clip_model.encode_text(text_tokens) |
| 52 | # text_embedding = text_embedding / text_embedding.norm( |
| 53 | # dim=-1, keepdim=True) |
| 54 | return text_embedding.float() |
| 55 | except Exception as e: |
| 56 | print(f"Warning: Failed to encode text '{text}': {e}") |
| 57 | return torch.zeros(1, 512, device=device, dtype=torch.float32) |
| 58 | |
| 59 | text_embedding = get_text_embedding("stand", clip_model, cfg.device) |
| 60 | future_motion, motion_dict, abs_pose = generate_next_motion( |