Xenova HF staff commited on
Commit
10f0fc0
1 Parent(s): 1751340

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -2
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 "bicycle" at [0.64, 181.27, 38.81, 203.94] with score 0.84.
47
+ // Found "car" at [157.68, 137.26, 223.67, 167.39] with score 0.78.
48
+ // Found "bicycle" at [157.69, 167.86, 195.10, 188.92] with score 0.78.
49
+ // Found "bicycle" at [123.69, 184.40, 162.44, 206.26] with score 0.74.
50
+ // Found "car" at [62.47, 119.27, 139.17, 145.84] with score 0.73.
51
+ // Found "person" at [193.18, 91.03, 206.57, 116.17] with score 0.72.
52
+ // Found "traffic light" at [73.08, 20.15, 82.06, 35.85] with score 0.70.
53
+ // Found "person" at [11.45, 164.69, 27.88, 199.36] with score 0.69.
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`).