MCPcopy
hub / github.com/facebookresearch/MetaCLIP / forward

Method forward

src/mini_clip/model.py:441–455  ·  view source on GitHub ↗
(self, image, text, clamp_logit_scale_to=None)

Source from the content-addressed store, hash-verified

439 return x
440
441 def forward(self, image, text, clamp_logit_scale_to=None):
442 if image is not None:
443 image_features = self.encode_image(image)
444 image_features = F.normalize(image_features, dim=-1)
445 else:
446 image_features = None
447 if text is not None:
448 text_features = self.encode_text(text)
449 text_features = F.normalize(text_features, dim=-1)
450 else:
451 text_features = None
452 if clamp_logit_scale_to is not None:
453 with torch.no_grad():
454 self.logit_scale.data.clamp_(0, clamp_logit_scale_to)
455 return image_features, text_features, self.logit_scale.exp()
456
457
458def convert_weights_to_fp16(model: nn.Module):

Callers

nothing calls this directly

Calls 2

encode_imageMethod · 0.95
encode_textMethod · 0.95

Tested by

no test coverage detected