Update README.md
Browse files
README.md
CHANGED
@@ -69,7 +69,34 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
[More Information Needed]
|
75 |
|
|
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
+
```python
|
73 |
+
from transformers import AutoProcessor, VisionEncoderDecoderModel
|
74 |
+
import requests
|
75 |
+
from PIL import Image
|
76 |
+
import torch
|
77 |
+
|
78 |
+
processor = AutoProcessor.from_pretrained("LeroyDyer/Mixtral_AI_Cyber_Q_Vision")
|
79 |
+
model = VisionEncoderDecoderModel.from_pretrained("LeroyDyer/Mixtral_AI_Cyber_Q_Vision")
|
80 |
+
|
81 |
+
# load image from the IAM dataset
|
82 |
+
url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
|
83 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
84 |
+
|
85 |
+
# training
|
86 |
+
model.config.decoder_start_token_id = processor.tokenizer.eos_token_id
|
87 |
+
model.config.pad_token_id = processor.tokenizer.pad_token_id
|
88 |
+
model.config.vocab_size = model.config.decoder.vocab_size
|
89 |
+
|
90 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
91 |
+
text = "hello world"
|
92 |
+
labels = processor.tokenizer(text, return_tensors="pt").input_ids
|
93 |
+
outputs = model(pixel_values=pixel_values, labels=labels)
|
94 |
+
loss = outputs.loss
|
95 |
+
|
96 |
+
# inference (generation)
|
97 |
+
generated_ids = model.generate(pixel_values)
|
98 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
99 |
+
```
|
100 |
|
101 |
[More Information Needed]
|
102 |
|