ONNX 模型库
返回模型

说明文档


library_name: transformers.js license: gpl-3.0 pipeline_tag: object-detection

https://github.com/WongKinYiu/yolov9 的 ONNX 权重,用于兼容 Transformers.js。

用法 (Transformers.js)

如果你还没有安装,可以通过 NPM 安装 Transformers.js JavaScript 库:

npm i @xenova/transformers

示例: 使用 Xenova/gelan-c_all 进行目标检测。

import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';

// Load model
const model = await AutoModel.from_pretrained('Xenova/gelan-c_all', {
    // quantized: false,    // (Optional) Use unquantized version.
})

// Load processor
const processor = await AutoProcessor.from_pretrained('Xenova/gelan-c_all');
// processor.feature_extractor.size = { shortest_edge: 128 }    // (Optional) Update resize value

// 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 inputs = await processor(image);

// Run object detection
const threshold = 0.3;
const { outputs } = await model(inputs);
const predictions = outputs.tolist();

for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
    if (score < threshold) break;
    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 [63.06, 118.80, 139.61, 146.78] with score 0.84.
// Found "bicycle" at [158.32, 166.13, 195.02, 189.03] with score 0.81.
// Found "bicycle" at [123.22, 183.83, 162.71, 206.30] with score 0.79.
// Found "bicycle" at [0.56, 180.92, 39.26, 203.94] with score 0.78.
// Found "car" at [157.10, 132.38, 223.72, 167.69] with score 0.77.
// Found "person" at [193.04, 90.98, 207.09, 116.78] with score 0.77.
// Found "person" at [12.49, 164.97, 27.63, 197.55] with score 0.66.
// Found "traffic light" at [102.80, 74.25, 124.12, 95.75] with score 0.62.
// ...

演示

这里测试!

<video controls autoplay loop src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/AgNFx_3cPMh5zjR91n9Dt.mp4"></video>


注意:为 ONNX 权重创建单独的仓库是一个临时方案,直到 WebML 获得更多关注。如果你想让你的模型支持网页端使用,我们建议使用 🤗 Optimum 转换为 ONNX 格式,并按照本仓库的结构组织(将 ONNX 权重放在名为 onnx 的子文件夹中)。

kurnie/yolo-realtime

作者 kurnie

object-detection transformers.js
↓ 1 ♥ 1

创建时间: 2024-07-09 00:37:36+00:00

更新时间: 2024-07-23 10:50:45+00:00

在 Hugging Face 上查看

文件 (5)

.gitattributes
README.md
config.json
onnx/bestv8.onnx ONNX
preprocessor_config.json