Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve aidemo code style #103

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions miniprogram/packageAPI/pages/ai/mobilenet/classify.js
Original file line number Diff line number Diff line change
@@ -1025,15 +1025,15 @@ export class Classifier {

speedTime = 0.0;

//modelInput = null;
modelInput = null;

constructor(displaySize) {
this.displaySize = {
width: displaySize.width,
height: displaySize.height,
};

//this.modelInput = new Float32Array(modelWidth * modelHeight * 3);
this.modelInput = new Float32Array(modelWidth * modelHeight * modelChannel);

this.ready = false;
}
@@ -1209,12 +1209,10 @@ export class Classifier {
{
return new Promise((resolve, reject) =>
{
var dstInput = new Float32Array(modelChannel * modelHeight * modelWidth);

this.preProcess(frame, dstInput).then(() => {
this.preProcess(frame, this.modelInput).then(() => {
const xinput = {
shape: [1, 3, 224, 224], // Input data shape in NCHW
data: dstInput.buffer,
data: this.modelInput.buffer,
type: 'float32', // Input data type
};

@@ -1245,7 +1243,7 @@ export class Classifier {
index = i
}
}

this.getClass(index);

resolve();
2 changes: 1 addition & 1 deletion miniprogram/packageAPI/pages/ai/mobilenet/index.js
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ Page({
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
this.ctx = wx.createCanvasContext('ssd');
this.ctx = wx.createCanvasContext('ssd1');
const context = wx.createCameraContext(this);
this.initClassifier();
this.fpsHelper = new FpsHelper();
23 changes: 10 additions & 13 deletions miniprogram/packageAPI/pages/ai/mobilenet/index.wxml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<!--pages/mobilenet/index.wxml-->
<app-nav />
<camera class="camera" device-position="back" flash="off" frame-size="medium">
<canvas class="canvas" canvas-id="ssd"></canvas>
</camera>

<text class="subtitle"> 分类结果: {{predClass}}</text>

<view wx:if="{{enableSpeedTest}}">
<text class="subtitle"> 平均耗时(ms): {{avgTime}}</text>
<text class="subtitle"> 最小耗时(ms): {{minTime}}</text>
<!--pages/mobilenet_int8/index.wxml-->
<view class="container page" data-weui-theme="{{theme}}">
<camera style=" width: 100%; height: 70vh;" device-position="back" flash="off" frame-size="medium">
<canvas canvas-id="ssd1"></canvas>
</camera>
<view style="margin: 30px auto; position: relative"> 分类结果: {{predClass}}</view>
<view style="margin: 30px auto; position: relative" wx:if="{{enableSpeedTest}}">
<text class="subtitle"> 平均耗时(ms): {{avgTime}}</text>
<text class="subtitle"> 最小耗时(ms): {{minTime}}</text>
</view>
</view>

<van-toast id="van-toast" />
6 changes: 3 additions & 3 deletions miniprogram/packageAPI/pages/ai/mobilenet/index.wxss
Original file line number Diff line number Diff line change
@@ -2,16 +2,16 @@
/* pages/mobilenet/index.wxss */
.camera {
width: 100%;
height: 80vh;
height: 70vh;
}

.canvas {
width: 100%;
height: 100vh;
}

.subtitle {
color: #5f6368;
.textstyle {
color: #e0a165;
font-size: 28rpx;
line-height: 1.6;
}
10 changes: 4 additions & 6 deletions miniprogram/packageAPI/pages/ai/mobilenet_int8/classify.js
Original file line number Diff line number Diff line change
@@ -1025,15 +1025,15 @@ export class Classifier {

speedTime = 0.0;

//modelInput = null;
modelInput = null;

constructor(displaySize) {
this.displaySize = {
width: displaySize.width,
height: displaySize.height,
};

//this.modelInput = new Float32Array(modelWidth * modelHeight * 3);
this.modelInput = new Float32Array(modelWidth * modelHeight * modelChannel);

this.ready = false;
}
@@ -1208,12 +1208,10 @@ export class Classifier {
{
return new Promise((resolve, reject) =>
{
var dstInput = new Float32Array(modelChannel * modelHeight * modelWidth);

this.preProcess(frame, dstInput).then(() => {
this.preProcess(frame, this.modelInput).then(() => {
const xinput = {
shape: [1, 3, 224, 224], // Input data shape in NCHW
data: dstInput.buffer,
data: this.modelInput.buffer,
type: 'float32', // Input data type
};