wangchongyi commited on
Commit
d272cfd
·
1 Parent(s): 73cb2e7

add multi-image infer usage

Browse files
Files changed (1) hide show
  1. README.md +29 -0
README.md CHANGED
@@ -260,6 +260,35 @@ answer = model.chat(
260
  print(answer)
261
  ```
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
  ## License
265
  #### Model License
 
260
  print(answer)
261
  ```
262
 
263
+ #### Chat with multiple images
264
+ <details>
265
+ <summary> Click to show Python code running MiniCPM-V 4.5 with multiple images input. </summary>
266
+
267
+ ```python
268
+ import torch
269
+ from PIL import Image
270
+ from transformers import AutoModel, AutoTokenizer
271
+
272
+ model = AutoModel.from_pretrained('openbmb/MiniCPM-V-4_5', trust_remote_code=True,
273
+ attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2
274
+ model = model.eval().cuda()
275
+ tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-4_5', trust_remote_code=True)
276
+
277
+ image1 = Image.open('image1.jpg').convert('RGB')
278
+ image2 = Image.open('image2.jpg').convert('RGB')
279
+ question = 'Compare image 1 and image 2, tell me about the differences between image 1 and image 2.'
280
+
281
+ msgs = [{'role': 'user', 'content': [image1, image2, question]}]
282
+
283
+ answer = model.chat(
284
+ image=None,
285
+ msgs=msgs,
286
+ tokenizer=tokenizer
287
+ )
288
+ print(answer)
289
+ ```
290
+ </details>
291
+
292
 
293
  ## License
294
  #### Model License