Xenova HF staff commited on
Commit
589b213
1 Parent(s): f1bd08c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers.js
3
+ pipeline_tag: object-detection
4
+ license: agpl-3.0
5
+ ---
6
+
7
+ ## Usage (Transformers.js)
8
+
9
+ 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:
10
+ ```bash
11
+ npm i @xenova/transformers
12
+ ```
13
+
14
+ **Example:** Perform object-detection.
15
+ ```js
16
+ import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
17
+
18
+ // Load model
19
+ const model = await AutoModel.from_pretrained('onnx-community/yolov10s', {
20
+ // quantized: false, // (Optional) Use unquantized version.
21
+ })
22
+
23
+ // Load processor
24
+ const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10s');
25
+
26
+ // Read image and run processor
27
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
28
+ const image = await RawImage.read(url);
29
+ const { pixel_values } = await processor(image);
30
+
31
+ // Run object detection
32
+ const { output0 } = await model({ images: pixel_values });
33
+ const predictions = output0.tolist()[0];
34
+ const threshold = 0.5;
35
+ for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
36
+ if (score < threshold) continue;
37
+ const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
38
+ console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
39
+ }
40
+ // Found "car" at [448.81, 378.16, 639.25, 477.85] with score 0.95.
41
+ // Found "car" at [177.93, 338.54, 398.13, 417.66] with score 0.93.
42
+ // Found "bicycle" at [449.25, 475.36, 555.90, 537.42] with score 0.92.
43
+ // Found "bicycle" at [1.46, 517.67, 109.81, 584.15] with score 0.90.
44
+ // Found "bicycle" at [351.74, 524.63, 464.50, 588.63] with score 0.87.
45
+ // Found "person" at [550.09, 260.31, 591.83, 332.18] with score 0.85.
46
+ // Found "person" at [474.90, 429.96, 533.88, 535.70] with score 0.83.
47
+ // Found "traffic light" at [208.08, 55.58, 233.91, 102.01] with score 0.78.
48
+ // ...
49
+ ```