mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2026-01-31 14:51:02 +03:00
Waitmissing for missing memory
This commit is contained in:
@@ -116,7 +116,7 @@ string ClassFlowAlignment::getHTMLSingleStep(string host)
|
|||||||
bool ClassFlowAlignment::doFlow(string time)
|
bool ClassFlowAlignment::doFlow(string time)
|
||||||
{
|
{
|
||||||
if (!ImageTMP)
|
if (!ImageTMP)
|
||||||
ImageTMP = new CImageBasis(ImageBasis);
|
ImageTMP = new CImageBasis(ImageBasis, 5);
|
||||||
|
|
||||||
if (AlignAndCutImage)
|
if (AlignAndCutImage)
|
||||||
delete AlignAndCutImage;
|
delete AlignAndCutImage;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void ClassFlowAnalog::SetInitialParameter(void)
|
|||||||
modelysize = 1;
|
modelysize = 1;
|
||||||
ListFlowControll = NULL;
|
ListFlowControll = NULL;
|
||||||
previousElement = NULL;
|
previousElement = NULL;
|
||||||
SaveAllFiles = true;
|
SaveAllFiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassFlowAnalog::ClassFlowAnalog(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
|
ClassFlowAnalog::ClassFlowAnalog(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)
|
||||||
|
|||||||
@@ -202,15 +202,11 @@ bool ClassFlowControll::doFlow(string time)
|
|||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
int aInternalFreeHeapSizeAtEnd, aInternalFreeHeapSizeAtStart;
|
|
||||||
aInternalFreeHeapSizeAtStart = getInternalESPHeapSize();
|
|
||||||
|
|
||||||
if (flowcontrolldebugdetail){
|
if (flowcontrolldebugdetail){
|
||||||
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Start: " + getESPHeapInfo();
|
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Start: " + getESPHeapInfo();
|
||||||
LogFile.WriteToFile(aStartEspInfoStr);
|
LogFile.WriteToFile(aStartEspInfoStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize();
|
|
||||||
if (flowcontrolldebugdetail){
|
if (flowcontrolldebugdetail){
|
||||||
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
|
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
|
||||||
LogFile.WriteToFile(aStartEspInfoStr);
|
LogFile.WriteToFile(aStartEspInfoStr);
|
||||||
@@ -241,7 +237,6 @@ bool ClassFlowControll::doFlow(string time)
|
|||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize();
|
|
||||||
if (flowcontrolldebugdetail){
|
if (flowcontrolldebugdetail){
|
||||||
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
|
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
|
||||||
LogFile.WriteToFile(aStartEspInfoStr);
|
LogFile.WriteToFile(aStartEspInfoStr);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ void ClassFlowDigit::SetInitialParameter(void)
|
|||||||
modelysize = 1;
|
modelysize = 1;
|
||||||
ListFlowControll = NULL;
|
ListFlowControll = NULL;
|
||||||
previousElement = NULL;
|
previousElement = NULL;
|
||||||
SaveAllFiles = true;
|
SaveAllFiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassFlowDigit::ClassFlowDigit() : ClassFlowImage(TAG)
|
ClassFlowDigit::ClassFlowDigit() : ClassFlowImage(TAG)
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CImageBasis::CImageBasis(CImageBasis *_copyfrom)
|
CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat)
|
||||||
{
|
{
|
||||||
externalImage = false;
|
externalImage = false;
|
||||||
channels = _copyfrom->channels;
|
channels = _copyfrom->channels;
|
||||||
@@ -293,6 +293,18 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
|
|||||||
|
|
||||||
int memsize = width * height * channels;
|
int memsize = width * height * channels;
|
||||||
rgb_image = (unsigned char*)GET_MEMORY(memsize);
|
rgb_image = (unsigned char*)GET_MEMORY(memsize);
|
||||||
|
|
||||||
|
int anz = 1;
|
||||||
|
TickType_t xDelay;
|
||||||
|
while (!rgb_image && (anz < _anzrepeat))
|
||||||
|
{
|
||||||
|
printf("Create Image from Copy - Speicher ist voll - Versuche es erneut: %d.\n", anz);
|
||||||
|
xDelay = 1000 / portTICK_PERIOD_MS;
|
||||||
|
rgb_image = (unsigned char*) malloc(memsize);
|
||||||
|
anz++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!rgb_image)
|
if (!rgb_image)
|
||||||
{
|
{
|
||||||
printf(getESPHeapInfo().c_str());
|
printf(getESPHeapInfo().c_str());
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class CImageBasis
|
|||||||
CImageBasis(std::string _image);
|
CImageBasis(std::string _image);
|
||||||
CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
|
CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
|
||||||
CImageBasis(int _width, int _height, int _channels);
|
CImageBasis(int _width, int _height, int _channels);
|
||||||
CImageBasis(CImageBasis *_copyfrom);
|
CImageBasis(CImageBasis *_copyfrom, int _anzrepeat = 0);
|
||||||
|
|
||||||
void Resize(int _new_dx, int _new_dy);
|
void Resize(int _new_dx, int _new_dy);
|
||||||
void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
|
void Resize(int _new_dx, int _new_dy, CImageBasis *_target);
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "CTfLiteClass.h"
|
#include "CTfLiteClass.h"
|
||||||
|
|
||||||
#include "bitmap_image.hpp"
|
// #include "bitmap_image.hpp"
|
||||||
|
|
||||||
#include "ClassLogFile.h"
|
#include "ClassLogFile.h"
|
||||||
|
|
||||||
#include "Helper.h"
|
#include "Helper.h"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -33,20 +32,6 @@ int CTfLiteClass::GetClassFromImageBasis(CImageBasis *rs)
|
|||||||
return GetOutClassification();
|
return GetOutClassification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int CTfLiteClass::GetClassFromImage(std::string _fn)
|
|
||||||
{
|
|
||||||
// printf("Before Load image %s\n", _fn.c_str());
|
|
||||||
if (!LoadInputImage(_fn))
|
|
||||||
return -1000;
|
|
||||||
// printf("After Load image %s\n", _fn.c_str());
|
|
||||||
|
|
||||||
Invoke();
|
|
||||||
printf("After Invoke %s\n", _fn.c_str());
|
|
||||||
|
|
||||||
return GetOutClassification();
|
|
||||||
}
|
|
||||||
|
|
||||||
int CTfLiteClass::GetOutClassification()
|
int CTfLiteClass::GetOutClassification()
|
||||||
{
|
{
|
||||||
TfLiteTensor* output2 = interpreter->output(0);
|
TfLiteTensor* output2 = interpreter->output(0);
|
||||||
@@ -128,13 +113,10 @@ void CTfLiteClass::Invoke()
|
|||||||
bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
|
bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
|
||||||
{
|
{
|
||||||
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach LoadInputResizeImage: ";
|
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach LoadInputResizeImage: ";
|
||||||
// LogFile.WriteToFile(zw);
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int w = rs->width;
|
unsigned int w = rs->width;
|
||||||
unsigned int h = rs->height;
|
unsigned int h = rs->height;
|
||||||
unsigned char red, green, blue;
|
unsigned char red, green, blue;
|
||||||
|
|
||||||
// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
|
// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
|
||||||
|
|
||||||
input_i = 0;
|
input_i = 0;
|
||||||
@@ -152,49 +134,6 @@ bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
|
|||||||
input_data_ptr++;
|
input_data_ptr++;
|
||||||
*(input_data_ptr) = (float) blue;
|
*(input_data_ptr) = (float) blue;
|
||||||
input_data_ptr++;
|
input_data_ptr++;
|
||||||
|
|
||||||
// printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CTfLiteClass::LoadInputImage(std::string _fn)
|
|
||||||
{
|
|
||||||
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach Load Image: " + _fn;
|
|
||||||
// LogFile.WriteToFile(zw);
|
|
||||||
bitmap_image image(_fn);
|
|
||||||
if (debugdetailtflite) LogFile.WriteToFile(zw);
|
|
||||||
|
|
||||||
unsigned int w = image.width();
|
|
||||||
unsigned int h = image.height();
|
|
||||||
unsigned char red, green, blue;
|
|
||||||
|
|
||||||
// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
|
|
||||||
|
|
||||||
input_i = 0;
|
|
||||||
float* input_data_ptr = (interpreter->input(0))->data.f;
|
|
||||||
|
|
||||||
for (int y = 0; y < h; ++y)
|
|
||||||
for (int x = 0; x < w; ++x)
|
|
||||||
{
|
|
||||||
red = image.red_channel(x, y);
|
|
||||||
green = image.green_channel(x, y);
|
|
||||||
blue = image.blue_channel(x, y);
|
|
||||||
*(input_data_ptr) = (float) red;
|
|
||||||
input_data_ptr++;
|
|
||||||
*(input_data_ptr) = (float) green;
|
|
||||||
input_data_ptr++;
|
|
||||||
*(input_data_ptr) = (float) blue;
|
|
||||||
input_data_ptr++;
|
|
||||||
|
|
||||||
// printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
|
if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
|
||||||
@@ -205,7 +144,6 @@ bool CTfLiteClass::LoadInputImage(std::string _fn)
|
|||||||
|
|
||||||
void CTfLiteClass::MakeAllocate()
|
void CTfLiteClass::MakeAllocate()
|
||||||
{
|
{
|
||||||
// static tflite::ops::micro::AllOpsResolver resolver;
|
|
||||||
static tflite::AllOpsResolver resolver;
|
static tflite::AllOpsResolver resolver;
|
||||||
this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
|
this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
|
||||||
|
|
||||||
@@ -215,7 +153,6 @@ void CTfLiteClass::MakeAllocate()
|
|||||||
this->GetInputDimension();
|
this->GetInputDimension();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("Allocate Done.\n");
|
// printf("Allocate Done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,8 +160,6 @@ void CTfLiteClass::GetInputTensorSize(){
|
|||||||
float *zw = this->input;
|
float *zw = this->input;
|
||||||
int test = sizeof(zw);
|
int test = sizeof(zw);
|
||||||
printf("Input Tensor Dimension: %d\n", test);
|
printf("Input Tensor Dimension: %d\n", test);
|
||||||
|
|
||||||
printf("Input Tensor Dimension: %d\n", test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long CTfLiteClass::GetFileSize(std::string filename)
|
long CTfLiteClass::GetFileSize(std::string filename)
|
||||||
@@ -239,7 +174,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
|
|||||||
{
|
{
|
||||||
long size;
|
long size;
|
||||||
|
|
||||||
size = this->GetFileSize(_fn);
|
size = GetFileSize(_fn);
|
||||||
|
|
||||||
if (size == -1)
|
if (size == -1)
|
||||||
{
|
{
|
||||||
@@ -247,16 +182,25 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char *result = (unsigned char*) malloc(size);
|
unsigned char *result = (unsigned char*) malloc(size);
|
||||||
|
int anz = 1;
|
||||||
|
TickType_t xDelay;
|
||||||
|
while (!result && (anz < 6)) // maximal 5x versuchen (= 5s)
|
||||||
|
{
|
||||||
|
printf("Speicher ist voll - Versuche es erneut: %d.\n", anz);
|
||||||
|
xDelay = 1000 / portTICK_PERIOD_MS;
|
||||||
|
result = (unsigned char*) malloc(size);
|
||||||
|
anz++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(result != NULL) {
|
if(result != NULL) {
|
||||||
// printf("\nSpeicher ist reserviert\n");
|
// printf("\nSpeicher ist reserviert\n");
|
||||||
FILE* f = OpenFileAndWait(_fn.c_str(), "rb"); // vorher nur "r"
|
FILE* f = OpenFileAndWait(_fn.c_str(), "rb"); // vorher nur "r"
|
||||||
fread(result, 1, size, f);
|
fread(result, 1, size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}else {
|
}else {
|
||||||
printf("\nKein freier Speicher vorhanden.\n");
|
printf("\nKein freier Speicher vorhanden.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -272,14 +216,11 @@ void CTfLiteClass::LoadModel(std::string _fn){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned char *rd;
|
unsigned char *rd;
|
||||||
rd = this->ReadFileToCharArray(_fn.c_str());
|
rd = ReadFileToCharArray(_fn.c_str());
|
||||||
// printf("loadedfile: %d", (int) rd);
|
|
||||||
|
|
||||||
this->model = tflite::GetModel(rd);
|
this->model = tflite::GetModel(rd);
|
||||||
free(rd);
|
free(rd);
|
||||||
TFLITE_MINIMAL_CHECK(model != nullptr);
|
TFLITE_MINIMAL_CHECK(model != nullptr);
|
||||||
// printf("tfile Loaded.\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -308,6 +249,6 @@ namespace tflite {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tflite
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class CTfLiteClass
|
|||||||
const tflite::Model* model;
|
const tflite::Model* model;
|
||||||
tflite::MicroInterpreter* interpreter;
|
tflite::MicroInterpreter* interpreter;
|
||||||
TfLiteTensor* output = nullptr;
|
TfLiteTensor* output = nullptr;
|
||||||
// static tflite::ops::micro::AllOpsResolver *resolver;
|
|
||||||
static tflite::AllOpsResolver resolver;
|
static tflite::AllOpsResolver resolver;
|
||||||
|
|
||||||
int kTensorArenaSize;
|
int kTensorArenaSize;
|
||||||
@@ -60,12 +59,10 @@ class CTfLiteClass
|
|||||||
void LoadModel(std::string _fn);
|
void LoadModel(std::string _fn);
|
||||||
void MakeAllocate();
|
void MakeAllocate();
|
||||||
void GetInputTensorSize();
|
void GetInputTensorSize();
|
||||||
bool LoadInputImage(std::string _fn);
|
|
||||||
bool LoadInputImageBasis(CImageBasis *rs);
|
bool LoadInputImageBasis(CImageBasis *rs);
|
||||||
void Invoke();
|
void Invoke();
|
||||||
void GetOutPut();
|
void GetOutPut();
|
||||||
int GetOutClassification();
|
int GetOutClassification();
|
||||||
int GetClassFromImage(std::string _fn);
|
|
||||||
int GetClassFromImageBasis(CImageBasis *rs);
|
int GetClassFromImageBasis(CImageBasis *rs);
|
||||||
|
|
||||||
float GetOutputValue(int nr);
|
float GetOutputValue(int nr);
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ esp_err_t starttime_get_handler(httpd_req_t *req)
|
|||||||
esp_err_t hello_main_handler(httpd_req_t *req)
|
esp_err_t hello_main_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
char filepath[50];
|
char filepath[50];
|
||||||
struct stat file_stat;
|
|
||||||
printf("uri: %s\n", req->uri);
|
printf("uri: %s\n", req->uri);
|
||||||
int _pos;
|
int _pos;
|
||||||
esp_err_t res;
|
esp_err_t res;
|
||||||
@@ -196,7 +195,6 @@ esp_err_t hello_main_handler(httpd_req_t *req)
|
|||||||
esp_err_t img_tmp_handler(httpd_req_t *req)
|
esp_err_t img_tmp_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
char filepath[50];
|
char filepath[50];
|
||||||
struct stat file_stat;
|
|
||||||
printf("uri: %s\n", req->uri);
|
printf("uri: %s\n", req->uri);
|
||||||
|
|
||||||
char *base_path = (char*) req->user_ctx;
|
char *base_path = (char*) req->user_ctx;
|
||||||
@@ -236,7 +234,7 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req)
|
|||||||
|
|
||||||
if (filetosend == "raw.jpg")
|
if (filetosend == "raw.jpg")
|
||||||
{
|
{
|
||||||
return GetRawJPG(req);
|
return GetRawJPG(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t zw = GetJPG(filetosend, req);
|
esp_err_t zw = GetJPG(filetosend, req);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="b418525";
|
const char* GIT_REV="9971c82";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
||||||
const char* BUILD_TIME="2020-12-23 07:56";
|
const char* BUILD_TIME="2020-12-23 10:06";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="b418525";
|
const char* GIT_REV="9971c82";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
||||||
const char* BUILD_TIME="2020-12-23 07:56";
|
const char* BUILD_TIME="2020-12-23 10:06";
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user