英文:
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
。
英文:
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
答案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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论