mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 12:36:52 +03:00
Update Rolling
This commit is contained in:
@@ -27,7 +27,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### Rolling - (2020-11-21)
|
##### Rolling - (2020-11-26)
|
||||||
|
|
||||||
|
* Bug fixing: CheckDigitConsistency not always working (case zero crossing & no increase)
|
||||||
|
|
||||||
|
2020-11-21
|
||||||
|
|
||||||
* Implementation of standardized access to current logfile via `http://IP-ADRESS/logfileact` - implemented via internal redirect
|
* Implementation of standardized access to current logfile via `http://IP-ADRESS/logfileact` - implemented via internal redirect
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
#define CAMERA_MODEL_AI_THINKER
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(CAMERA_MODEL_WROVER_KIT)
|
|
||||||
#define PWDN_GPIO_NUM -1
|
|
||||||
#define RESET_GPIO_NUM -1
|
|
||||||
#define XCLK_GPIO_NUM 21
|
|
||||||
#define SIOD_GPIO_NUM 26
|
|
||||||
#define SIOC_GPIO_NUM 27
|
|
||||||
|
|
||||||
#define Y9_GPIO_NUM 35
|
|
||||||
#define Y8_GPIO_NUM 34
|
|
||||||
#define Y7_GPIO_NUM 39
|
|
||||||
#define Y6_GPIO_NUM 36
|
|
||||||
#define Y5_GPIO_NUM 19
|
|
||||||
#define Y4_GPIO_NUM 18
|
|
||||||
#define Y3_GPIO_NUM 5
|
|
||||||
#define Y2_GPIO_NUM 4
|
|
||||||
#define VSYNC_GPIO_NUM 25
|
|
||||||
#define HREF_GPIO_NUM 23
|
|
||||||
#define PCLK_GPIO_NUM 22
|
|
||||||
|
|
||||||
#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
|
|
||||||
#define PWDN_GPIO_NUM -1
|
|
||||||
#define RESET_GPIO_NUM 15
|
|
||||||
#define XCLK_GPIO_NUM 27
|
|
||||||
#define SIOD_GPIO_NUM 25
|
|
||||||
#define SIOC_GPIO_NUM 23
|
|
||||||
|
|
||||||
#define Y9_GPIO_NUM 19
|
|
||||||
#define Y8_GPIO_NUM 36
|
|
||||||
#define Y7_GPIO_NUM 18
|
|
||||||
#define Y6_GPIO_NUM 39
|
|
||||||
#define Y5_GPIO_NUM 5
|
|
||||||
#define Y4_GPIO_NUM 34
|
|
||||||
#define Y3_GPIO_NUM 35
|
|
||||||
#define Y2_GPIO_NUM 32
|
|
||||||
#define VSYNC_GPIO_NUM 22
|
|
||||||
#define HREF_GPIO_NUM 26
|
|
||||||
#define PCLK_GPIO_NUM 21
|
|
||||||
|
|
||||||
#elif defined(CAMERA_MODEL_AI_THINKER)
|
|
||||||
#define PWDN_GPIO_NUM GPIO_NUM_32
|
|
||||||
#define RESET_GPIO_NUM -1
|
|
||||||
#define XCLK_GPIO_NUM GPIO_NUM_0
|
|
||||||
#define SIOD_GPIO_NUM GPIO_NUM_26
|
|
||||||
#define SIOC_GPIO_NUM GPIO_NUM_27
|
|
||||||
|
|
||||||
#define Y9_GPIO_NUM GPIO_NUM_35
|
|
||||||
#define Y8_GPIO_NUM GPIO_NUM_34
|
|
||||||
#define Y7_GPIO_NUM GPIO_NUM_39
|
|
||||||
#define Y6_GPIO_NUM GPIO_NUM_36
|
|
||||||
#define Y5_GPIO_NUM GPIO_NUM_21
|
|
||||||
#define Y4_GPIO_NUM GPIO_NUM_19
|
|
||||||
#define Y3_GPIO_NUM GPIO_NUM_18
|
|
||||||
#define Y2_GPIO_NUM GPIO_NUM_5
|
|
||||||
#define VSYNC_GPIO_NUM GPIO_NUM_25
|
|
||||||
#define HREF_GPIO_NUM GPIO_NUM_23
|
|
||||||
#define PCLK_GPIO_NUM GPIO_NUM_22
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "Camera model not selected"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static camera_config_t camera_config = {
|
|
||||||
.pin_pwdn = PWDN_GPIO_NUM,
|
|
||||||
.pin_reset = RESET_GPIO_NUM,
|
|
||||||
.pin_xclk = XCLK_GPIO_NUM,
|
|
||||||
.pin_sscb_sda = SIOD_GPIO_NUM,
|
|
||||||
.pin_sscb_scl = SIOC_GPIO_NUM,
|
|
||||||
|
|
||||||
.pin_d7 = Y9_GPIO_NUM,
|
|
||||||
.pin_d6 = Y8_GPIO_NUM,
|
|
||||||
.pin_d5 = Y7_GPIO_NUM,
|
|
||||||
.pin_d4 = Y6_GPIO_NUM,
|
|
||||||
.pin_d3 = Y5_GPIO_NUM,
|
|
||||||
.pin_d2 = Y4_GPIO_NUM,
|
|
||||||
.pin_d1 = Y3_GPIO_NUM,
|
|
||||||
.pin_d0 = Y2_GPIO_NUM,
|
|
||||||
.pin_vsync = VSYNC_GPIO_NUM,
|
|
||||||
.pin_href = HREF_GPIO_NUM,
|
|
||||||
.pin_pclk = PCLK_GPIO_NUM,
|
|
||||||
|
|
||||||
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
|
|
||||||
.xclk_freq_hz = 20000000,
|
|
||||||
.ledc_timer = LEDC_TIMER_0,
|
|
||||||
.ledc_channel = LEDC_CHANNEL_0,
|
|
||||||
|
|
||||||
.pixel_format = PIXFORMAT_JPEG,//YUV422,GRAYSCALE,RGB565,JPEG
|
|
||||||
// .pixel_format = PIXFORMAT_RGB888,//YUV422,GRAYSCALE,RGB565,JPEG
|
|
||||||
.frame_size = FRAMESIZE_UXGA,//QQVGA-QXGA Do not use sizes above QVGA when not JPEG
|
|
||||||
|
|
||||||
.jpeg_quality = 5, //0-63 lower number means higher quality
|
|
||||||
.fb_count = 1 //if more than one, i2s runs in continuous mode. Use only with JPEG
|
|
||||||
};
|
|
||||||
@@ -1,206 +0,0 @@
|
|||||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
/*
|
|
||||||
* Example Use
|
|
||||||
*
|
|
||||||
static camera_config_t camera_example_config = {
|
|
||||||
.pin_pwdn = PIN_PWDN,
|
|
||||||
.pin_reset = PIN_RESET,
|
|
||||||
.pin_xclk = PIN_XCLK,
|
|
||||||
.pin_sscb_sda = PIN_SIOD,
|
|
||||||
.pin_sscb_scl = PIN_SIOC,
|
|
||||||
.pin_d7 = PIN_D7,
|
|
||||||
.pin_d6 = PIN_D6,
|
|
||||||
.pin_d5 = PIN_D5,
|
|
||||||
.pin_d4 = PIN_D4,
|
|
||||||
.pin_d3 = PIN_D3,
|
|
||||||
.pin_d2 = PIN_D2,
|
|
||||||
.pin_d1 = PIN_D1,
|
|
||||||
.pin_d0 = PIN_D0,
|
|
||||||
.pin_vsync = PIN_VSYNC,
|
|
||||||
.pin_href = PIN_HREF,
|
|
||||||
.pin_pclk = PIN_PCLK,
|
|
||||||
|
|
||||||
.xclk_freq_hz = 20000000,
|
|
||||||
.ledc_timer = LEDC_TIMER_0,
|
|
||||||
.ledc_channel = LEDC_CHANNEL_0,
|
|
||||||
.pixel_format = PIXFORMAT_JPEG,
|
|
||||||
.frame_size = FRAMESIZE_SVGA,
|
|
||||||
.jpeg_quality = 10,
|
|
||||||
.fb_count = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
esp_err_t camera_example_init(){
|
|
||||||
return esp_camera_init(&camera_example_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t camera_example_capture(){
|
|
||||||
//capture a frame
|
|
||||||
camera_fb_t * fb = esp_camera_fb_get();
|
|
||||||
if (!fb) {
|
|
||||||
ESP_LOGE(TAG, "Frame buffer could not be acquired");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//replace this with your own function
|
|
||||||
display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
|
|
||||||
|
|
||||||
//return the frame buffer back to be reused
|
|
||||||
esp_camera_fb_return(fb);
|
|
||||||
|
|
||||||
return ESP_OK;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef ESPCAMERADEF
|
|
||||||
#define ESPCAMERADEF
|
|
||||||
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "driver/ledc.h"
|
|
||||||
#include "sensor.h"
|
|
||||||
#include "sys/time.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration structure for camera initialization
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
typedef struct {
|
|
||||||
int pin_pwdn; /*!< GPIO pin for camera power down line */
|
|
||||||
int pin_reset; /*!< GPIO pin for camera reset line */
|
|
||||||
int pin_xclk; /*!< GPIO pin for camera XCLK line */
|
|
||||||
int pin_sscb_sda; /*!< GPIO pin for camera SDA line */
|
|
||||||
int pin_sscb_scl; /*!< GPIO pin for camera SCL line */
|
|
||||||
int pin_d7; /*!< GPIO pin for camera D7 line */
|
|
||||||
int pin_d6; /*!< GPIO pin for camera D6 line */
|
|
||||||
int pin_d5; /*!< GPIO pin for camera D5 line */
|
|
||||||
int pin_d4; /*!< GPIO pin for camera D4 line */
|
|
||||||
int pin_d3; /*!< GPIO pin for camera D3 line */
|
|
||||||
int pin_d2; /*!< GPIO pin for camera D2 line */
|
|
||||||
int pin_d1; /*!< GPIO pin for camera D1 line */
|
|
||||||
int pin_d0; /*!< GPIO pin for camera D0 line */
|
|
||||||
int pin_vsync; /*!< GPIO pin for camera VSYNC line */
|
|
||||||
int pin_href; /*!< GPIO pin for camera HREF line */
|
|
||||||
int pin_pclk; /*!< GPIO pin for camera PCLK line */
|
|
||||||
|
|
||||||
int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. Either 20KHz or 10KHz for OV2640 double FPS (Experimental) */
|
|
||||||
|
|
||||||
ledc_timer_t ledc_timer; /*!< LEDC timer to be used for generating XCLK */
|
|
||||||
ledc_channel_t ledc_channel; /*!< LEDC channel to be used for generating XCLK */
|
|
||||||
|
|
||||||
pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
|
|
||||||
framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
|
|
||||||
|
|
||||||
int jpeg_quality; /*!< Quality of JPEG output. 0-63 lower means higher quality */
|
|
||||||
size_t fb_count; /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) */
|
|
||||||
} camera_config_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data structure of camera frame buffer
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t * buf; /*!< Pointer to the pixel data */
|
|
||||||
size_t len; /*!< Length of the buffer in bytes */
|
|
||||||
size_t width; /*!< Width of the buffer in pixels */
|
|
||||||
size_t height; /*!< Height of the buffer in pixels */
|
|
||||||
pixformat_t format; /*!< Format of the pixel data */
|
|
||||||
struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
|
|
||||||
} camera_fb_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define ESP_ERR_CAMERA_BASE 0x20000
|
|
||||||
#define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
|
|
||||||
#define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
|
|
||||||
#define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 3)
|
|
||||||
#define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 4)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize the camera driver
|
|
||||||
*
|
|
||||||
* @note call camera_probe before calling this function
|
|
||||||
*
|
|
||||||
* This function detects and configures camera over I2C interface,
|
|
||||||
* allocates framebuffer and DMA buffers,
|
|
||||||
* initializes parallel I2S input, and sets up DMA descriptors.
|
|
||||||
*
|
|
||||||
* Currently this function can only be called once and there is
|
|
||||||
* no way to de-initialize this module.
|
|
||||||
*
|
|
||||||
* @param config Camera configuration parameters
|
|
||||||
*
|
|
||||||
* @return ESP_OK on success
|
|
||||||
*/
|
|
||||||
esp_err_t esp_camera_init(const camera_config_t* config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deinitialize the camera driver
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* - ESP_OK on success
|
|
||||||
* - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
|
|
||||||
*/
|
|
||||||
esp_err_t esp_camera_deinit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Obtain pointer to a frame buffer.
|
|
||||||
*
|
|
||||||
* @return pointer to the frame buffer
|
|
||||||
*/
|
|
||||||
camera_fb_t* esp_camera_fb_get();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the frame buffer to be reused again.
|
|
||||||
*
|
|
||||||
* @param fb Pointer to the frame buffer
|
|
||||||
*/
|
|
||||||
void esp_camera_fb_return(camera_fb_t * fb);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get a pointer to the image sensor control structure
|
|
||||||
*
|
|
||||||
* @return pointer to the sensor
|
|
||||||
*/
|
|
||||||
sensor_t * esp_camera_sensor_get();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Save camera settings to non-volatile-storage (NVS)
|
|
||||||
*
|
|
||||||
* @param key A unique nvs key name for the camera settings
|
|
||||||
*/
|
|
||||||
esp_err_t esp_camera_save_to_nvs(const char *key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Load camera settings from non-volatile-storage (NVS)
|
|
||||||
*
|
|
||||||
* @param key A unique nvs key name for the camera settings
|
|
||||||
*/
|
|
||||||
esp_err_t esp_camera_load_from_nvs(const char *key);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "img_converters.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -428,6 +428,7 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
|
|||||||
int aktdigit_before, olddigit_before;
|
int aktdigit_before, olddigit_before;
|
||||||
int pot, pot_max;
|
int pot, pot_max;
|
||||||
float zw;
|
float zw;
|
||||||
|
bool no_nulldurchgang = false;
|
||||||
|
|
||||||
pot = _decilamshift;
|
pot = _decilamshift;
|
||||||
if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
|
if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
|
||||||
@@ -448,12 +449,22 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
|
|||||||
zw = PreValue / pow(10, pot);
|
zw = PreValue / pow(10, pot);
|
||||||
olddigit = ((int) zw) % 10;
|
olddigit = ((int) zw) % 10;
|
||||||
|
|
||||||
if (aktdigit != olddigit) {
|
no_nulldurchgang = (olddigit_before <= aktdigit_before);
|
||||||
if (olddigit_before <= aktdigit_before) // stelle vorher hat noch keinen Nulldurchgang --> nachfolgestelle sollte sich nicht verändern
|
|
||||||
|
if (no_nulldurchgang)
|
||||||
|
{
|
||||||
|
if (aktdigit != olddigit)
|
||||||
{
|
{
|
||||||
input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // Neue Digit wird durch alte Digit ersetzt;
|
input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // Neue Digit wird durch alte Digit ersetzt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (aktdigit == olddigit) // trotz Nulldurchgang wurde Stelle nicht hochgezählt --> addiere 1
|
||||||
|
{
|
||||||
|
input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pot++;
|
pot++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,254 +0,0 @@
|
|||||||
#include "CTfLiteClass.h"
|
|
||||||
|
|
||||||
#include "bitmap_image.hpp"
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
float CTfLiteClass::GetOutputValue(int nr)
|
|
||||||
{
|
|
||||||
TfLiteTensor* output2 = this->interpreter->output(0);
|
|
||||||
|
|
||||||
int numeroutput = output2->dims->data[1];
|
|
||||||
if ((nr+1) > numeroutput)
|
|
||||||
return -1000;
|
|
||||||
|
|
||||||
return output2->data.f[nr];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
// return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CTfLiteClass::GetOutClassification()
|
|
||||||
{
|
|
||||||
TfLiteTensor* output2 = interpreter->output(0);
|
|
||||||
|
|
||||||
float zw_max = 0;
|
|
||||||
float zw;
|
|
||||||
int zw_class = -1;
|
|
||||||
|
|
||||||
if (output2 == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
int numeroutput = output2->dims->data[1];
|
|
||||||
for (int i = 0; i < numeroutput; ++i)
|
|
||||||
{
|
|
||||||
zw = output2->data.f[i];
|
|
||||||
if (zw > zw_max)
|
|
||||||
{
|
|
||||||
zw_max = zw;
|
|
||||||
zw_class = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// printf("Result Ziffer: %d\n", zw_class);
|
|
||||||
return zw_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTfLiteClass::GetInputDimension(bool silent = false)
|
|
||||||
{
|
|
||||||
TfLiteTensor* input2 = this->interpreter->input(0);
|
|
||||||
|
|
||||||
int numdim = input2->dims->size;
|
|
||||||
if (!silent) printf("NumDimension: %d\n", numdim);
|
|
||||||
|
|
||||||
int sizeofdim;
|
|
||||||
for (int j = 0; j < numdim; ++j)
|
|
||||||
{
|
|
||||||
sizeofdim = input2->dims->data[j];
|
|
||||||
if (!silent) printf("SizeOfDimension %d: %d\n", j, sizeofdim);
|
|
||||||
if (j == 1) im_height = sizeofdim;
|
|
||||||
if (j == 2) im_width = sizeofdim;
|
|
||||||
if (j == 3) im_channel = sizeofdim;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CTfLiteClass::GetOutPut()
|
|
||||||
{
|
|
||||||
TfLiteTensor* output2 = this->interpreter->output(0);
|
|
||||||
|
|
||||||
int numdim = output2->dims->size;
|
|
||||||
printf("NumDimension: %d\n", numdim);
|
|
||||||
|
|
||||||
int sizeofdim;
|
|
||||||
for (int j = 0; j < numdim; ++j)
|
|
||||||
{
|
|
||||||
sizeofdim = output2->dims->data[j];
|
|
||||||
printf("SizeOfDimension %d: %d\n", j, sizeofdim);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float fo;
|
|
||||||
|
|
||||||
// Process the inference results.
|
|
||||||
int numeroutput = output2->dims->data[1];
|
|
||||||
for (int i = 0; i < numeroutput; ++i)
|
|
||||||
{
|
|
||||||
fo = output2->data.f[i];
|
|
||||||
printf("Result %d: %f\n", i, fo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTfLiteClass::Invoke()
|
|
||||||
{
|
|
||||||
interpreter->Invoke();
|
|
||||||
// printf("Invoke Done.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CTfLiteClass::LoadInputImage(std::string _fn)
|
|
||||||
{
|
|
||||||
bitmap_image image(_fn);
|
|
||||||
unsigned int w = image.width();
|
|
||||||
unsigned int h = image.height();
|
|
||||||
unsigned char red, green, blue;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CTfLiteClass::MakeAllocate()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
this->micro_op_resolver.AddBuiltin(
|
|
||||||
tflite::BuiltinOperator_RESHAPE,
|
|
||||||
tflite::ops::micro::Register_RESHAPE());
|
|
||||||
this->micro_op_resolver.AddBuiltin(tflite::BuiltinOperator_CONV_2D,
|
|
||||||
tflite::ops::micro::Register_CONV_2D());
|
|
||||||
this->micro_op_resolver.AddBuiltin(tflite::BuiltinOperator_FULLY_CONNECTED,
|
|
||||||
tflite::ops::micro::Register_FULLY_CONNECTED());
|
|
||||||
this->micro_op_resolver.AddBuiltin(tflite::BuiltinOperator_SOFTMAX,
|
|
||||||
tflite::ops::micro::Register_SOFTMAX());
|
|
||||||
this->micro_op_resolver.AddBuiltin(tflite::BuiltinOperator_DEPTHWISE_CONV_2D,
|
|
||||||
tflite::ops::micro::Register_DEPTHWISE_CONV_2D());
|
|
||||||
|
|
||||||
|
|
||||||
this->interpreter = new tflite::MicroInterpreter(this->model, this->micro_op_resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
static tflite::ops::micro::AllOpsResolver resolver;
|
|
||||||
this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter);
|
|
||||||
|
|
||||||
TfLiteStatus allocate_status = this->interpreter->AllocateTensors();
|
|
||||||
if (allocate_status != kTfLiteOk) {
|
|
||||||
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
|
|
||||||
this->GetInputDimension();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Allocate Done.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
struct stat stat_buf;
|
|
||||||
long rc = stat(filename.c_str(), &stat_buf);
|
|
||||||
return rc == 0 ? stat_buf.st_size : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
|
|
||||||
{
|
|
||||||
long size;
|
|
||||||
|
|
||||||
size = this->GetFileSize(_fn);
|
|
||||||
|
|
||||||
if (size == -1)
|
|
||||||
{
|
|
||||||
printf("\nFile existiert nicht.\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char *result = (unsigned char*) malloc(size);
|
|
||||||
|
|
||||||
if(result != NULL) {
|
|
||||||
// printf("\nSpeicher ist reserviert\n");
|
|
||||||
FILE* f = fopen(_fn.c_str(), "rb"); // vorher nur "r"
|
|
||||||
fread(result, 1, size, f);
|
|
||||||
fclose(f);
|
|
||||||
}else {
|
|
||||||
printf("\nKein freier Speicher vorhanden.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTfLiteClass::LoadModel(std::string _fn){
|
|
||||||
|
|
||||||
|
|
||||||
this->error_reporter = new tflite::MicroErrorReporter;
|
|
||||||
|
|
||||||
unsigned char *rd;
|
|
||||||
rd = this->ReadFileToCharArray(_fn.c_str());
|
|
||||||
// printf("loadedfile: %d", (int) rd);
|
|
||||||
|
|
||||||
this->model = tflite::GetModel(rd);
|
|
||||||
free(rd);
|
|
||||||
TFLITE_MINIMAL_CHECK(model != nullptr);
|
|
||||||
printf("tfile Loaded.\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CTfLiteClass::CTfLiteClass()
|
|
||||||
{
|
|
||||||
// this->accessSD = _accessSD;
|
|
||||||
this->model = nullptr;
|
|
||||||
this->interpreter = nullptr;
|
|
||||||
this->input = nullptr;
|
|
||||||
this->output = nullptr;
|
|
||||||
this->kTensorArenaSize = 600 * 1024;
|
|
||||||
this->tensor_arena = new uint8_t[kTensorArenaSize];
|
|
||||||
|
|
||||||
// micro_op_resolver.AddBuiltin(tflite::BuiltinOperator_CONV_2D,
|
|
||||||
// tflite::ops::micro::Register_CONV_2D());
|
|
||||||
}
|
|
||||||
|
|
||||||
CTfLiteClass::~CTfLiteClass()
|
|
||||||
{
|
|
||||||
delete this->tensor_arena;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef __CFINDTEMPLATE
|
|
||||||
#define __CFINGTEMPLATE
|
|
||||||
|
|
||||||
#define TFLITE_MINIMAL_CHECK(x) \
|
|
||||||
if (!(x)) { \
|
|
||||||
fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); \
|
|
||||||
exit(1); \
|
|
||||||
}
|
|
||||||
|
|
||||||
//#include "CAccessSD.h"
|
|
||||||
#include "CFindTemplate.h"
|
|
||||||
|
|
||||||
#include "tensorflow/lite/micro/kernels/all_ops_resolver.h"
|
|
||||||
#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/micro/kernels/micro_ops.h"
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
//extern CAccessSDClass accessSD;
|
|
||||||
|
|
||||||
class CTfLiteClass
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
// CAccessSDClass *accessSD;
|
|
||||||
|
|
||||||
tflite::ErrorReporter* error_reporter;
|
|
||||||
|
|
||||||
const tflite::Model* model;
|
|
||||||
tflite::MicroInterpreter* interpreter;
|
|
||||||
// TfLiteTensor* input = nullptr;
|
|
||||||
TfLiteTensor* output = nullptr;
|
|
||||||
static tflite::ops::micro::AllOpsResolver *resolver;
|
|
||||||
|
|
||||||
tflite::MicroOpResolver<5> micro_op_resolver;
|
|
||||||
|
|
||||||
|
|
||||||
int kTensorArenaSize;
|
|
||||||
uint8_t *tensor_arena;
|
|
||||||
|
|
||||||
float* input;
|
|
||||||
int input_i;
|
|
||||||
|
|
||||||
int im_height, im_width, im_channel;
|
|
||||||
|
|
||||||
long GetFileSize(std::string filename);
|
|
||||||
unsigned char* ReadFileToCharArray(std::string _fn);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// CTfLiteClass(CAccessSDClass *_accessSD);
|
|
||||||
CTfLiteClass();
|
|
||||||
~CTfLiteClass();
|
|
||||||
void LoadModel(std::string _fn);
|
|
||||||
void MakeAllocate();
|
|
||||||
void GetInputTensorSize();
|
|
||||||
bool LoadInputImage(std::string _fn);
|
|
||||||
void Invoke();
|
|
||||||
void GetOutPut();
|
|
||||||
int GetOutClassification();
|
|
||||||
int GetClassFromImage(std::string _fn);
|
|
||||||
|
|
||||||
float GetOutputValue(int nr);
|
|
||||||
void GetInputDimension(bool silent);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# Name, Type, SubType, Offset, Size, Flags
|
|
||||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
|
||||||
nvs, data, nvs, , 0x4000,
|
|
||||||
otadata, data, ota, , 0x2000,
|
|
||||||
phy_init, data, phy, , 0x1000,
|
|
||||||
factory, app, factory, , 1900k,
|
|
||||||
ota_0, app, ota_0, , 1900k,
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="288910e";
|
const char* GIT_REV="eb47d51";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling";
|
const char* GIT_BRANCH="rolling";
|
||||||
const char* BUILD_TIME="2020-11-21 19:02";
|
const char* BUILD_TIME="2020-11-26 20:55";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="288910e";
|
const char* GIT_REV="eb47d51";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling";
|
const char* GIT_BRANCH="rolling";
|
||||||
const char* BUILD_TIME="2020-11-21 19:02";
|
const char* BUILD_TIME="2020-11-26 20:54";
|
||||||
Binary file not shown.
Binary file not shown.
BIN
sd-card/.DS_Store
vendored
BIN
sd-card/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user