在分包中使用
plugin.configPlugin(
{
// polyfill fetch function
fetchFunc: fetchWechat.fetchFunc(),
// inject tfjs runtime
tf: that.tf,
// inject cup backend
cup,
// inject webgl backend
webgl,
// webgpu,
// provide webgl canvas
canvas: wx.createOffscreenCanvas(),
},
false
);
之后就就是
const modelConfig = {
modelUrl,
modelType: poseDetection.movenet.modelType.SINGLEPOSE_LIGHTNING,
// multiPoseMaxDimension: 384, // 默认是256 必须是32的倍数 数值越大精度越高速度越慢
// enableSmoothing: true, // 指示是否使用时间滤波器来平滑预测的关键点 对于多姿势检测,需要启用跟踪
};
const model = poseDetection.SupportedModels.MoveNet;
const detection = await poseDetection.createDetector(model, modelConfig);
// 识别点
detection
.estimatePoses(object)
.then(function (res) {
})
.catch(function (err) {
console.log(err,'====err');
});
这里进入了 catch 返回 u.getLogicalCoordinatesFromFlatIndex is not a function
找到原因了,是因为我在主包中引入了
import * as tf from "@tensorflow/tfjs-core"
跟换到需要的分包就好了,但是分包里面需要引入tfjs-backend-cpu,不然还是报
u.getLogicalCoordinatesFromFlatIndex is not a function
@tensorflow/tfjs-backend-cpu
在分包中接着引入 cpu 分包的大小就超过2Mb了,就没法上传了
有人遇到过微信小程序使用第三方插件,在分包中使用分包大小超了怎么办。
tensorflow 又是直接全部插件引入的
plugin.configPlugin(
{
// polyfill fetch function
fetchFunc: fetchFunc(),
// inject tfjs runtime
tf,
// inject cpu backend
cpu,
// inject webgl backend
webgl,
// provide webgl canvas
canvas: wx.createOffscreenCanvas(),
},
false
);