MCPcopy Create free account
hub / github.com/Adamdad/hash3D / encode_image

Method encode_image

eval_clip_sim.py:19–23  ·  view source on GitHub ↗
(self, image)

Source from the content-addressed store, hash-verified

17 self.processor = CLIPProcessor.from_pretrained(model_name)
18
19 def encode_image(self, image):
20 pixel_values = self.processor(images=image, return_tensors="pt").pixel_values.to(self.device)
21 image_features = self.clip_model.get_image_features(pixel_values=pixel_values)
22 image_features = image_features / image_features.norm(dim=-1, keepdim=True) # normalize features
23 return image_features
24
25 def encode_text(self, text):
26 inputs = self.processor(text=[text], padding=True, return_tensors="pt").to(self.device)

Callers 3

eval_clip_sim.pyFile · 0.80
forwardMethod · 0.80
forwardMethod · 0.80

Calls 1

toMethod · 0.45

Tested by

no test coverage detected