MCPcopy Create free account
hub / github.com/TeleHuman/TextOp / get_text_embedding

Function get_text_embedding

TextOpDeploy/src/textop_ctrl/scripts/rmdar.py:45–57  ·  view source on GitHub ↗

Encode text using CLIP model.

(text: str, clip_model, device: str)

Source from the content-addressed store, hash-verified

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(

Callers 1

warmupFunction · 0.70

Calls 1

toMethod · 0.80

Tested by

no test coverage detected