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

Function get_text_embedding

TextOpRobotMDAR/robotmdar/eval/loop_dar.py:53–64  ·  view source on GitHub ↗

Encode text using CLIP model.

(text: str, clip_model, device: str)

Source from the content-addressed store, hash-verified

51
52
53def get_text_embedding(text: str, clip_model, device: str) -> torch.Tensor:
54 """Encode text using CLIP model."""
55 try:
56 with torch.no_grad():
57 text_tokens = clip.tokenize([text]).to(device)
58 text_embedding = clip_model.encode_text(text_tokens)
59 # text_embedding = text_embedding / text_embedding.norm(dim=-1,
60 # keepdim=True)
61 return text_embedding.float()
62 except Exception as e:
63 logger.warning(f"Failed to encode text '{text}': {e}")
64 return torch.zeros(1, 512, device=device, dtype=torch.float32)
65
66
67def interactive_input_thread(loop_state: LoopState):

Callers 2

warmupFunction · 0.70
mainFunction · 0.70

Calls 1

toMethod · 0.80

Tested by

no test coverage detected