收藏
回答

AI 推理 ios系统16.2版本使用 allowNPU 报错?

InferenceSession wx.createInferenceSession

微信版本8.0.32

IOS下使用allowNPU

// 创建会话,加载模型
const session = wx.createInferenceSession({
  model: `${wx.env.USER_DATA_PATH}/MNIST.onnx`,
  precisionLevel: 4,
  typicalShape:{input1:[1, 3, 224, 224], input2:[1, 1, 224, 224]},  //除非使用动态轴,一般不用显式指定
  allowNPU: false,
  allowQuantize: false
})

// 监听 error 事件
session.onError(err => {
  console.error(err)
})

// 监听模型加载完成事件
session.onLoad(() => {
  // 运行推理
  // 其中input1, input2, output0 必须与使用的 onnx 模型中实际的输入输出名字完全一致,不可随意填写。
  // 模型输入输出信息可以通过Netron 打开 onnx 模型看到
  session.run({
    input1: {
      type: 'float32',
      data: new Float32Array(3 * 224 * 224).buffer,
      shape: [1, 3, 224, 224] // NCHW 顺序
    },
    // 多个 input 的添加方法,假设第二个 input 需要数据类型为uint8
    input2: {
      type: 'uint8',
      data: new Uint8Array(224 * 224).buffer,
      shape: [1, 1, 224, 224]
    },
  }).then(res => {
    console.log(res.output0)
  })
})

// 销毁Session
// session完成创建后可以多次调用 run 进行推理,直到调用`session.destroy()`释放相关内存。

// 销毁会话
session.destroy()


回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2023-02-23

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2023-02-23
    有用
    回复
  • Jianbo
    Jianbo
    2023-02-23

    是不是基础库版本的问题?

    2023-02-23
    有用
    回复 1
登录 后发表内容