Update README.md
Browse files
README.md
CHANGED
@@ -1,4 +1,63 @@
|
|
1 |
---
|
2 |
library_name: transformers.js
|
3 |
license: gpl-3.0
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
library_name: transformers.js
|
3 |
license: gpl-3.0
|
4 |
+
pipeline_tag: object-detection
|
5 |
+
---
|
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/@xenova/transformers) using:
|
13 |
+
```bash
|
14 |
+
npm i @xenova/transformers
|
15 |
+
```
|
16 |
+
|
17 |
+
**Example:** Perform object-detection with `Xenova/gelan-e`.
|
18 |
+
|
19 |
+
```js
|
20 |
+
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
|
21 |
+
|
22 |
+
// Load model
|
23 |
+
const model = await AutoModel.from_pretrained('Xenova/gelan-e', {
|
24 |
+
// quantized: false, // (Optional) Use unquantized version.
|
25 |
+
})
|
26 |
+
|
27 |
+
// Load processor
|
28 |
+
const processor = await AutoProcessor.from_pretrained('Xenova/gelan-e');
|
29 |
+
// processor.feature_extractor.do_resize = false; // (Optional) Disable resizing
|
30 |
+
// processor.feature_extractor.size = { width: 128, height: 128 } // (Optional) Update resize value
|
31 |
+
|
32 |
+
// Read image and run processor
|
33 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
34 |
+
const image = await RawImage.read(url);
|
35 |
+
const { pixel_values } = await processor(image);
|
36 |
+
|
37 |
+
// Run object detection
|
38 |
+
const { outputs } = await model({ images: pixel_values })
|
39 |
+
const predictions = outputs.tolist();
|
40 |
+
|
41 |
+
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
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 [177.60, 337.36, 398.55, 416.89] with score 0.93.
|
46 |
+
// Found "car" at [447.15, 378.75, 639.80, 477.55] with score 0.93.
|
47 |
+
// Found "bicycle" at [1.58, 518.34, 109.99, 584.37] with score 0.90.
|
48 |
+
// Found "person" at [551.19, 261.01, 591.45, 330.76] with score 0.89.
|
49 |
+
// Found "bicycle" at [449.09, 477.33, 555.91, 537.40] with score 0.89.
|
50 |
+
// Found "bicycle" at [352.70, 528.23, 463.36, 588.13] with score 0.88.
|
51 |
+
// Found "traffic light" at [376.77, 65.71, 401.59, 111.02] with score 0.86.
|
52 |
+
// Found "traffic light" at [208.46, 55.44, 233.45, 101.43] with score 0.85.
|
53 |
+
// ...
|
54 |
+
```
|
55 |
+
|
56 |
+
## Demo
|
57 |
+
|
58 |
+
Test it out [here](https://huggingface.co/spaces/Xenova/yolov9-web)!
|
59 |
+
|
60 |
+
---
|
61 |
+
|
62 |
+
|
63 |
+
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`).
|