onnxruntime-web A tensor's dims must be a number array

huangapple go评论81阅读模式
英文:

onnxruntime-web A tensor's dims must be a number array

问题

我想复制这个可行的MNIST推断示例,该示例使用不推荐使用的onnxjs库,而我想使用新的onnxruntime,但在从画布图像创建张量时出现错误:

const imgData = this.ctx.getImageData(0, 0, this.CANVAS_SIZE, this.CANVAS_SIZE);
let img_arr = new Float32Array(imgData.data); //560 x 560 = 313600
const dims = [1, 1, 560, 560];
const input = new ort.Tensor(img_arr, "float32", dims);

错误消息:

A tensor's dims must be a number array

要复制问题的完整代码,请访问此存储库

我还尝试在CodeSandbox上复制问题,但似乎CodeSandbox在安装onnxruntime-web时遇到了问题:Unable to open 'ort-web.min.js': File not found (file:///sandbox/node_modules/onnxruntime-web/dist/ort-web.min.js).

因此,我收到另一个错误:invalid wire type 4 at offset 3

onnxruntime-web A tensor's dims must be a number array

英文:

I want to replicate this working MNIST inference example which uses the deprecated onnxjs library in favor of using the new onnxruntime, but I'm getting an error while creating a Tensor from the canvas image:

const imgData = this.ctx.getImageData(0, 0, this.CANVAS_SIZE, this.CANVAS_SIZE);
let img_arr= new Float32Array(imgData.data); //560 x 560 = 313600
const dims = [1, 1, 560, 560];
const input = new ort.Tensor(img_arr, "float32", dims);

Error Message:

A tensor's dims must be a number array

The full code to replicate my problem is available in this repository.

I have tried also to replicate my problem on Code sandbox, but it seems that the code sandbox has an issue installing the onnxruntime-web: Unable to open 'ort-web.min.js': File not found (file:///sandbox/node_modules/onnxruntime-web/dist/ort-web.min.js).

So I get another error: invalid wire type 4 at offset 3

onnxruntime-web A tensor's dims must be a number array

答案1

得分: 0

Tensor创建的约定(参数顺序)在新的API中已经改变:

const input = new ort.Tensor("float32", img_arr, dims);
英文:

The convention (parameters order) of Tensor creation has changed in the new API:

const input = new ort.Tensor("float32", img_arr, dims);

huangapple
  • 本文由 发表于 2023年5月18日 04:01:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定