czczup commited on
Commit
d1a7f0a
1 Parent(s): f0bf9a7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -2
README.md CHANGED
@@ -43,10 +43,38 @@ It is _**the largest open-source vision/vision-language foundation model (14B)**
43
 
44
  We will provide a minimum code example to run InternVL-Chat using only the `transformers` library.
45
 
46
- Before this is completed, you can use our [online demo](https://internvl.opengvlab.com/) for a quick experience of this model.
47
 
48
  ```python
49
- TODO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  ```
51
 
52
  ## Examples
 
43
 
44
  We will provide a minimum code example to run InternVL-Chat using only the `transformers` library.
45
 
46
+ You also can use our [online demo](https://internvl.opengvlab.com/) for a quick experience of this model.
47
 
48
  ```python
49
+ import torch
50
+ from PIL import Image
51
+ from transformers import AutoModel, CLIPImageProcessor
52
+ from transformers import AutoTokenizer
53
+
54
+ path = "OpenGVLab/InternVL-Chat-Chinese-V1-1"
55
+ model = AutoModel.from_pretrained(
56
+ path,
57
+ torch_dtype=torch.bfloat16,
58
+ low_cpu_mem_usage=True,
59
+ trust_remote_code=True,
60
+ device_map='auto').eval()
61
+
62
+ tokenizer = AutoTokenizer.from_pretrained(path)
63
+ image = Image.open('./examples/image2.jpg').convert('RGB')
64
+ image = image.resize((448, 448))
65
+ image_processor = CLIPImageProcessor.from_pretrained(path)
66
+
67
+ pixel_values = image_processor(images=image, return_tensors='pt').pixel_values
68
+ pixel_values = pixel_values.to(torch.bfloat16).cuda()
69
+
70
+ generation_config = dict(
71
+ num_beams=1,
72
+ max_new_tokens=512,
73
+ do_sample=False,
74
+ )
75
+
76
+ question = "请详细描述图片"
77
+ response = model.chat(tokenizer, pixel_values, question, generation_config)
78
  ```
79
 
80
  ## Examples