yolov10x / README.md
Xenova's picture
Xenova HF staff
Create README.md
316c8c3 verified
|
raw
history blame
2.44 kB
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.

Latency-accuracy trade-offs Size-accuracy trade-offs
latency-accuracy trade-offs size-accuracy trade-offs

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/yolov10x', {
    // quantized: false,    // (Optional) Use unquantized version.
})

// Load processor
const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10x');

// 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 [177.70, 336.97, 398.84, 417.47] with score 0.97.
Found "car" at [447.32, 378.86, 639.43, 478.14] with score 0.97.
Found "person" at [473.79, 430.18, 533.20, 532.84] with score 0.95.
Found "bicycle" at [352.02, 526.71, 463.56, 588.08] with score 0.93.
Found "bicycle" at [1.32, 517.64, 109.91, 584.40] with score 0.92.
Found "bicycle" at [449.09, 478.36, 555.36, 537.83] with score 0.91.
Found "person" at [550.20, 261.00, 591.49, 332.14] with score 0.90.
Found "person" at [392.72, 481.26, 442.78, 586.88] with score 0.89.
// ...