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