Views
No views yet

1import torch
2import transformers
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from PIL import Image
5import warnings
6
7# disable some warnings
8transformers.logging.set_verbosity_error()
9transformers.logging.disable_progress_bar()
10warnings.filterwarnings('ignore')
11
12# set device
13torch.set_default_device('cuda') # or 'cpu'
14
15model_name = 'cognitivecomputations/dolphin-vision-72b'
16
17# create model
18model = AutoModelForCausalLM.from_pretrained(
19 model_name,
20 torch_dtype=torch.float16,
21 device_map='auto',
22 trust_remote_code=True)
23tokenizer = AutoTokenizer.from_pretrained(
24 model_name,
25 trust_remote_code=True)
26
27# text prompt
28prompt = 'Describe this image in detail'
29
30messages = [
31 {"role": "user", "content": f'<image>\n{prompt}'}
32]
33text = tokenizer.apply_chat_template(
34 messages,
35 tokenize=False,
36 add_generation_prompt=True
37)
38
39print(text)
40
41text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
42input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
43
44# image, sample images can be found in images folder
45image = Image.open('/path/to/image.png')
46image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
47
48# generate
49output_ids = model.generate(
50 input_ids,
51 images=image_tensor,
52 max_new_tokens=2048,
53 use_cache=True)[0]
54
55print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
<|im_start|>user
: do OCR on all the text
<|im_start|>assistant
: The text in the image reads as follows:
- STOP USING DOCKER
- Applications were not meant to be trapped in virtual jars like digital fireflies
- Years of software development, yet no one questioned why we were putting programs in imaginary boats
- Let's containerize our monolith. I'll just quickly spin up 17 microservices. Statements dreamt up by the utterly deranged
- Observe the whale-sized deception they fooled us with all this time
- These are real images used to explain Docker
- "Yay Matey, I'd like to run my website in a virtual sea"
- They have played us for absolute fools
This text is a satirical commentary on the use of Docker in software development, using humor and exaggeration to question the practice.| Model | VQA v2 | MMBench | MMMU (Eval) | MathVista | RealWorldQA |
|---|---|---|---|---|---|
| Dolphin-Vision-72B | 83.6 | 81.2 | 45.7 | 47.25 | 66.4 |
| GPT-4V | 84.4 | 78.1 | 52.4 | - | 67.9 |