Update README.md
Browse files
README.md
CHANGED
@@ -30,7 +30,24 @@ The abstract of the paper states that:
|
|
30 |
|
31 |
# Using the model
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
You can use the [`convert_pix2struct_checkpoint_to_pytorch.py`](https://github.com/huggingface/transformers/blob/main/src/transformers/models/pix2struct/convert_pix2struct_original_pytorch_to_hf.py) script as follows:
|
36 |
```bash
|
|
|
30 |
|
31 |
# Using the model
|
32 |
|
33 |
+
```python
|
34 |
+
from transformers import Pix2StructProcessor, Pix2StructForConditionalGeneration
|
35 |
+
import requests
|
36 |
+
from PIL import Image
|
37 |
+
|
38 |
+
processor = Pix2StructProcessor.from_pretrained('google/matcha-base')
|
39 |
+
model = Pix2StructForConditionalGeneration.from_pretrained('google/matcha-base')
|
40 |
+
|
41 |
+
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/20294671002019.png"
|
42 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
43 |
+
|
44 |
+
inputs = processor(images=image, text="Is the sum of all 4 places greater than Laos?", return_tensors="pt")
|
45 |
+
predictions = model.generate(**inputs, max_new_tokens=512)
|
46 |
+
print(processor.decode(predictions[0], skip_special_tokens=True))
|
47 |
+
>>> No
|
48 |
+
```
|
49 |
+
|
50 |
+
# Converting from T5x to huggingface
|
51 |
|
52 |
You can use the [`convert_pix2struct_checkpoint_to_pytorch.py`](https://github.com/huggingface/transformers/blob/main/src/transformers/models/pix2struct/convert_pix2struct_original_pytorch_to_hf.py) script as follows:
|
53 |
```bash
|