Skip to content

Commit 8db7ba1

Browse files
committed
optimize mobilenet demo
1 parent b10b99a commit 8db7ba1

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

libraries/Maxi_KPU/examples/mobilenet_v1/MBNet_1000.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
#include "MBNet_1000.h"
99
#include "names.h"
1010
#include "stdlib.h"
11+
#include "errno.h"
1112

1213

1314
MBNet_1000::MBNet_1000(KPUClass& kpu, Sipeed_ST7789& lcd, Sipeed_OV2640& camera)
1415
:_kpu(kpu),_lcd(lcd), _camera(camera),
15-
_count(0), _result(nullptr)
16+
_model(nullptr), _count(0), _result(nullptr)
1617
{
1718
_names = mbnet_label_name;
1819
memset(_statistics, 0, sizeof(_statistics));
1920
}
2021

2122
MBNet_1000::~MBNet_1000()
2223
{
23-
24+
if(_model)
25+
free(_model);
2426
}
2527

2628

@@ -32,25 +34,44 @@ int MBNet_1000::begin(const char* kmodel_name)
3234
if(!_lcd.begin(15000000, COLOR_RED))
3335
return -2;
3436
_camera.run(true);
37+
_lcd.setTextSize(2);
38+
_lcd.setTextColor(COLOR_WHITE);
3539

3640
if (!SD.begin())
41+
{
42+
_lcd.setCursor(100,100);
43+
_lcd.print("No SD Card");
3744
return -3;
45+
}
3846

3947
myFile = SD.open(kmodel_name);
4048
if (!myFile)
4149
return -4;
4250
uint32_t fSize = myFile.size();
43-
_lcd.setTextSize(2);
44-
_lcd.setTextColor(COLOR_WHITE);
4551
_lcd.setCursor(100,100);
4652
_lcd.print("Loading ... ");
53+
_model = (uint8_t*)malloc(fSize);
54+
if(!_model)
55+
{
56+
_lcd.setCursor(100,140);
57+
_lcd.print("Memmory not enough ... ");
58+
return ENOMEM;
59+
}
4760
long ret = myFile.read(_model, fSize);
4861
myFile.close();
4962
if(ret != fSize)
63+
{
64+
free(_model);
65+
_model = nullptr;
5066
return -5;
67+
}
5168

5269
if(_kpu.begin(_model) != 0)
70+
{
71+
free(_model);
72+
_model = nullptr;
5373
return -6;
74+
}
5475
return 0;
5576
}
5677

libraries/Maxi_KPU/examples/mobilenet_v1/MBNet_1000.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class MBNet_1000{
3737
KPUClass& _kpu;
3838
Sipeed_ST7789& _lcd;
3939
Sipeed_OV2640& _camera;
40-
uint8_t _model[KMODEL_SIZE] __attribute__((aligned(128)));
41-
size_t _count;
40+
uint8_t* _model;
41+
size_t _count;
4242
statistics_t _statistics[STATISTICS_NUM];
4343
float* _result;
4444
uint16_t _index[1000];

0 commit comments

Comments
 (0)