Views
No views yet
| Variant | Vision params | Text params | Embed dim | Resolution |
|---|---|---|---|---|
| S/14 | 22M | 34M | 384 | 448 |
| B/14 | 86M | 110M | 768 | 448 |
| L/14 | 304M | 184M | 1024 | 448 |
| So400m/14 | 413M | 448M | 1152 | 448 |
| g/14 | 1.1B | 389M | 1536 | 448 |
| g/14 low-res | 1.1B | 389M | 1536 | 224 |
pip install transformers torch torchvision sentencepiece scikit-learn requests1from transformers import AutoModel
2
3model = AutoModel.from_pretrained("google/tipsv1-g14-lowres", trust_remote_code=True)
4model.eval()[0, 1] range (just ToTensor(), no ImageNet normalization).1import requests
2from PIL import Image
3from torchvision import transforms
4
5url = "https://huggingface.co/spaces/google/TIPSv2/resolve/main/examples/zeroseg/pascal_context_00049_image.png"
6image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
7transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
8pixel_values = transform(image).unsqueeze(0)
9
10out = model.encode_image(pixel_values)
11print(out.cls_token.shape) # (1, 1, 1536) — global image embedding
12print(out.patch_tokens.shape) # (1, 256, 1536) — per-patch spatial featuresout.register_tokens) was trained on synthetic captions; the first (out.cls_token) on web alt-text, and is the one aligned with the text tower.1text_emb = model.encode_text(["a photo of a bus", "a photo of a dog"])
2print(text_emb.shape) # (2, 1536) — 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()]) # predicted class1import numpy as np
2from sklearn.decomposition import PCA
3
4feat = out.patch_tokens[0].detach().cpu().numpy()
5rgb = PCA(n_components=3, whiten=True).fit_transform(feat).reshape(16, 16, 3)
6rgb = 1 / (1 + np.exp(-2.0 * rgb)) # sigmoid for [0, 1] range with good contrast[0, 1], no normalization; SentencePiece tokenizer, lowercased, max 64 tokens1@inproceedings{maninis2025tips,
2 title = {{TIPS: Text-Image Pretraining with Spatial Awareness}},
3 author = {Maninis, Kevis-Kokitsi and Chen, Kaifeng and Ghosh, Soham and Karpur, Arjun and Chen, Koert and Xia, Ye and Cao, Bingyi and Salz, Daniel and Han, Guangxing and Dlabal, Jan and Gnanapragasam, Dan and Seyedhosseini, Mojtaba and Zhou, Howard and Araujo, Andre},
4 booktitle = {International Conference on Learning Representations (ICLR)},
5 year = {2025},
6 url = {https://arxiv.org/abs/2410.16512}
7}