Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This is an ONNX export of the [MGP-STR] model for text recognition.
|
2 |
+
|
3 |
+
It can be run as follows:
|
4 |
+
|
5 |
+
```
|
6 |
+
import onnxruntime as ort
|
7 |
+
from transformers import MgpstrProcessor
|
8 |
+
|
9 |
+
processor = MgpstrProcessor.from_pretrained("alibaba-damo/mgp-str-base")
|
10 |
+
|
11 |
+
mpg_str_onnx = hf_hub_download(repo_id="ml6team/mgp-str-onnx", filename="mgp-str.onnx", repo_type="model")
|
12 |
+
|
13 |
+
providers = [('CUDAExecutionProvider', {"cudnn_conv_algo_search": "DEFAULT"}), 'CPUExecutionProvider'] if ort.get_device() == 'GPU' else ['CPUExecutionProvider']
|
14 |
+
|
15 |
+
session = ort.InferenceSession(
|
16 |
+
mpg_str_onnx, providers=providers,
|
17 |
+
)
|
18 |
+
|
19 |
+
image = Image.open("path_to_your_image")convert("RGB")
|
20 |
+
|
21 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
22 |
+
inputs = {"pixel_values": pixel_values.numpy()}
|
23 |
+
|
24 |
+
warmup = mgp_str_session.run(None, inputs)
|
25 |
+
outputs = session.run(None, inputs)
|
26 |
+
|
27 |
+
outputs = [torch.tensor(i) for i in outputs]
|
28 |
+
out_strs = processor.batch_decode(tuple(outputs))
|
29 |
+
print(out_strs["generated_text"])
|
30 |
+
```
|