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/yolov10s', {
// quantized: false, // (Optional) Use unquantized version.
})
// Load processor
const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10s');
// 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 [448.81, 378.16, 639.25, 477.85] with score 0.95.
// Found "car" at [177.93, 338.54, 398.13, 417.66] with score 0.93.
// Found "bicycle" at [449.25, 475.36, 555.90, 537.42] with score 0.92.
// Found "bicycle" at [1.46, 517.67, 109.81, 584.15] with score 0.90.
// Found "bicycle" at [351.74, 524.63, 464.50, 588.63] with score 0.87.
// Found "person" at [550.09, 260.31, 591.83, 332.18] with score 0.85.
// Found "person" at [474.90, 429.96, 533.88, 535.70] with score 0.83.
// Found "traffic light" at [208.08, 55.58, 233.91, 102.01] with score 0.78.
// ...