Reputation: 195
I'm trying to run a TF Lite model on the Arduino Nano BLE 33 board.
My data comes from two ultrasonic sensors -- Channel 1 and Channel 2. I am trying to determine where an object might be, so the sensors are measuring distance.
Every time I run my inference, my code returns the exact same answer -- that with 100% accuracy there is an object on the left side of the test area. I get this answer ever when there is no object there.
I am taking 5000 samples per channel (this is the samplesRead
figure) and was loading them in as follows:
tflInputTensor->data.f[samplesRead*2+0] = channel1;
tflInputTensor->data.f[samplesRead*2+1] = channel2;
Where channel1
and channel2
are the samples from the sensor.
As I said, every time I run my inference I got the exact same answer.
I decided to cut my code back to try and understand what was going on, so, I hard-coded some figures in, as follows:
tflInputTensor->data.f[samplesRead*2+0] = 4512.00;
tflInputTensor->data.f[samplesRead*2+1] = 4428.00;
But I still got the same answer, no matter what figures I put in here. This makes me think I am loading the data in incorrectly, so, I wanted to print the contents of the input tensors to check what was in there. And this is what I am hoping I can get some help with.
Also, I have 2 in tflInputTensor->data.f[samplesRead*2+0]
, because I seen an example that had 6 inputs, and in this bit of code they had 6, so I just modified that.
For completeness, here is that main section of code:
const int numSamples = 5000;
int samplesRead = numSamples;
void loop()
{
float durationCh1, durationCh2;
while(samplesRead == numSamples)
{
samplesRead = 0;
break;
}
// for(i=0; i<5000; i++)
while(samplesRead < numSamples)
{
tflInputTensor->data.f[samplesRead*2+0] = 4512.00;
tflInputTensor->data.f[samplesRead*2+1] = 4428.00;
samplesRead++;
Serial.println(samplesRead);
if(samplesRead == numSamples)
{
TfLiteStatus invokeStatus = tflInterpreter->Invoke();
Serial.println("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_LOC; i++)
{
Serial.print(GRIDS[i]);
Serial.print(": ");
Serial.println(tflOutputTensor->data.f[i],9); // The int here gives the decimal places
}
Serial.println();
delay(2000);
}
}
}
Upvotes: 0
Views: 187
Reputation: 195
I was obviously a sleep deprived idiot when I posted this question, because the answer was in my code!!
I modified Serial.println(tflOutputTensor->data.f[i],9);
to be:
Serial.println(tflInputTensor->data.f[samplesRead]);
Upvotes: 0