(self, image, text)
| 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 | |
| 381 | def convert_weights(model: nn.Module): |
no test coverage detected