Instructions to use alibaba-damo/mgp-str-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alibaba-damo/mgp-str-base with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("image-to-text", model="alibaba-damo/mgp-str-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("alibaba-damo/mgp-str-base") model = AutoModel.from_pretrained("alibaba-damo/mgp-str-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse filesupdate code example
README.md
CHANGED
|
@@ -30,21 +30,21 @@ You can use the raw model for optical character recognition (OCR) on text images
|
|
| 30 |
Here is how to use this model in PyTorch:
|
| 31 |
|
| 32 |
```python
|
| 33 |
-
from transformers import
|
| 34 |
import requests
|
| 35 |
from PIL import Image
|
| 36 |
|
| 37 |
-
processor =
|
| 38 |
-
model =
|
| 39 |
|
| 40 |
# load image from the IIIT-5k dataset
|
| 41 |
url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
|
| 42 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 43 |
|
| 44 |
-
pixel_values = processor(image, return_tensors="pt").pixel_values
|
| 45 |
-
|
| 46 |
|
| 47 |
-
generated_text = processor.batch_decode(
|
| 48 |
```
|
| 49 |
|
| 50 |
### BibTeX entry and citation info
|
|
|
|
| 30 |
Here is how to use this model in PyTorch:
|
| 31 |
|
| 32 |
```python
|
| 33 |
+
from transformers import MgpstrProcessor, MgpstrForSceneTextRecognition
|
| 34 |
import requests
|
| 35 |
from PIL import Image
|
| 36 |
|
| 37 |
+
processor = MgpstrProcessor.from_pretrained('alibaba-damo/mgp-str-base')
|
| 38 |
+
model = MgpstrForSceneTextRecognition.from_pretrained('alibaba-damo/mgp-str-base')
|
| 39 |
|
| 40 |
# load image from the IIIT-5k dataset
|
| 41 |
url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
|
| 42 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 43 |
|
| 44 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
| 45 |
+
outputs = model(pixel_values)
|
| 46 |
|
| 47 |
+
generated_text = processor.batch_decode(outputs.logits)['generated_text']
|
| 48 |
```
|
| 49 |
|
| 50 |
### BibTeX entry and citation info
|