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

问题描述 投票:0回答:3

您好 stackoverflow 社区,

我正在尝试利用 PlatformIO 和 Arduino 框架(不是 ESP-IDF)在我的 ESP32 上运行一个利用 Tensorflow Lite Micro 的项目。基本上,我遵循了这篇中等帖子中的指南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
c++ tensorflow tensorflow-lite esp32 arduino-esp32
3个回答
1
投票

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


0
投票

我现在通过从 Arduino 框架切换到 ESP-IDF 框架解决了这个问题。有了这个,它就像一个魅力。


0
投票

我也遇到过同样的问题。该问题是由于缺少 ESP32 库依赖造成的。 您可以通过添加“#include ”作为最顶层的头文件来解决该问题。

#include <TensorFlowLite_ESP32.h>
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/system_setup.h"
#include "tensorflow/lite/schema/schema_generated.h"

另请确保您已从库部分下载TensorFlowLite ESP32

© www.soinside.com 2019 - 2024. All rights reserved.