Skip to content

Commit 12f8108

Browse files
authored
Merge pull request #103 from Sunnyday2016/improve_aidemo
improve aidemo code style
2 parents 1a58674 + 7122acb commit 12f8108

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

miniprogram/packageAPI/pages/ai/mobilenet/classify.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,15 @@ export class Classifier {
10251025

10261026
speedTime = 0.0;
10271027

1028-
//modelInput = null;
1028+
modelInput = null;
10291029

10301030
constructor(displaySize) {
10311031
this.displaySize = {
10321032
width: displaySize.width,
10331033
height: displaySize.height,
10341034
};
10351035

1036-
//this.modelInput = new Float32Array(modelWidth * modelHeight * 3);
1036+
this.modelInput = new Float32Array(modelWidth * modelHeight * modelChannel);
10371037

10381038
this.ready = false;
10391039
}
@@ -1209,12 +1209,10 @@ export class Classifier {
12091209
{
12101210
return new Promise((resolve, reject) =>
12111211
{
1212-
var dstInput = new Float32Array(modelChannel * modelHeight * modelWidth);
1213-
1214-
this.preProcess(frame, dstInput).then(() => {
1212+
this.preProcess(frame, this.modelInput).then(() => {
12151213
const xinput = {
12161214
shape: [1, 3, 224, 224], // Input data shape in NCHW
1217-
data: dstInput.buffer,
1215+
data: this.modelInput.buffer,
12181216
type: 'float32', // Input data type
12191217
};
12201218

@@ -1245,7 +1243,7 @@ export class Classifier {
12451243
index = i
12461244
}
12471245
}
1248-
1246+
12491247
this.getClass(index);
12501248

12511249
resolve();

miniprogram/packageAPI/pages/ai/mobilenet/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Page({
4141
* 生命周期函数--监听页面初次渲染完成
4242
*/
4343
onReady() {
44-
this.ctx = wx.createCanvasContext('ssd');
44+
this.ctx = wx.createCanvasContext('ssd1');
4545
const context = wx.createCameraContext(this);
4646
this.initClassifier();
4747
this.fpsHelper = new FpsHelper();
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
<!--pages/mobilenet/index.wxml-->
2-
<app-nav />
3-
<camera class="camera" device-position="back" flash="off" frame-size="medium">
4-
<canvas class="canvas" canvas-id="ssd"></canvas>
5-
</camera>
6-
7-
<text class="subtitle"> 分类结果: {{predClass}}</text>
8-
9-
<view wx:if="{{enableSpeedTest}}">
10-
<text class="subtitle"> 平均耗时(ms): {{avgTime}}</text>
11-
<text class="subtitle"> 最小耗时(ms): {{minTime}}</text>
1+
<!--pages/mobilenet_int8/index.wxml-->
2+
<view class="container page" data-weui-theme="{{theme}}">
3+
<camera style=" width: 100%; height: 70vh;" device-position="back" flash="off" frame-size="medium">
4+
<canvas canvas-id="ssd1"></canvas>
5+
</camera>
6+
<view style="margin: 30px auto; position: relative"> 分类结果: {{predClass}}</view>
7+
<view style="margin: 30px auto; position: relative" wx:if="{{enableSpeedTest}}">
8+
<text class="subtitle"> 平均耗时(ms): {{avgTime}}</text>
9+
<text class="subtitle"> 最小耗时(ms): {{minTime}}</text>
10+
</view>
1211
</view>
13-
14-
<van-toast id="van-toast" />

miniprogram/packageAPI/pages/ai/mobilenet/index.wxss

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
/* pages/mobilenet/index.wxss */
33
.camera {
44
width: 100%;
5-
height: 80vh;
5+
height: 70vh;
66
}
77

88
.canvas {
99
width: 100%;
1010
height: 100vh;
1111
}
1212

13-
.subtitle {
14-
color: #5f6368;
13+
.textstyle {
14+
color: #e0a165;
1515
font-size: 28rpx;
1616
line-height: 1.6;
1717
}

miniprogram/packageAPI/pages/ai/mobilenet_int8/classify.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,15 @@ export class Classifier {
10251025

10261026
speedTime = 0.0;
10271027

1028-
//modelInput = null;
1028+
modelInput = null;
10291029

10301030
constructor(displaySize) {
10311031
this.displaySize = {
10321032
width: displaySize.width,
10331033
height: displaySize.height,
10341034
};
10351035

1036-
//this.modelInput = new Float32Array(modelWidth * modelHeight * 3);
1036+
this.modelInput = new Float32Array(modelWidth * modelHeight * modelChannel);
10371037

10381038
this.ready = false;
10391039
}
@@ -1208,12 +1208,10 @@ export class Classifier {
12081208
{
12091209
return new Promise((resolve, reject) =>
12101210
{
1211-
var dstInput = new Float32Array(modelChannel * modelHeight * modelWidth);
1212-
1213-
this.preProcess(frame, dstInput).then(() => {
1211+
this.preProcess(frame, this.modelInput).then(() => {
12141212
const xinput = {
12151213
shape: [1, 3, 224, 224], // Input data shape in NCHW
1216-
data: dstInput.buffer,
1214+
data: this.modelInput.buffer,
12171215
type: 'float32', // Input data type
12181216
};
12191217

0 commit comments

Comments
 (0)