How can i repeat the data infinitly?

Because of the memory capacity, i can only put the input data 500row.

But my tflite model(ver1_1.h) input shape is (4500,12), so i have to make the data repeat infinitly.

This is my code. Please somebody help me... :frowning:

#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 "ver1_1.h"

tflite::MicroErrorReporter tflErrorReporter;
tflite::AllOpsResolver tflOpsResolver;
const tflite::Model* tflModel = nullptr;
tflite::MicroInterpreter* tflInterpreter = nullptr;
TfLiteTensor* tflInputTensor = nullptr;
TfLiteTensor* tflOutputTensor = nullptr;
const uint32_t tensorArenaSize = 60 * 1024;
uint8_t tensorArena[tensorArenaSize];
tflite::MicroErrorReporter micro_error_reporter;
tflite::AllOpsResolver resolver;
const int inputSize = 4500 * 12 * sizeof(float);
const int outputSize = sizeof(float);

int led = LED_BUILTIN;

float data[500][12] = { { ... }, { ... }, ... , { ... } };

void setup() {
  Serial.begin(9600);
  digitalWrite(led, HIGH);

  tflInterpreter = new tflite::MicroInterpreter(tflModel, resolver, tensorArena, tensorArenaSize, &micro_error_reporter);
  tflInterpreter->AllocateTensors();

  float* inputData = tflInterpreter->input(0)->data.f;
  float* outputData = tflInterpreter->output(0)->data.f;

  for (int i=0; i<4500; i++) {
    for (int j=0; j<12; j++) {
      *inputData++ = data[i][j];
    }
  }

  tflInterpreter->Invoke();

  Serial.println(*outputData);
  
  pinMode(led, OUTPUT);
  if (*outputData>=0.5) {
    digitalWrite(led, HIGH);
  } else {
    for (int fadeValue=0; fadeValue<=255; fadeValue+=5) {
      analogWrite(led, fadeValue);    
      }
  }
};

void loop() {
}

Use a controller with more memory.
Try const and PROGMEM.

1 Like

What is your arduino board?

my board is arduino nano 33 ble.

The data is too big - (4500 * 12 * 4) = 216 kbytes. And in your code you try to allocate it at least twice. - first as array data and second as input of tflInterpreter. Why didn't save the first array in PROGMEM or on external storage?

And after moving data to PROGMEM you're aiming for too much. I'm afraid that none of the arduino boards will be suitable for your task.... try with something like a Raspberry Pi

maybe 1 teensy 4.0 with 1MB of RAM will work.
But if you plan do to additionally things this might be too less again.

What is the final purpose of your project?
Depending on the final purpose maybe a different solution can be found.
So please post a description of your project.

best regards Stefan

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.