Waitmissing for missing memory

This commit is contained in:
jomjol
2020-12-23 11:09:27 +01:00
parent 9971c82e99
commit 7e4f83c2f5
14 changed files with 39 additions and 96 deletions

View File

@@ -116,7 +116,7 @@ string ClassFlowAlignment::getHTMLSingleStep(string host)
bool ClassFlowAlignment::doFlow(string time)
{
if (!ImageTMP)
ImageTMP = new CImageBasis(ImageBasis);
ImageTMP = new CImageBasis(ImageBasis, 5);
if (AlignAndCutImage)
delete AlignAndCutImage;

View File

@@ -23,7 +23,7 @@ void ClassFlowAnalog::SetInitialParameter(void)
modelysize = 1;
ListFlowControll = NULL;
previousElement = NULL;
SaveAllFiles = true;
SaveAllFiles = false;
}
ClassFlowAnalog::ClassFlowAnalog(std::vector<ClassFlow*>* lfc) : ClassFlowImage(lfc, TAG)

View File

@@ -202,15 +202,11 @@ bool ClassFlowControll::doFlow(string time)
/////////////////////////////////////////////////////
int aInternalFreeHeapSizeAtEnd, aInternalFreeHeapSizeAtStart;
aInternalFreeHeapSizeAtStart = getInternalESPHeapSize();
if (flowcontrolldebugdetail){
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Start: " + getESPHeapInfo();
LogFile.WriteToFile(aStartEspInfoStr);
}
aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize();
if (flowcontrolldebugdetail){
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
LogFile.WriteToFile(aStartEspInfoStr);
@@ -241,7 +237,6 @@ bool ClassFlowControll::doFlow(string time)
result = true;
}
aInternalFreeHeapSizeAtEnd = getInternalESPHeapSize();
if (flowcontrolldebugdetail){
std::string aStartEspInfoStr = "ClassFlowAnalog::doFlow - Now : " + getESPHeapInfo();
LogFile.WriteToFile(aStartEspInfoStr);

View File

@@ -24,7 +24,7 @@ void ClassFlowDigit::SetInitialParameter(void)
modelysize = 1;
ListFlowControll = NULL;
previousElement = NULL;
SaveAllFiles = true;
SaveAllFiles = false;
}
ClassFlowDigit::ClassFlowDigit() : ClassFlowImage(TAG)

View File

@@ -283,7 +283,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
}
CImageBasis::CImageBasis(CImageBasis *_copyfrom)
CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat)
{
externalImage = false;
channels = _copyfrom->channels;
@@ -293,6 +293,18 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom)
int memsize = width * height * channels;
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)
{
printf(getESPHeapInfo().c_str());

View File

@@ -65,7 +65,7 @@ class CImageBasis
CImageBasis(std::string _image);
CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp);
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, CImageBasis *_target);

View File

@@ -1,9 +1,8 @@
#include "CTfLiteClass.h"
#include "bitmap_image.hpp"
// #include "bitmap_image.hpp"
#include "ClassLogFile.h"
#include "Helper.h"
#include <sys/stat.h>
@@ -33,20 +32,6 @@ int CTfLiteClass::GetClassFromImageBasis(CImageBasis *rs)
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()
{
TfLiteTensor* output2 = interpreter->output(0);
@@ -128,13 +113,10 @@ void CTfLiteClass::Invoke()
bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
{
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach LoadInputResizeImage: ";
// LogFile.WriteToFile(zw);
unsigned int w = rs->width;
unsigned int h = rs->height;
unsigned char red, green, blue;
// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h);
input_i = 0;
@@ -152,49 +134,6 @@ bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs)
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");
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");
@@ -205,7 +144,6 @@ bool CTfLiteClass::LoadInputImage(std::string _fn)
void CTfLiteClass::MakeAllocate()
{
// static tflite::ops::micro::AllOpsResolver resolver;
static tflite::AllOpsResolver resolver;
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();
return;
}
// printf("Allocate Done.\n");
}
@@ -223,8 +160,6 @@ void CTfLiteClass::GetInputTensorSize(){
float *zw = this->input;
int test = sizeof(zw);
printf("Input Tensor Dimension: %d\n", test);
printf("Input Tensor Dimension: %d\n", test);
}
long CTfLiteClass::GetFileSize(std::string filename)
@@ -239,7 +174,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
{
long size;
size = this->GetFileSize(_fn);
size = GetFileSize(_fn);
if (size == -1)
{
@@ -247,16 +182,25 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
return NULL;
}
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");
FILE* f = OpenFileAndWait(_fn.c_str(), "rb"); // vorher nur "r"
fread(result, 1, size, f);
fclose(f);
}else {
printf("\nKein freier Speicher vorhanden.\n");
}else {
printf("\nKein freier Speicher vorhanden.\n");
}
@@ -272,14 +216,11 @@ void CTfLiteClass::LoadModel(std::string _fn){
#endif
unsigned char *rd;
rd = this->ReadFileToCharArray(_fn.c_str());
// printf("loadedfile: %d", (int) rd);
rd = ReadFileToCharArray(_fn.c_str());
this->model = tflite::GetModel(rd);
free(rd);
TFLITE_MINIMAL_CHECK(model != nullptr);
// printf("tfile Loaded.\n");
}
@@ -308,6 +249,6 @@ namespace tflite {
return 0;
}
} // namespace tflite
}

View File

@@ -41,7 +41,6 @@ class CTfLiteClass
const tflite::Model* model;
tflite::MicroInterpreter* interpreter;
TfLiteTensor* output = nullptr;
// static tflite::ops::micro::AllOpsResolver *resolver;
static tflite::AllOpsResolver resolver;
int kTensorArenaSize;
@@ -60,12 +59,10 @@ class CTfLiteClass
void LoadModel(std::string _fn);
void MakeAllocate();
void GetInputTensorSize();
bool LoadInputImage(std::string _fn);
bool LoadInputImageBasis(CImageBasis *rs);
void Invoke();
void GetOutPut();
int GetOutClassification();
int GetClassFromImage(std::string _fn);
int GetClassFromImageBasis(CImageBasis *rs);
float GetOutputValue(int nr);