Xenova HF staff commited on
Commit
2e039c7
1 Parent(s): 0818c7c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -1
README.md CHANGED
@@ -1,3 +1,61 @@
1
  ---
2
  library_name: transformers.js
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: transformers.js
3
+ ---
4
+
5
+ https://github.com/WongKinYiu/yolov9 with ONNX weights to be compatible with Transformers.js.
6
+
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/@xenova/transformers) using:
11
+ ```bash
12
+ npm i @xenova/transformers
13
+ ```
14
+
15
+ **Example:** Perform object-detection with `Xenova/yolov9-c`.
16
+
17
+ ```js
18
+ import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
19
+
20
+ // Load model
21
+ const model = await AutoModel.from_pretrained('Xenova/yolov9-c', {
22
+ // quantized: false, // (Optional) Use unquantized version.
23
+ })
24
+
25
+ // Load processor
26
+ const processor = await AutoProcessor.from_pretrained('Xenova/yolov9-c');
27
+ // processor.feature_extractor.do_resize = false; // (Optional) Disable resizing
28
+ // processor.feature_extractor.size = { width: 128, height: 128 } // (Optional) Update resize value
29
+
30
+ // Read image and run processor
31
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
32
+ const image = await RawImage.read(url);
33
+ const { pixel_values } = await processor(image);
34
+
35
+ // Run object detection
36
+ const { outputs } = await model({ images: pixel_values })
37
+ const predictions = outputs.tolist();
38
+
39
+ for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
40
+ const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
41
+ console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
42
+ }
43
+ // Found "car" at [176.86, 335.53, 399.82, 418.13] with score 0.94.
44
+ // Found "car" at [447.50, 378.46, 639.81, 477.57] with score 0.93.
45
+ // Found "bicycle" at [351.90, 527.82, 463.50, 587.76] with score 0.90.
46
+ // Found "person" at [472.44, 430.52, 533.74, 533.30] with score 0.89.
47
+ // Found "bicycle" at [448.97, 477.34, 555.42, 537.63] with score 0.88.
48
+ // Found "bicycle" at [0.59, 518.69, 109.53, 584.31] with score 0.88.
49
+ // Found "traffic light" at [208.55, 55.80, 233.99, 101.63] with score 0.86.
50
+ // Found "person" at [550.75, 260.98, 591.90, 331.24] with score 0.86.
51
+ // ...
52
+ ```
53
+
54
+ ## Demo
55
+
56
+ Test it out [here](https://huggingface.co/spaces/Xenova/yolov9-web)!
57
+
58
+ ---
59
+
60
+
61
+ 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`).