-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_clip.py
36 lines (27 loc) · 1.19 KB
/
test_clip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
from transformers import CLIPVisionModel, CLIPImageProcessor, CLIPVisionConfig, CLIPProcessor
# 可参考:https://colab.research.google.com/drive/1pPHiwHUnM3zmTLtMcNL2zTu2M6FdKtRK?usp=sharing
# ====================
# 加载模型和图像处理器
model = CLIPVisionModel.from_pretrained("openai/clip-vit-large-patch14-336", cache_dir="/data/gongoubo/VQA/LLaVA//model_hub/")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14-336")
print(processor)
# ====================
# ====================
# 读取图片
img_path = "/data/gongoubo/VQA/LLaVA/llava/serve/examples/waterview.jpg"
from PIL import Image
image = Image.open(img_path).convert('RGB')
print(np.array(image).shape)
image = processor(images=image, return_tensors='pt')
print(image["pixel_values"].shape)
output = model(image["pixel_values"], output_hidden_states=True)
print(len(output.hidden_states))
print(output.hidden_states[-1].shape)
# ====================
# =====================
# apt install jupyter-core
# pip install notebook
# jupyter notebook --port 7767 --allow-root --ip=192.168.16.6
# =====================
# <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1000x667 at 0x7FE6A3304220>