Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino_LSM9DS1.h>
- #include <TensorFlowLite.h>
- #include <tensorflow/lite/micro/kernels/micro_ops.h>
- #include <tensorflow/lite/micro/model.h>
- #include <tensorflow/lite/micro/error_reporter.h>
- #include <tensorflow/lite/micro/micro_interpreter.h>
- // Include the TensorFlow Lite model
- #include "gesture_model.h"
- // TensorFlow Lite setup
- tflite::MicroErrorReporter micro_error_reporter;
- tflite::MicroInterpreter* interpreter;
- TfLiteTensor* input;
- TfLiteTensor* output;
- void setup() {
- Serial.begin(115200);
- // Initialize the LSM9DS1 sensor
- if (!IMU.begin()) {
- Serial.println("Failed to initialize IMU!");
- while (1);
- }
- // Load the model
- static tflite::MicroOpResolver<6> micro_op_resolver;
- micro_op_resolver.AddFullyConnected();
- micro_op_resolver.AddSoftmax();
- static tflite::MicroInterpreter static_interpreter(
- gesture_model, micro_op_resolver, tensor_arena, kTensorArenaSize, µ_error_reporter);
- interpreter = &static_interpreter;
- interpreter->AllocateTensors();
- input = interpreter->input(0);
- output = interpreter->output(0);
- }
- void loop() {
- float ax, ay, az;
- if (IMU.accelerationAvailable()) {
- IMU.readAcceleration(ax, ay, az);
- // Prepare the input data
- input->data.f[0] = ax;
- input->data.f[1] = ay;
- input->data.f[2] = az;
- // Run inference
- interpreter->Invoke();
- // Read the result
- float gesture = output->data.f[0];
- Serial.print("Gesture Probability: ");
- Serial.println(gesture);
- }
- delay(1000); // Adjust delay as needed
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement