Views
No views yet
| Variant | Vision params | Text params | Embed dim | DPT Heads |
|---|---|---|---|---|
| B/14 | 86M | 110M | 768 | B/14-dpt |
| L/14 | 303M | 184M | 1024 | L/14-dpt |
| SO400m/14 | 412M | 448M | 1152 | SO400m/14-dpt |
| g/14 | 1.1B | 389M | 1536 | g/14-dpt |
pip install transformers torch torchvision sentencepiece scikit-learn1from transformers import AutoModel
2
3model = AutoModel.from_pretrained("google/tipsv2-b14", trust_remote_code=True)
4model.eval()[0, 1] range (just ToTensor(), no ImageNet normalization).1from torchvision import transforms
2from PIL import Image
3import requests
4
5transform = transforms.Compose([
6 transforms.Resize((448, 448)),
7 transforms.ToTensor(),
8])
9
10url = "https://huggingface.co/spaces/google/TIPSv2/resolve/main/examples/zeroseg/pascal_context_00049_image.png"
11image = Image.open(requests.get(url, stream=True).raw)
12pixel_values = transform(image).unsqueeze(0)
13out = model.encode_image(pixel_values)
14
15print(out.cls_token.shape) # (1, 1, 768) — global image embedding
16print(out.patch_tokens.shape) # (1, 1024, 768) — per-patch spatial features1text_emb = model.encode_text(["a photo of a bus", "a photo of a dog"])
2print(text_emb.shape) # (2, 768) — one embedding per query1import torch.nn.functional as F
2
3classes = ["bus", "car", "dog", "cat"]
4cls = F.normalize(out.cls_token[:, 0, :], dim=-1)
5text_emb = F.normalize(model.encode_text(classes), dim=-1)
6similarity = cls @ text_emb.T
7print(classes[similarity.argmax()]) # bus — predicted class1import numpy as np
2from sklearn.decomposition import PCA
3
4spatial = out.patch_tokens.reshape(1, 32, 32, 768)
5feat = spatial[0].detach().cpu().numpy().reshape(-1, 768)
6rgb = PCA(n_components=3, whiten=True).fit_transform(feat).reshape(32, 32, 3)
7rgb = 1 / (1 + np.exp(-2.0 * rgb)) # sigmoid for [0, 1] range with good contrast
8print(rgb.shape) # (32, 32, 3) — PCA of patch features as RGB1model = model.cuda()
2out = model.encode_image(pixel_values.cuda())
3text_emb = model.encode_text(["a city"])[0, 1] (no ImageNet normalization)1@inproceedings{cao2026tipsv2,
2 title = {{TIPSv2: Advancing Vision-Language Pretraining with Enhanced Patch-Text Alignment}},
3 author = {Cao, Bingyi and Chen, Koert and Maninis, Kevis-Kokitsi and Chen, Kaifeng and Karpur, Arjun and Xia, Ye and Dua, Sahil and Dabral, Tanmaya and Han, Guangxing and Han, Bohyung and Ainslie, Joshua and Bewley, Alex and Jacob, Mithun and Wagner, Rene and Ramos, Washington and Choromanski, Krzysztof and Seyedhosseini, Mojtaba and Zhou, Howard and Araujo, Andre},
4 booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
5 year = {2026},
6 url = {https://arxiv.org/abs/2604.12012}
7}