Views
No views yet
from clip.evaluate.utils import (
get_text_batch, get_image_batch, get_tokenizer,
show_test_images, load_weights_only
)
import torch
# Load model and tokenizer
model, args = load_weights_only("ViT-B/32-small")
model = model.cuda().float().eval()
tokenizer = get_tokenizer()
# Load test images and prepare for model
images, texts = show_test_images(args)
input_ids, attention_mask = get_text_batch(["Это " + desc for desc in texts], tokenizer, args)
img_input = get_image_batch(images, args.img_transform, args)
# Call model
with torch.no_grad():
logits_per_image, logits_per_text = model(
img_input={"x": img_input},
text_input={"x": input_ids, "attention_mask": attention_mask}
)