尝试将 Tensorflow Lite Micro 集成到我的 ESP32 Arduino 项目时,在 Tensorflow Lite Micro 框架中编译错误

Compile errors in Tensorflow Lite Micro framework when trying to integrate Tensorflow Lite Micro to my ESP32 Arduino project

嗨,Whosebug 社区,

我正在尝试使用 PlatformIO 和 Arduino 框架(不是 ESP-IDF)在我的 ESP32 上 运行 获得一个利用 Tensorflow Lite Micro 的项目。基本上,我遵循了这个媒介 post https://towardsdatascience.com/tensorflow-meet-the-esp32-3ac36d7f32c7 中的指南,然后将所有内容都包含在我现有的 ESP32 项目中。

我的项目在集成 Tensorflow Lite Micro 之前编译正常,但自从集成它后,我收到以下似乎与 Tensorflow 框架本身有关的编译错误。当我取消注释与 Tensorflow 相关的所有内容时,它编译正常。但是就在只包含以下头文件时,它会中断:

#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"

有人知道这些错误是从哪里来的吗?我能做些什么来解决这些错误?

这是错误跟踪:

In file included from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:24:0,
                 from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:37,
                 from src/main.cpp:3:
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected identifier before numeric constant
 #define DEFAULT 1
                 ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
     DEFAULT = 1,
     ^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected '}' before numeric constant
 #define DEFAULT 1
                 ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
     DEFAULT = 1,
     ^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected unqualified-id before numeric constant
 #define DEFAULT 1
                 ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
     DEFAULT = 1,
     ^
In file included from lib/tfmicro/tensorflow/lite/micro/micro_interpreter.h:24:0,
                 from src/main.cpp:12:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:51:21: error: declaration of '~tflite::Profiler' as non-member
   virtual ~Profiler() {}
                     ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:61:48: error: 'EventType' has not been declared
   virtual uint32_t BeginEvent(const char* tag, EventType event_type,
                                                ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:54: error: 'virtual' outside class declaration
                               int64_t event_metadata2) = 0;
                                                      ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:58: error: function 'uint32_t tflite::BeginEvent(const char*, int, int64_t, int64_t)' is initialized like a variable
                               int64_t event_metadata2) = 0;
                                                          ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:65:40: error: 'EventType' has not been declared
   uint32_t BeginEvent(const char* tag, EventType event_type,
                                        ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:74:48: error: 'virtual' outside class declaration
                         int64_t event_metadata2) {}
                                                ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:46: error: 'virtual' outside class declaration
   virtual void EndEvent(uint32_t event_handle) = 0;
                                              ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:50: error: function 'void tflite::EndEvent(uint32_t)' is initialized like a variable
   virtual void EndEvent(uint32_t event_handle) = 0;
                                                  ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:34: error: 'EventType' has not been declared
   void AddEvent(const char* tag, EventType event_type, uint64_t start,
                                  ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: In function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)':
lib/tfmicro/tensorflow/lite/core/api/profiler.h:88:35: error: too many arguments to function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)'
              /*event_metadata2*/ 0);
                                   ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:8: note: declared here
   void AddEvent(const char* tag, EventType event_type, uint64_t start,
        ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: At global scope:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:91:42: error: 'EventType' has not been declared
   virtual void AddEvent(const char* tag, EventType event_type, uint64_t start,
                                          ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:93:48: error: 'virtual' outside class declaration
                         int64_t event_metadata2) {}
                                                ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:95:2: error: expected unqualified-id before 'protected'
  protected:
  ^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:105:25: error: expected ')' before '*' token
   ScopedProfile(Profiler* profiler, const char* tag,
                         ^
src/main.cpp:202:1: error: expected '}' at end of input
 }
 ^
src/main.cpp:202:1: error: expected unqualified-id at end of input
*** [.pio/build/esp32cam/src/main.cpp.o] Error 1

我暂时解决了这个问题,方法是从 Arduino 框架切换到 ESP-IDF 框架。有了这个,它就像一个魅力。

今天我遇到了类似的问题。我使用 TensorFlowLite_ESP32 库而不是 Arduino_TensorFlowLite 解决了这个问题。您需要下载此库并添加 #include 行。希望对你也有帮助