I've been trying to do the machine learning project through arduino with the tensorflow built in, but the library isnt working. The most I've found is that you need to manually install it, but when I do that it says that it cant be installed on my computer and into the IDE, so I'm at a loss. Does anyone have any suggestions on how to do this? I'm on the last part of the training section and its just refusing to work
Hi @thekingoz13
Please provide a detailed description of the procedure you used when you attempted to install the library.
Please provide the full and exact text of any error or warning messages you encounter when you try to do that. Do not paraphrase the message.
Please mention your operating system and the specific error message that you're seeing.
This outstanding tutorial, which implements a complete neural network for image recognition (with backpropagation training code and data) on an Arduino Uno, would probably be a much better learning experience.
I used this libray and it downloaded and installed. The pathing is all incorrect for the code thats provided, and when I changed it its still not working. I downloaded the zip for the library, and then in the IDE did: Sketch>Include Library> Add Zip File> then chose the zip. It said it installed and I can see the library in my libraries for my arduino folder on my computer, but it doesn't show up on my installed libraries on the IDE. When I run the code, it passes the library include part, but then gets stuck on the subsection corresponding to parts of the library. the code is below:
#include <TensorFlowLite.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/schema/schema_generated.h>
#include <tensorflow/lite/version.h>
#include "model.h"
error:
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:22:10: fatal error: tensorflow/lite/micro/micro_error_reporter.h: No such file or directory
#include <tensorflow/lite/micro/micro_error_reporter.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: tensorflow/lite/micro/micro_error_reporter.h: No such file or directory
any thoughts?
I would do that, but the project that I'm working on is for gesture detection and recognition. So I wanted to go through this training and then reowork the code to fit what I need to do for the project. I also only have access currently to an arduino Nano 33 BLE sense rev2, and I don't know if my lab would be keen on buying a new sensor to try out this other training that doesn't really correspond to what I'm working on.
On my own time I think I'll get the sensor and play around with that tutorial, so thank you for bringing it up!
Using a Macbook pro MacOS 13.2.1
this is the error message:
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:22:10: fatal error: tensorflow/lite/micro/micro_error_reporter.h: No such file or directory
#include <tensorflow/lite/micro/micro_error_reporter.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: tensorflow/lite/micro/micro_error_reporter.h: No such file or directory
I've tried reorganizing the pathing of the file on my computer to fit what it says on the code, but its not working either. I've even tried the adafruit_tensorflow library, and that one didnt work.
Okay the problem was closing the IDE every time I edited a file placement in my computer. Now that I have that all working, the libraries all go through but the code stalls right at the beginning. I also deleted the #install version.h part because this file does not have that and it was getting stuck on it, so i wanted to run it without and it passes. the following is the code for the tensorflow reading:
#include <Arduino_BMI270_BMM150.h>
/*
IMU Classifier
This example uses the on-board IMU to start reading acceleration and gyroscope
data from on-board IMU, once enough samples are read, it then uses a
TensorFlow Lite (Micro) model to try to classify the movement as a known gesture.
Note: The direct use of C/C++ pointers, namespaces, and dynamic memory is generally
discouraged in Arduino examples, and in the future the TensorFlowLite library
might change to make the sketch simpler.
The circuit:
- Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board.
Created by Don Coleman, Sandeep Mistry
Modified by Dominic Pajak, Sandeep Mistry
This example code is in the public domain.
*/
#include <TensorFlowLite.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/schema/schema_generated.h>
#include "model.h"
const float accelerationThreshold = 2.5; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
// global variables used for TensorFlow Lite (Micro)
tflite::MicroErrorReporter tflErrorReporter;
// pull in all the TFLM ops, you can remove this line and
// only pull in the TFLM ops you need, if would like to reduce
// the compiled size of the sketch.
tflite::AllOpsResolver tflOpsResolver;
const tflite::Model* tflModel = nullptr;
tflite::MicroInterpreter* tflInterpreter = nullptr;
TfLiteTensor* tflInputTensor = nullptr;
TfLiteTensor* tflOutputTensor = nullptr;
// Create a static memory buffer for TFLM, the size may need to
// be adjusted based on the model you are using
constexpr int tensorArenaSize = 8 * 1024;
byte tensorArena[tensorArenaSize] __attribute__((aligned(16)));
// array to map gesture index to a name
const char* GESTURES[] = {
"punch",
"flex"
};
#define NUM_GESTURES (sizeof(GESTURES) / sizeof(GESTURES[0]))
void setup() {
Serial.begin(9600);
while (!Serial);
// initialize the IMU
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
// print out the samples rates of the IMUs
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println(" Hz");
Serial.println();
// get the TFL representation of the model byte array
tflModel = tflite::GetModel(model);
if (tflModel->version() != TFLITE_SCHEMA_VERSION) {
Serial.println("Model schema mismatch!");
while (1);
}
// Create an interpreter to run the model
tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter);
// Allocate memory for the model's input and output tensors
tflInterpreter->AllocateTensors();
// Get pointers for the model's input and output tensors
tflInputTensor = tflInterpreter->input(0);
tflOutputTensor = tflInterpreter->output(0);
}
void loop() {
float aX, aY, aZ, gX, gY, gZ;
// wait for significant motion
while (samplesRead == numSamples) {
if (IMU.accelerationAvailable()) {
// read the acceleration data
IMU.readAcceleration(aX, aY, aZ);
// sum up the absolutes
float aSum = fabs(aX) + fabs(aY) + fabs(aZ);
// check if it's above the threshold
if (aSum >= accelerationThreshold) {
// reset the sample read count
samplesRead = 0;
break;
}
}
}
// check if the all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// check if new acceleration AND gyroscope data is available
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
// read the acceleration and gyroscope data
IMU.readAcceleration(aX, aY, aZ);
IMU.readGyroscope(gX, gY, gZ);
// normalize the IMU data between 0 to 1 and store in the model's
// input tensor
tflInputTensor->data.f[samplesRead * 6 + 0] = (aX + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 1] = (aY + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 2] = (aZ + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 3] = (gX + 2000.0) / 4000.0;
tflInputTensor->data.f[samplesRead * 6 + 4] = (gY + 2000.0) / 4000.0;
tflInputTensor->data.f[samplesRead * 6 + 5] = (gZ + 2000.0) / 4000.0;
samplesRead++;
if (samplesRead == numSamples) {
// Run inferencing
TfLiteStatus invokeStatus = tflInterpreter->Invoke();
if (invokeStatus != kTfLiteOk) {
Serial.println("Invoke failed!");
while (1);
return;
}
// Loop through the output tensor values from the model
for (int i = 0; i < NUM_GESTURES; i++) {
Serial.print(GESTURES[i]);
Serial.print(": ");
Serial.println(tflOutputTensor->data.f[i], 6);
}
Serial.println();
}
}
}
}
along with the error message:
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino: In function 'void setup()':
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:86:122: error: no matching function for call to 'tflite::MicroInterpreter::MicroInterpreter(const tflite::Model*&, tflite::AllOpsResolver&, byte [8192], const int&, tflite::MicroErrorReporter*)'
tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter);
^
In file included from /Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:23:0:
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:60:3: note: candidate: tflite::MicroInterpreter::MicroInterpreter(const tflite::Model*, const tflite::MicroOpResolver&, tflite::MicroAllocator*, tflite::MicroResourceVariables*, tflite::MicroProfilerInterface*)
MicroInterpreter(const Model* model, const MicroOpResolver& op_resolver,
^~~~~~~~~~~~~~~~
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:60:3: note: no known conversion for argument 3 from 'byte [8192] {aka unsigned char [8192]}' to 'tflite::MicroAllocator*'
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:50:3: note: candidate: tflite::MicroInterpreter::MicroInterpreter(const tflite::Model*, const tflite::MicroOpResolver&, uint8_t*, size_t, tflite::MicroResourceVariables*, tflite::MicroProfilerInterface*)
MicroInterpreter(const Model* model, const MicroOpResolver& op_resolver,
^~~~~~~~~~~~~~~~
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:50:3: note: no known conversion for argument 5 from 'tflite::MicroErrorReporter*' to 'tflite::MicroResourceVariables*'
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:40:7: note: candidate: constexpr tflite::MicroInterpreter::MicroInterpreter(const tflite::MicroInterpreter&)
class MicroInterpreter {
^~~~~~~~~~~~~~~~
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/micro/micro_interpreter.h:40:7: note: candidate expects 1 argument, 5 provided
exit status 1
Compilation error: no matching function for call to 'tflite::MicroInterpreter::MicroInterpreter(const tflite::Model*&, tflite::AllOpsResolver&, byte [8192], const int&, tflite::MicroErrorReporter*)'
seeing as how all of this is premade code I have no idea what could be wrong with it, but any help in deciphering this would be amazing. Really confused here
Hi @thekingoz13. As you discovered, the Arduino TensorFlow Lite Tutorials were written for a different version of the library than the one you get from https://github.com/tensorflow/tflite-micro-arduino-examples. The Arduino developers are tracking the need to update the tutorials here:
I don't think your current approach of trying to modify the library to match the sketch code makes sense. I'll suggest two alternative solutions. You can pick whichever of the two you prefer:
Use the version of the library the tutorials were written for
- Delete the folder that contains your current installation of the incompatible version of the library at this path:
/Users/maxwelljohnson/Documents/Arduino/libraries/Arduino_TensorFlowLite
- Click the following link to download the version of the library the tutorial's sketches were written for:
https://downloads.arduino.cc/libraries/github.com/bcmi-labs/Arduino_TensorFlowLite-2.4.0-ALPHA.zip - Wait for the download to finish.
- Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus.
- Select the downloaded file.
- Click the Open button.
You should now be able to compile the tutorial sketches without any errors.
Update the tutorial sketches to work with the current version of the library
Although much more challenging than the alternative, the benefit of this approach is it will allow you to work with the modern maintained version of the TensorFlow Lite for Microcontrollers Arduino library.
You can learn how to use the modern version of the library by studying the examples that are included with the library. You'll find those under the File > Examples > Arduino_TensorFlowLite menu in Arduino IDE.
The error message you provided suggests that the file "tensorflow/lite/micro/micro_error_reporter.h" could not be found during the compilation process.
This error typically occurs when the specified file or directory is missing or not accessible to the compiler. The reason can be a missing TensorFlow Lite Micro library, an incorrect include path, or an incorrect file location. Here are some links that may help:
Thank you for your help!
I did the first version of the advice you gave, and its going through and compiling. the main issue I'm having now is as follows:
In reference to the original code, when I run it now I get this error message:
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino: In function 'void setup()':
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:80:30: error: 'TFLITE_SCHEMA_VERSION' was not declared in this scope
if (tflModel->version() != TFLITE_SCHEMA_VERSION) {
^~~~~~~~~~~~~~~~~~~~~
/Users/maxwelljohnson/Desktop/Gesture/Gesture.ino:80:30: note: suggested alternative: 'TFLITE_CHECK_LE'
if (tflModel->version() != TFLITE_SCHEMA_VERSION) {
^~~~~~~~~~~~~~~~~~~~~
TFLITE_CHECK_LE
exit status 1
Compilation error: 'TFLITE_SCHEMA_VERSION' was not declared in this scope
thats the error message I'm getting for line 78 through 83. I don't know why its not being called, but it isn't declared and I'm assuming its calling one of the library parts. I assume since its calling the full path for where the code is held I should have another thing in there to clarify what that is, but I dont know what that should be since there wasnt anything in this tutorial that went along with that. if you have any ideas that'd be great.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.