MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / forward

Method forward

clip/model.py:364–378  ·  view source on GitHub ↗
(self, image, text)

Source from the content-addressed store, hash-verified

362 return x
363
364 def forward(self, image, text):
365 image_features = self.encode_image(image)
366 text_features = self.encode_text(text)
367
368 # normalized features
369 image_features = image_features / image_features.norm(dim=-1, keepdim=True)
370 text_features = text_features / text_features.norm(dim=-1, keepdim=True)
371
372 # cosine similarity as logits
373 logit_scale = self.logit_scale.exp()
374 logits_per_image = logit_scale * image_features @ text_features.t()
375 logits_per_text = logit_scale * text_features @ image_features.t()
376
377 # shape = [global_batch_size, global_batch_size]
378 return logits_per_image, logits_per_text
379
380
381def convert_weights(model: nn.Module):

Callers 1

forwardMethod · 0.45

Calls 2

encode_imageMethod · 0.95
encode_textMethod · 0.95

Tested by

no test coverage detected