我正在尝试使用 ONNX.js 在浏览器中运行 ONNX 对象检测模型。我知道在 Tensorflow.js 中,您只需将图像对象传递给模型,Tensorflow 会自动创建模型所需的张量,但在 ONNX 中,我们必须从图像创建张量,然后将其传递给模型。
我阅读了官方存储库 - https://github.com/Microsoft/onnxjs,但我找不到任何有关如何在 Javascript 中从图像创建张量的资源。
如果有人知道什么请帮忙?
我正在使用以下代码使用 ONNX.js 在浏览器中运行对象检测
<html>
<head> </head>
<body>
<div onclick="runOD()">
Run Model
</div>
<img src="box.jpg" id="image">
<!-- Load ONNX.js -->
<script src="https://cdn.jsdelivr.net/npm/onnxjs/dist/onnx.min.js"></script>
<!-- Code that consume ONNX.js -->
<script>
async function runOD() {
// Creat the session and load the pre-trained model
const session = new onnx.InferenceSession({
backendHint: 'webgl'
});
await session.loadModel("./model.onnx");
//Function to load image to Canvas and Convert it to Tensor
const …Run Code Online (Sandbox Code Playgroud)