Add/update the quantized ONNX model files and README.md for Transformers.js v3 (#1)
Browse files- Add/update the quantized ONNX model files and README.md for Transformers.js v3 (9498c5a91deef9b4f57efbb13471a4a758f9ed1e)
Co-authored-by: Yuichiro Tachibana <[email protected]>
README.md
CHANGED
@@ -6,23 +6,22 @@ pipeline_tag: object-detection
|
|
6 |
|
7 |
https://github.com/WongKinYiu/yolov9 with ONNX weights to be compatible with Transformers.js.
|
8 |
|
9 |
-
|
10 |
## Usage (Transformers.js)
|
11 |
|
12 |
-
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/@
|
13 |
```bash
|
14 |
-
npm i @
|
15 |
```
|
16 |
|
17 |
**Example:** Perform object-detection with `Xenova/yolov9-e_all`.
|
18 |
|
19 |
```js
|
20 |
-
import { AutoModel, AutoProcessor, RawImage } from '@
|
21 |
|
22 |
// Load model
|
23 |
const model = await AutoModel.from_pretrained('Xenova/yolov9-e_all', {
|
24 |
-
|
25 |
-
})
|
26 |
|
27 |
// Load processor
|
28 |
const processor = await AutoProcessor.from_pretrained('Xenova/yolov9-e_all');
|
@@ -40,8 +39,8 @@ const predictions = outputs.tolist();
|
|
40 |
|
41 |
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
42 |
if (score < threshold) break;
|
43 |
-
const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
|
44 |
-
console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
|
45 |
}
|
46 |
// Found "car" at [156.96, 133.09, 223.66, 167.14] with score 0.91.
|
47 |
// Found "car" at [63.22, 119.01, 139.68, 145.72] with score 0.88.
|
@@ -62,5 +61,4 @@ Test it out [here](https://huggingface.co/spaces/Xenova/video-object-detection)!
|
|
62 |
|
63 |
---
|
64 |
|
65 |
-
|
66 |
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`).
|
|
|
6 |
|
7 |
https://github.com/WongKinYiu/yolov9 with ONNX weights to be compatible with Transformers.js.
|
8 |
|
|
|
9 |
## Usage (Transformers.js)
|
10 |
|
11 |
+
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:
|
12 |
```bash
|
13 |
+
npm i @huggingface/transformers
|
14 |
```
|
15 |
|
16 |
**Example:** Perform object-detection with `Xenova/yolov9-e_all`.
|
17 |
|
18 |
```js
|
19 |
+
import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
|
20 |
|
21 |
// Load model
|
22 |
const model = await AutoModel.from_pretrained('Xenova/yolov9-e_all', {
|
23 |
+
dtype: "fp32", // (Optional) Use unquantized version.
|
24 |
+
});
|
25 |
|
26 |
// Load processor
|
27 |
const processor = await AutoProcessor.from_pretrained('Xenova/yolov9-e_all');
|
|
|
39 |
|
40 |
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
41 |
if (score < threshold) break;
|
42 |
+
const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ');
|
43 |
+
console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`);
|
44 |
}
|
45 |
// Found "car" at [156.96, 133.09, 223.66, 167.14] with score 0.91.
|
46 |
// Found "car" at [63.22, 119.01, 139.68, 145.72] with score 0.88.
|
|
|
61 |
|
62 |
---
|
63 |
|
|
|
64 |
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`).
|