Adafruit Circuit Playground Bluefruit编译TensorFlow Lite示例文件缺失求助
问题概述
在Adafruit Circuit Playground Bluefruit上编译官方TensorFlow Lite示例(hello_world_arcada、micro_speech_arcada)时遇到以下问题:
- 安装Adafruit_Tensorflow_Lite库后编译提示大量文件缺失,手动补充TensorFlow仓库文件后,仍报错缺少
am_bsp.h、am_mcu_apollo.h、am_util.h - 尝试添加SparkFun Edge BSP中的am_bsp.h,依旧无法编译
- 编译报错截图:

- 使用的代码如下:
#include <TensorFlowLite.h> #include "Adafruit_TFLite.h" #include "Adafruit_Arcada.h" #include "output_handler.h" #include "sine_model_data.h" // Create an area of memory to use for input, output, and intermediate arrays. // Finding the minimum value for your model may require some trial and error. const int kTensorAreaSize (2 * 1024); // This constant represents the range of x values our model was trained on, // which is from 0 to (2 * Pi). We approximate Pi to avoid requiring additional // libraries. const float kXrange = 2.f * 3.14159265359f; // Will need tuning for your chipset const int kInferencesPerCycle = 200; int inference_count = 0; Adafruit_Arcada arcada; Adafruit_TFLite ada_tflite(kTensorAreaSize); // The name of this function is important for Arduino compatibility. void setup() { Serial.begin(115200); //while (!Serial) yield(); arcada.arcadaBegin(); // If we are using TinyUSB we will have the filesystem show up! arcada.filesysBeginMSD(); arcada.filesysListFiles(); // Set the display to be on! arcada.displayBegin(); arcada.setBacklight(255); arcada.display->fillScreen(ARCADA_BLUE); if (! ada_tflite.begin()) { arcada.haltBox("Failed to initialize TFLite"); while (1) yield(); } if (arcada.exists("model.tflite")) { arcada.infoBox("Loading model.tflite from disk!"); if (! ada_tflite.loadModel(arcada.open("model.tflite"))) { arcada.haltBox("Failed to load model file"); } } else if (! ada_tflite.loadModel(g_sine_model_data)) { arcada.haltBox("Failed to load default model"); } Serial.println("\nOK"); // Keep track of how many inferences we have performed. inference_count = 0; } // The name of this function is important for Arduino compatibility. void loop() { // Calculate an x value to feed into the model. We compare the current // inference_count to the number of inferences per cycle to determine // our position within the range of possible x values the model was // trained on, and use this to calculate a value. float position = static_cast<float>(inference_count) / static_cast<float>(kInferencesPerCycle); float x_val = position * kXrange; // Place our calculated x value in the model's input tensor ada_tflite.input->data.f[0] = x_val; // Run inference, and report any error TfLiteStatus invoke_status = ada_tflite.interpreter->Invoke(); if (invoke_status != kTfLiteOk) { ada_tflite.error_reporter->Report("Invoke failed on x_val: %f\n", static_cast<double>(x_val)); return; } // Read the predicted y value from the model's output tensor float y_val = ada_tflite.output->data.f[0]; // Output the results. A custom HandleOutput function can be implemented // for each supported hardware target. HandleOutput(ada_tflite.error_reporter, x_val, y_val); // Increment the inference_counter, and reset it if we have reached // the total number per cycle inference_count += 1; if (inference_count >= kInferencesPerCycle) inference_count = 0; }
解决方案
这些am_xxx.h是Ambiq Apollo系列芯片(如SparkFun Edge使用的Apollo3)的BSP文件,Circuit Playground Bluefruit用的是nRF52840,完全不需要这些文件,问题出在库配置或示例使用错误:
重置库文件
- 卸载现有Adafruit_Tensorflow_Lite库,通过Arduino Library Manager重新安装最新版的Adafruit TensorFlow Lite Library,不要手动修改库文件。
- 确保同时安装依赖库:Adafruit Arcada Library、Adafruit nRF52 Arduino Core(通过Board Manager安装)。
确认开发板选择
在Arduino IDE中,确保正确选择Tools > Board > Adafruit nRF52 Boards > Adafruit Circuit Playground Bluefruit,并选择对应的串口端口。使用官方示例文件
不要自行复制代码,直接从Arduino IDE的File > Examples > Adafruit TensorFlow Lite Library中打开hello_world_arcada或micro_speech_arcada,这些示例已经包含所有依赖文件(如output_handler.h、sine_model_data.h),避免文件遗漏。清理编译缓存
执行编译前,先清理编译缓存:开启File > Preferences > Show verbose output during: compilation,然后删除Arduino缓存目录(Windows路径通常为%USERPROFILE%\AppData\Local\Arduino15\cache,Linux/macOS路径为~/.arduino15/cache)。
内容的提问来源于stack exchange,提问作者thareaper5

