File size: 1,086 Bytes
cfd8b54
 
 
 
 
 
 
bbfa147
f42a674
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
tags:
- mgp-str
- text-recognition
---


This is an ONNX export of the [MGP-STR](https://huggingface.co/docs/transformers/model_doc/mgp-str) model for text recognition.

It can be run as follows:

```
import onnxruntime as ort
from transformers import MgpstrProcessor

processor = MgpstrProcessor.from_pretrained("alibaba-damo/mgp-str-base")

mpg_str_onnx = hf_hub_download(repo_id="ml6team/mgp-str-onnx", filename="mgp-str.onnx", repo_type="model")

providers = [('CUDAExecutionProvider', {"cudnn_conv_algo_search": "DEFAULT"}), 'CPUExecutionProvider'] if ort.get_device() == 'GPU' else ['CPUExecutionProvider']

session = ort.InferenceSession(
        mpg_str_onnx, providers=providers,
)

image = Image.open("path_to_your_image")convert("RGB")

pixel_values = processor(images=image, return_tensors="pt").pixel_values
inputs = {"pixel_values": pixel_values.numpy()}

warmup = mgp_str_session.run(None, inputs)
outputs = session.run(None, inputs)

outputs = [torch.tensor(i) for i in outputs]
out_strs = processor.batch_decode(tuple(outputs))
print(out_strs["generated_text"])
```