【问题标题】:Loading in a .onnx file into javascript将 .onnx 文件加载到 javascript 中
【发布时间】:2019-08-02 06:40:50
【问题描述】:

我正在尝试将 .onnx 文件加载到 javascript 会话中。我收到的错误是 TypeError: unrecognized operator 'ReduceL2',但这个链接 https://github.com/onnx/onnx/blob/master/docs/Operators.md 说 onnx 支持 'ReduceL2'。我猜这可能与 webGL 不支持它有关。是否有任何解决方法或更好的方法可以在浏览器中运行模型?对 javascript 非常陌生。

Javascript 代码:

async function runExample() {
  // Create an ONNX inference session with WebGL backend.
  const session = new onnx.InferenceSession({ backendHint: 'webgl' });


  // Load an ONNX model. This model is Resnet50 that takes a 1*3*224*224 image and classifies it.
  await session.loadModel("./pathtomodel");

抛出错误:

Uncaught (in promise) TypeError: unrecognized operator 'ReduceL2'
    at t.createOperator (session-handler.ts:222)
    at t.resolve (session-handler.ts:86)
    at e.initializeOps (session.ts:252)
    at session.ts:92
    at t.event (instrument.ts:294)
    at e.initialize (session.ts:81)
    at e.<anonymous> (session.ts:63)
    at inference-session-impl.ts:16
    at Object.next (inference-session-impl.ts:16)
    at a (inference-session-impl.ts:16)

【问题讨论】:

    标签: onnx


    【解决方案1】:

    请参阅 ONNX.js 的 list of supported operators,它只是所有 ONNX 运算符的一个子集。 ReduceL2 不在列表中,但有趣的是 ReduceSumSquare 在列表中,这似乎是一回事。 (?)

    与其等待他们在 ONXX.js 中实现 ReduceL2,不如尝试 ReduceSumSquare 或尝试(逐点)对参数求平方,然后调用 ReduceSum。

    同样,您可以定义自己的 ReduceL2() 函数来调用上述两个操作中的任何一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2013-06-22
      相关资源
      最近更新 更多