Views
No views yet
1conda create -n univitar python=3.11 -y
2conda activate univitar
3pip3 install einops==0.8.0 ninja==1.11.1.1 numpy==1.26.4 pillow==10.4.0 psutil==6.0.0 torch==2.2.2 torchvision==0.17.2 transformers==4.49.0 timm==1.0.14
4pip3 install flash-attn==2.6.31import torch
2import numpy as np
3from PIL import Image
4from modeling_univitar import UniViTARVisionModel
5
6# Prepare Model
7model = UniViTARVisionModel("config.json")
8_ = model.load_state_dict(torch.load(f"pytorch_model.bin", map_location="cpu"))
9model = model.to(torch.bfloat16).cuda()
10
11# Prepare Data: [(3, H1, W1), ..., (3, Hn, Wn)] --> (N1+...+Nn, P)
12images = [Image.open(f"xx1.jpg"), Image.open(f"xx2.jpg")]
13data_inputs, grid_shapes = [], []
14for image in images:
15 data_item = model.image_transform(image)
16 input_data, grid_shape = model.data_patchify(data_item)
17 data_inputs.append(input_data.to(torch.bfloat16).cuda())
18 grid_shapes.append(grid_shape)
19data_inputs = torch.concatenate(data_inputs, dim=0)
20
21# Forward: (N1+...+Nn, P) --> [(N1, D), ..., (Nn, D)]
22data_embeds = model(pixel_values=data_inputs, grid_shapes=grid_shapes)
23data_embeds = data_embeds.split([np.prod(grid_shape) for grid_shape in grid_shapes])
24print(data_embeds[0].shape, data_embeds[1].shape)| Model | Size | #Seen | IN1KZS | IN1KLP | FlickrT2I | FlickrI2T | K400ZS | ADE20K |
|---|---|---|---|---|---|---|---|---|
| UniViTAR-0.3B | 310M | 14.6B | 81.5 | 87.7 | 84.0 | 95.1 | 66.0 | 54.6 |
| UniViTAR-0.6B | 637M | 14.6B | 82.3 | 88.3 | 84.1 | 95.5 | 68.6 | 55.1 |
| UniViTAR-1B | 1419M | 14.6B | 82.9 | 89.2 | 83.5 | 95.1 | 69.0 | 56.2 |
@article{qiao2025univitar,
title={UniViTAR: Unified Vision Transformer with Native Resolution},
author={Qiao, Limeng and Gan, Yiyang and Wang, Bairui and Qin, Jie and Xu, Shuang and Yang, Siqi and Ma, Lin},
journal={arXiv preprint arXiv:2504.01792},
year={2025}
}