This model is a fine-tuned version of the CLIP ViT-H-14 model on the Polaris dataset. The model was trained using one-to-one image-text pairs.
1import torch
2import open_clip
3from PIL import Image
4
5# Load model
6model, _, preprocess = open_clip.create_model_and_transforms('ViT-H-14')
7model.load_state_dict(torch.load('pytorch_model.bin'))
8model.eval()
9
10# Prepare image and text
11image = Image.open('your_image.jpg')
12image = preprocess(image).unsqueeze(0)
13text = "your text description"
14
15# Get embeddings
16with torch.no_grad():
17 image_features = model.encode_image(image)
18 text_features = model.encode_text(text)
19
20 # Normalize features
21 image_features = image_features / image_features.norm(dim=-1, keepdim=True)
22 text_features = text_features / text_features.norm(dim=-1, keepdim=True)
23
24 # Calculate similarity
25 similarity = (image_features @ text_features.t()).item()