|
--- |
|
library_name: transformers.js |
|
pipeline_tag: object-detection |
|
license: agpl-3.0 |
|
--- |
|
|
|
# YOLOv10: Real-Time End-to-End Object Detection |
|
|
|
ONNX weights for https://github.com/THU-MIG/yolov10. |
|
|
|
Latency-accuracy trade-offs | Size-accuracy trade-offs |
|
:-------------------------:|:-------------------------: |
|
 |  |
|
|
|
## Usage (Transformers.js) |
|
|
|
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: |
|
```bash |
|
npm i @xenova/transformers |
|
``` |
|
|
|
**Example:** Perform object-detection. |
|
```js |
|
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers'; |
|
|
|
// Load model |
|
const model = await AutoModel.from_pretrained('onnx-community/yolov10b', { |
|
// quantized: false, // (Optional) Use unquantized version. |
|
}) |
|
|
|
// Load processor |
|
const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10b'); |
|
|
|
// Read image and run processor |
|
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg'; |
|
const image = await RawImage.read(url); |
|
const { pixel_values } = await processor(image); |
|
|
|
// Run object detection |
|
const { output0 } = await model({ images: pixel_values }); |
|
const predictions = output0.tolist()[0]; |
|
const threshold = 0.5; |
|
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) { |
|
if (score < threshold) continue; |
|
const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ') |
|
console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`) |
|
} |
|
// Found "car" at [447.84, 378.56, 639.25, 478.67] with score 0.94. |
|
// Found "car" at [176.77, 336.73, 398.79, 418.09] with score 0.94. |
|
// Found "bicycle" at [351.96, 526.97, 463.51, 588.49] with score 0.93. |
|
// Found "bicycle" at [449.39, 477.36, 555.63, 538.10] with score 0.91. |
|
// Found "person" at [474.16, 429.78, 534.73, 534.29] with score 0.91. |
|
// Found "bicycle" at [1.51, 517.97, 110.14, 584.14] with score 0.90. |
|
// Found "person" at [31.05, 469.64, 79.11, 567.90] with score 0.90. |
|
// Found "person" at [394.04, 479.20, 442.46, 587.36] with score 0.89. |
|
// ... |
|
``` |