功能是创建 AI 推理 Session。
示例代码:
// 创建会话,加载模型 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()
wx.getInferenceEnvInfo(Object object)
获取通用AI推理引擎版本。
示例代码
// 获取通用AI推理引擎版本 wx.getInferenceEnvInfo({ complete: (res) => { console.log(res.ver) console.log(res.errMsg) }, })
clearAnimatedStyle清除节点上 worklet 驱动样式的绑定关系
styleIds 数组为空,则清除选中节点上所有绑定的 animatedStyle,需要注意的是样式并不会重置,只是解除了依赖关系。styleId 可由 applyAnimatedStyle 回调参数中获取。
节点移除时,相关的 animatedStyle 会自动释放,clearAnimatedStyle 可用于需要提前解绑的情况
示例代码
const offset = shared(0) const styleIds = [] this.applyAnimatedStyle('.box', () => { 'worklet' return { transform: `translateX(${offset.value}px) rotate(30deg)` } }, { immediate: true, flush: 'async' }, (res) => { console.log('animatedStyle 已绑定到节点 ', res.styleId) styleIds.push(res.styleId) }) this.clearAnimatedStyle('.box', styleIds, () => { console.log('animatedStyle 已清除绑定') })
applyAnimatedStyle 参数定义
定义段 | 类型 | 是否必填 | 描述 | 最低版本 |
selector | String | 是 | 节点选择器 | 2.29.0 |
updater | Function | 是 | worklet 样式更新函数 | 2.29.0 |
userConfig | Object | 否 | 配置项 | 2.30.1 |
callback | Function | 否 | 完成样式绑定的回调 | 2.30.1 |
问题描述:旧版本微信(好像是<8.0.25的)开启调试一点不卡; 新版微信(>=8.0.25)的超级卡, 关了调试就正常了.
问题已解决
退出当前小程序。必须有点击行为才能调用成功
1476浏览 2023-09-11
358浏览 2023-09-07
340浏览 2023-09-28
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
请在支付页面继续完成支付