-
Notifications
You must be signed in to change notification settings - Fork 100
/
profile.js
82 lines (74 loc) · 2.52 KB
/
profile.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const tf = require('@tensorflow/tfjs');
const mobilenet = require('@tensorflow-models/mobilenet');
const posenet = require('@tensorflow-models/posenet');
const bodypix = require('@tensorflow-models/body-pix');
const cocoSSD = require('@tensorflow-models/coco-ssd');
const handPose = require('@tensorflow-models/handpose');
const face = require('@tensorflow-models/face-landmarks-detection');
const fs = require('fs');
const mobilenetPredict = async () => {
// mobilenet
const model = await mobilenet.load({
version: 1,
modelUrl: 'https://ai.flypot.cn/mp/ai-pocket/models/imagenet/model.json'
});
return await model.infer(tf.zeros([1, 224, 224, 3]));
};
const posenetPredict = async () => {
// posenet
const model = await posenet.load(
{
architecture: 'MobileNetV1',
outputStride: 16,
inputResolution: 193,
multiplier: 0.5,
modelUrl: 'https://www.gstaticcnapps.cn/tfjs-models/savedmodel/posenet/mobilenet/float/050/model-stride16.json'
}
);
return await model.estimateSinglePose(tf.zeros([513, 513, 3]));
};
const bodypixPredict = async () => {
// body-pix
const model = await bodypix.load({
architecture: 'MobileNetV1',
outputStride: 16,
multiplier: 0.5,
modelUrl: 'https://www.gstaticcnapps.cn/tfjs-models/savedmodel/bodypix/mobilenet/float/050/model-stride16.json'
});
return await model.segmentPerson(tf.zeros([73, 73, 3]));
};
const cocoSSDPredict = async () => {
// body-pix
const model = await cocoSSD.load({
modelUrl: 'https://ai.flypot.cn/mp/ai-pocket/models/coco-ssd/model.json'
});
return await model.detect(tf.zeros([227, 227, 3], 'int32'));
};
const handPosePredict = async () => {
// handpose
const model = await handPose.load();
return await model.estimateHands(tf.zeros([128, 128, 3]));
};
const facePredict = async () => {
// face
const model = await face.load();
return await model.estimateFaces({input: tf.zeros([128, 128, 3])});
};
tf.profile(async () => {
try {
await mobilenetPredict();
await posenetPredict();
await bodypixPredict();
await cocoSSDPredict();
await facePredict();
// await handPosePredict();
} catch (e) {
console.error('error:', e);
}
}).then(e => {
console.log('kernels:', e.kernelNames);
let rawData = fs.readFileSync('./tfjs_config.json');
let tfjsConfig = JSON.parse(rawData);
tfjsConfig.kernels = e.kernelNames;
fs.writeFileSync('./tfjs_config.json', JSON.stringify(tfjsConfig, null, 2));
});