Views
No views yet

1from PIL import Image
2from transformers import AutoModel, AutoImageProcessor
3
4model_path = "moonshotai/MoonViT-SO-400M"
5model = AutoModel.from_pretrained(
6 model_path,
7 torch_dtype="auto",
8 device_map="auto",
9 trust_remote_code=True,
10)
11processor = AutoImageProcessor.from_pretrained(model_path, trust_remote_code=True)
12
13image_path = "./figures/demo.png"
14image = Image.open(image_path)
15
16images_processed = processor(image, return_tensors="pt").to(dtype=model.dtype, device=model.device)
17image_features: list = model(images_processed.pixel_values, images_processed.image_grid_hws)
18
19print(f"dtype: {image_features[0].dtype}, shape: {image_features[0].shape}")
20# dtype: torch.bfloat16, shape: torch.Size([1092, 4, 1152])