metadata
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.
Usage (Transformers.js)
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @xenova/transformers
Example: Perform object-detection.
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
// Load model
const model = await AutoModel.from_pretrained('onnx-community/yolov10n', {
// quantized: false, // (Optional) Use unquantized version.
})
// Load processor
const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10n');
// 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.54, 378.72, 640.04, 478.45] with score 0.93.
// Found "car" at [179.04, 339.41, 398.66, 416.86] with score 0.90.
// Found "bicycle" at [2.13, 518.43, 110.29, 584.21] with score 0.88.
// Found "bicycle" at [352.12, 521.97, 464.05, 588.28] with score 0.85.
// Found "person" at [550.97, 258.75, 591.22, 332.01] with score 0.85.
// Found "bicycle" at [449.07, 473.14, 556.22, 537.92] with score 0.83.
// Found "person" at [31.36, 469.01, 79.16, 572.99] with score 0.82.
// Found "person" at [473.11, 430.45, 533.71, 527.05] with score 0.79.
// ...