shilinxu commited on
Commit
00ec663
·
verified ·
1 Parent(s): 6c73cc4

Create README.md

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