-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.js
43 lines (43 loc) · 1.29 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//app.js
var fetchWechat = require('fetch-wechat');
var tf = require('@tensorflow/tfjs-core');
var webgl = require('@tensorflow/tfjs-backend-webgl');
var cpu = require('@tensorflow/tfjs-backend-cpu');
var plugin = requirePlugin('tfjsPlugin');
App({
onLaunch: function () {
this.getDeviceInfo();
tf.ENV.flagRegistry.WEBGL_VERSION.evaluationFn = () => { return 1 };
plugin.configPlugin({
// polyfill fetch function
fetchFunc: fetchWechat.fetchFunc(),
// inject tfjs runtime
tf,
// inject webgl backend
webgl,
// inject cpu backend
cpu,
// provide webgl canvas
canvas: wx.createOffscreenCanvas()
});
// tf.tensor([1, 2, 3, 4]).print();
},
getDeviceInfo() {
try {
const res = wx.getSystemInfoSync();
this.globalData.appWidth = typeof res.screenWidth === 'number' ? res.screenWidth : 320;
this.globalData.appHeight = typeof res.screenHeight === 'number' ? res.screenHeight : 500;
this.globalData.benchmarkLevel = typeof res.benchmarkLevel === 'number' ? res.benchmarkLevel : -1;
wx.reportAnalytics('get_device_info', {
device_info: JSON.stringify(res)
});
} catch (e) {
console.log(e);
}
},
globalData: {
appWidth: 320,
appHeight: 500,
benchmarkLevel: -1
}
})