Update README.md
Browse files
README.md
CHANGED
|
@@ -5,4 +5,37 @@ base_model: alibaba-damo/mgp-str-base
|
|
| 5 |
|
| 6 |
https://huggingface.co/alibaba-damo/mgp-str-base with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|
|
|
|
| 5 |
|
| 6 |
https://huggingface.co/alibaba-damo/mgp-str-base with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
| 8 |
+
## Usage (Transformers.js)
|
| 9 |
+
|
| 10 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
| 11 |
+
```bash
|
| 12 |
+
npm i @huggingface/transformers
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
**Example:** Optical Character Recognition (OCR) w/ `onnx-community/mgp-str-base`
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
import { MgpstrForSceneTextRecognition, MgpstrProcessor, RawImage } from '@huggingface/transformers';
|
| 19 |
+
|
| 20 |
+
const model_id = 'onnx-community/mgp-str-base';
|
| 21 |
+
const model = await MgpstrForSceneTextRecognition.from_pretrained(model_id,);
|
| 22 |
+
const processor = await MgpstrProcessor.from_pretrained(model_id);
|
| 23 |
+
|
| 24 |
+
// Load image from the IIIT-5k dataset
|
| 25 |
+
const url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png";
|
| 26 |
+
const image = await RawImage.read(url);
|
| 27 |
+
|
| 28 |
+
// Preprocess the image
|
| 29 |
+
const result = await processor(image);
|
| 30 |
+
|
| 31 |
+
// Perform inference
|
| 32 |
+
const outputs = await model(result);
|
| 33 |
+
|
| 34 |
+
// Decode the model outputs
|
| 35 |
+
const generated_text = processor.batch_decode(outputs.logits).generated_text;
|
| 36 |
+
console.log(generated_text); // [ 'ticket' ]
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|