抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • TTML
  • 网络
  • 媒体
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 页面导航
  • 开放接口
  • 登录
  • 用户信息
  • 广告
  • 营销能力
  • 支付
  • 分享
  • 小程序跳转
  • 抖音视频能力
  • 收货地址
  • 设置
  • 授权
  • 评价能力
  • 数据分析
  • 视频拍摄器
  • 引导关注
  • 订阅消息
  • 电商插件能力(即将废弃)
  • 隐私信息授权
  • web化
  • 转发和挂载
  • 侧边栏能力
  • 直播能力
  • AI/AR能力
  • AI/AR 能力简介
  • 算法管理器方案
  • 原生神经网络方案
  • 原生神经网络方案简介
  • tt.createBytennEngineContext
  • BytennEngineContext
  • BytennEngineContext
  • BytennEngineContext.onLoad
  • BytennEngineContext.onError
  • BytennEngineContext.load
  • BytennEngine
  • 特效贴纸方案
  • 安全能力
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • 基础库 2.29.0 开始支持本方法,这是一个同步方法。

    加载配置好的神经网络引擎。

    语法

    BytennEngineContext.load()

    参数说明

    无

    返回值

    无

    代码示例

    开发者工具中预览

    const app = getApp(); Page({ data: { item_class: "unknow", prob: 0, }, onLoad: function () { console.log("Welcome to Mini Code"); if (this.offscreenCanvas == null) { this.offscreenCanvas = tt.createOffscreenCanvas(); } this.utils = require("./utils"); }, createBytennEngine: function () { console.log("on create clicked"); const engineCtx = tt.createBytennEngineContext("littleapp_mobilenet", { backend: "auto", }); console.log("engine context is: ", engineCtx); engineCtx.onLoad((engine) => { console.log("load result: ", engine); this.engine = engine; }); engineCtx.onError((err) => { console.log("load error: ", err); }); engineCtx.load(); }, startInfer: function () { if (this.cameraCtx == null) { this.cameraCtx = tt.createCameraContext(); } this.listener = this.cameraCtx.onCameraFrame((res) => { this.engine.infer({ dataConfig: { data: res.data, width: res.width, height: res.height, channel: 4, dataType: "U8", dataFormat: "NHWC", }, convertConfig: [ { outputChannel: 0, normalizeFactor: 255, inputConfig: [ { inputChannel: 0, weight: 1.0, }, ], }, { outputChannel: 1, normalizeFactor: 255, inputConfig: [ { inputChannel: 1, weight: 1.0, }, ], }, { outputChannel: 2, normalizeFactor: 255, inputConfig: [ { inputChannel: 2, weight: 1.0, }, ], }, ], success: (res) => { const classifications = res; if (classifications != null) { const top = 300; const left = 100; const embedding = new Float32Array(classifications.data); const topK = this.utils.topK( embedding, this.utils.IMAGENET_CLASSES, 1 ); const { className, probability } = topK[0]; this.setData({ item_class: className, prob: probability, }); } else { console.warn("no predictions!!"); } }, fail: (err) => { console.log(err); }, }); }); this.listener.start(); }, });

    Bug & Tip

    • Tip: 需在调用 load 前设置回调,否则无法触发回调。
    该文档是否有帮助?
    有帮助
    无帮助