Update README.md
Browse files
README.md
CHANGED
@@ -1,4 +1,66 @@
|
|
1 |
---
|
2 |
-
license: gpl-3.0
|
3 |
library_name: transformers.js
|
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/yolov9-c_all`.
|
18 |
+
|
19 |
+
```js
|
20 |
+
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
|
21 |
+
|
22 |
+
// Load model
|
23 |
+
const model = await AutoModel.from_pretrained('Xenova/yolov9-c_all', {
|
24 |
+
// quantized: false, // (Optional) Use unquantized version.
|
25 |
+
})
|
26 |
+
|
27 |
+
// Load processor
|
28 |
+
const processor = await AutoProcessor.from_pretrained('Xenova/yolov9-c_all');
|
29 |
+
// processor.feature_extractor.size = { shortest_edge: 128 } // (Optional) Update resize value
|
30 |
+
|
31 |
+
// Read image and run processor
|
32 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
33 |
+
const image = await RawImage.read(url);
|
34 |
+
const inputs = await processor(image);
|
35 |
+
|
36 |
+
// Run object detection
|
37 |
+
const threshold = 0.3;
|
38 |
+
const { outputs } = await model(inputs);
|
39 |
+
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.
|
48 |
+
// Found "bicycle" at [0.80, 182.37, 39.26, 203.85] with score 0.85.
|
49 |
+
// Found "bicycle" at [124.02, 184.35, 163.21, 206.10] with score 0.85.
|
50 |
+
// Found "bicycle" at [158.31, 169.96, 194.58, 189.22] with score 0.80.
|
51 |
+
// Found "person" at [135.04, 166.16, 156.00, 204.01] with score 0.75.
|
52 |
+
// Found "person" at [192.14, 90.51, 205.68, 116.73] with score 0.74.
|
53 |
+
// Found "person" at [11.69, 164.45, 28.37, 200.11] with score 0.74.
|
54 |
+
// ...
|
55 |
+
```
|
56 |
+
|
57 |
+
## Demo
|
58 |
+
|
59 |
+
Test it out [here](https://huggingface.co/spaces/Xenova/video-object-detection)!
|
60 |
+
|
61 |
+
<video controls autoplay loop src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/AgNFx_3cPMh5zjR91n9Dt.mp4"></video>
|
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`).
|