import torch from PIL import Image from colpaliengine.models import ColQwen2,…
- User
import torch from PIL import Image
from colpali_engine.models import ColQwen2, ColQwen2Processor
model = ColQwen2.from_pretrained( "vidore/colqwen2-v0.1", torch_dtype=torch.bfloat16, device_map="cuda:0", # or "mps" if on Apple Silicon ).eval() processor = ColQwen2Processor.from_pretrained("vidore/colqwen2-v0.1")
Your inputs
images = [ Image.new("RGB", (32, 32), color="white"), Image.new("RGB", (16, 16), color="black"), ] queries = [ "Is attention really all you need?", "What is the amount of bananas farmed in Salvador?", ]
Process the inputs
batch_images = processor.process_images(images).to(model.device) batch_queries = processor.process_queries(queries).to(model.device)
Forward pass
with torch.no_grad(): image_embeddings = model(**batch_images) query_embeddings = model(**batch_queries)
scores = processor.score_multi_vector(query_embeddings, image_embeddings)
what is happening here?
- Assistant