Rolling 20210420

This commit is contained in:
jomjol
2021-04-20 19:44:16 +02:00
parent 520f818adc
commit ea2305de47
156 changed files with 11095 additions and 8601 deletions

View File

@@ -6,9 +6,13 @@
// #define DEBUG_DETAIL_ON
//#define GET_MEMORY(X) malloc(X)
#define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
float CTfLiteClass::GetOutputValue(int nr)
{
TfLiteTensor* output2 = this->interpreter->output(0);
TfLiteTensor* output2 = interpreter->output(0);
int numeroutput = output2->dims->data[1];
if ((nr+1) > numeroutput)
@@ -53,7 +57,7 @@ int CTfLiteClass::GetOutClassification()
void CTfLiteClass::GetInputDimension(bool silent = false)
{
TfLiteTensor* input2 = this->interpreter->input(0);
TfLiteTensor* input2 = interpreter->input(0);
int numdim = input2->dims->size;
if (!silent) printf("NumDimension: %d\n", numdim);
@@ -72,7 +76,7 @@ void CTfLiteClass::GetInputDimension(bool silent = false)
void CTfLiteClass::GetOutPut()
{
TfLiteTensor* output2 = this->interpreter->output(0);
TfLiteTensor* output2 = interpreter->output(0);
int numdim = output2->dims->size;
printf("NumDimension: %d\n", numdim);
@@ -142,20 +146,20 @@ void CTfLiteClass::MakeAllocate()
static tflite::AllOpsResolver resolver;
// printf(LogFile.getESPHeapInfo().c_str()); printf("\n");
this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
interpreter = new tflite::MicroInterpreter(model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
// printf(LogFile.getESPHeapInfo().c_str()); printf("\n");
TfLiteStatus allocate_status = this->interpreter->AllocateTensors();
TfLiteStatus allocate_status = interpreter->AllocateTensors();
if (allocate_status != kTfLiteOk) {
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
this->GetInputDimension();
GetInputDimension();
return;
}
// printf("Allocate Done.\n");
}
void CTfLiteClass::GetInputTensorSize(){
float *zw = this->input;
float *zw = input;
int test = sizeof(zw);
#ifdef DEBUG_DETAIL_ON
printf("Input Tensor Dimension: %d\n", test);
@@ -211,36 +215,39 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
void CTfLiteClass::LoadModel(std::string _fn){
#ifdef SUPRESS_TFLITE_ERRORS
this->error_reporter = new tflite::OwnMicroErrorReporter;
error_reporter = new tflite::OwnMicroErrorReporter;
#else
this->error_reporter = new tflite::MicroErrorReporter;
error_reporter = new tflite::MicroErrorReporter;
#endif
unsigned char *rd;
rd = ReadFileToCharArray(_fn.c_str());
this->model = tflite::GetModel(rd);
model = tflite::GetModel(rd);
free(rd);
TFLITE_MINIMAL_CHECK(model != nullptr);
MakeAllocate();
}
CTfLiteClass::CTfLiteClass()
{
this->model = nullptr;
this->interpreter = nullptr;
this->input = nullptr;
this->output = nullptr;
this->kTensorArenaSize = 200 * 1024; /// laut testfile: 108000 - bisher 600
this->tensor_arena = new uint8_t[kTensorArenaSize];
model = nullptr;
interpreter = nullptr;
input = nullptr;
output = nullptr;
kTensorArenaSize = 200 * 1024; /// laut testfile: 108000 - bisher 600
tensor_arena = (uint8_t*) GET_MEMORY(kTensorArenaSize);
// tensor_arena = new uint8_t[kTensorArenaSize];
}
CTfLiteClass::~CTfLiteClass()
{
delete this->tensor_arena;
delete this->interpreter;
delete this->error_reporter;
delete tensor_arena;
delete interpreter;
delete error_reporter;
}

View File

@@ -9,7 +9,7 @@
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
//#include "tensorflow/lite/version.h"
#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "esp_err.h"
#include "esp_log.h"
@@ -41,7 +41,7 @@ class CTfLiteClass
const tflite::Model* model;
tflite::MicroInterpreter* interpreter;
TfLiteTensor* output = nullptr;
static tflite::AllOpsResolver resolver;
tflite::AllOpsResolver resolver;
int kTensorArenaSize;
uint8_t *tensor_arena;
@@ -52,12 +52,12 @@ class CTfLiteClass
long GetFileSize(std::string filename);
unsigned char* ReadFileToCharArray(std::string _fn);
void MakeAllocate();
public:
CTfLiteClass();
~CTfLiteClass();
void LoadModel(std::string _fn);
void MakeAllocate();
void GetInputTensorSize();
bool LoadInputImageBasis(CImageBasis *rs);
void Invoke();

View File

@@ -128,31 +128,6 @@ void blink_task_doFlow(void *pvParameter)
xHandleblink_task_doFlow = NULL;
}
esp_err_t handler_init(httpd_req_t *req)
{
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_init - Start");
printf("handler_doinit uri:\n"); printf(req->uri); printf("\n");
#endif
char* resp_str = "Init started<br>";
httpd_resp_send(req, resp_str, strlen(resp_str));
doInit();
resp_str = "Init done<br>";
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_init - Done");
#endif
return ESP_OK;
};
esp_err_t handler_doflow(httpd_req_t *req)
{
#ifdef DEBUG_DETAIL_ON
@@ -434,44 +409,6 @@ esp_err_t handler_editflow(httpd_req_t *req)
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("test_align") == 0)
{
std::string _host = "";
if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
_host = std::string(_valuechar);
}
// printf("Parameter host: "); printf(_host.c_str()); printf("\n");
// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Alignment]", _host);
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("test_analog") == 0)
{
std::string _host = "";
if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
_host = std::string(_valuechar);
}
// printf("Parameter host: "); printf(_host.c_str()); printf("\n");
// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Analog]", _host);
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("test_digits") == 0)
{
std::string _host = "";
if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
_host = std::string(_valuechar);
}
// printf("Parameter host: "); printf(_host.c_str()); printf("\n");
// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Digits]", _host);
httpd_resp_sendstr_chunk(req, zw.c_str());
}
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_sendstr_chunk(req, NULL);
@@ -606,11 +543,6 @@ void register_server_tflite_uri(httpd_handle_t server)
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;
camuri.uri = "/doinit";
camuri.handler = handler_init;
camuri.user_ctx = (void*) "Light On";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/setPreValue.html";
camuri.handler = handler_prevalue;
camuri.user_ctx = (void*) "Prevalue";
@@ -620,7 +552,6 @@ void register_server_tflite_uri(httpd_handle_t server)
camuri.handler = handler_doflow;
camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/editflow.html";
camuri.handler = handler_editflow;