Xenova HF staff commited on
Commit
e2179ae
1 Parent(s): fdd4411

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/gelan-e_all`.
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_all', {
24
+ // quantized: false, // (Optional) Use unquantized version.
25
+ })
26
+
27
+ // Load processor
28
+ const processor = await AutoProcessor.from_pretrained('Xenova/gelan-e_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 [157.78, 132.88, 223.89, 167.56] with score 0.89.
47
+ // Found "car" at [62.69, 120.29, 140.12, 146.40] with score 0.86.
48
+ // Found "bicycle" at [0.53, 180.42, 39.41, 204.48] with score 0.84.
49
+ // Found "bicycle" at [157.39, 163.91, 194.82, 189.06] with score 0.81.
50
+ // Found "person" at [192.77, 90.67, 207.29, 116.15] with score 0.80.
51
+ // Found "bicycle" at [124.00, 183.29, 162.22, 206.57] with score 0.78.
52
+ // Found "person" at [11.91, 164.63, 27.64, 200.17] with score 0.78.
53
+ // Found "person" at [166.75, 150.84, 187.49, 186.04] 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 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`).