Views
No views yet
google/siglip-base-patch16-224 (Extracts rich image features).
| Benchmark | Score | What it means |
|---|---|---|
| MME Perception (Accuracy) | 58.00% | Binary Yes/No evaluation of visual perception. Solidly beats the 50% random chance baseline. |
| MMBench (Logic) | 50.00% | 4-choice visual logic test. Impressively doubles the 25% random chance baseline, proving visual reasoning capabilities! |
model.py, vqa_inference.py, vqa_model.safetensors, and vqa_projector.safetensors.1import torch
2from transformers import AutoTokenizer, AutoModel, AutoProcessor
3from model import GPTModel, VisionProjector, generate_text, text_to_token_ids, token_ids_to_text
4import torch.nn as nn
5from safetensors.torch import load_file
6import json
7from PIL import Image
8import requests
9
10device = "cuda" if torch.cuda.is_available() else "cpu"
11tokenizer = AutoTokenizer.from_pretrained("tokenizer")
12
13# 1. Load Vision Components
14vision_model = AutoModel.from_pretrained("google/siglip-base-patch16-224").to(device)
15image_processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-224")
16vision_model.eval()
17
18vision_projector = VisionProjector().to(device)
19vision_projector.load_state_dict(load_file("vqa_projector.safetensors"))
20vision_projector.eval()
21
22# 2. Load GPT Backend
23with open("tokenizer/config.json") as f:
24 cfg = json.load(f)
25model = GPTModel(cfg).to(device)
26model.load_state_dict(load_file("vqa_model.safetensors"))
27model.eval()
28
29# 3. Process Image
30raw_image = Image.open("llava_002509.jpg").convert("RGB")
31image_tensor = image_processor(images=raw_image, return_tensors="pt")['pixel_values'].to(device)
32
33with torch.no_grad():
34 vision_outputs = vision_model.vision_model(pixel_values=image_tensor)
35 raw_image_features = vision_outputs.pooler_output.unsqueeze(1)
36 image_embeds = vision_projector(raw_image_features)
37
38# 4. Generate
39prompt = (
40 "Below is an instruction that describes a task. "
41 "Write a response that appropriately completes the request.\n\n"
42 "### Instruction:\nWhat is in this image?\n\n### Response:\n"
43)
44encoded = text_to_token_ids(prompt, tokenizer).to(device)
45token_ids = generate_text(
46 model=model,
47 idx=encoded,
48 max_new_tokens=50,
49 context_size=model.pos_emb.weight.shape[0],
50 temperature=0.5,
51 top_k=30,
52 repetition_penalty=1.15,
53 image_embeds=image_embeds
54)
55print(token_ids_to_text(token_ids, tokenizer).split("### Response:\n")[-1])
What is in this image?
The image features a pizza with various toppings, including cheese and pepperoni, placed on top of a plate.