Question/Issue:
Hi all, I want to ask about image classification using a Wio Terminal. I have trained a model to classify objects, compiled the project, and exported it to run on Arduino. My images are in grayscale 160x120, a total of 19200 pixels. One of the scripts generated when I compile the project is the static_buffer. In the feature array, I paste the pixel values of a 160x120 image (19200). Still, when I download it to my Wio terminal, it automatically gives me this error: Failed to allocate TFLite arena (error code 1). I know this error is because it can’t allocate the array I’m passing in the arena. However, when I access the folder tflite-model/trained_model_compiled.cpp I see the following:
constexpr int kTensorArenaSize = 769920;
const TfArray<4, int> tensor_dimension0 = { 4, { 1,120,160,1 } };
In this case, the arena to hold the tensor is large enough, but the shape of the tensor_dimension0 is different from my feature vector. If these errors are corrected correctly, the feature vector must have the shape of the tensor_dimension0?.
Thanks
This is my Code:
/* Includes ---------------------------------------------------------------- */
#include <Obj_inferencing.h>
int i = 0;
float features[19200] = {0.533, 0.487, 0.141, 0.197, 0.438, 0.991, 0.332, 0.828, 0.954, 0.496, 0.04, 0.674, 0.363, 0.428, 0.256, 0.001, 0.094, 0.116, 0.432, 0.277, 0.177, 0.462, 0.023, 0.411, 0.994, 0.186, 0.97, 0.383, 0.402, 0.109, 0.854, 0.627, 0.84, 0.468, 0.574, 0.819, 0.096, 0.637, 0.38, 0.327, 0.22, 0.25, 0.795, 0.359, 0.495, 0.843, 0.138, 0.124, 0.43, 0.556, 0.872, 0.328, 0.789, 0.438, 0.44, 0.515, 0.909, 0.629, 0.772, 0.748, ..., 0.138, 0.124, 0.43, 0.556};
float tensor [120][160];
int ei_camera_cutout_get_data(size_t offset, size_t length, float *out_ptr) {
size_t pixel_ix = offset * 2;
size_t bytes_left = length;
size_t out_ptr_ix = 0;
float features[19200];
int contaPixel = 0;
for (int i = 0; i < 120; i++) {
for (int j = 0; j < 160; j++) {
tensor[i][j] = features[contaPixel];
//features[contaPixel];
out_ptr[out_ptr_ix] = features[contaPixel];
contaPixel = contaPixel + 1;
out_ptr_ix++;
}
}
// and done!
return 0;
}
/**
@brief Arduino setup function
*/
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
ei_printf("Inferencing settings:\n");
ei_printf("\tImage resolution: %dx%d\n", EI_CLASSIFIER_INPUT_WIDTH, EI_CLASSIFIER_INPUT_HEIGHT);
ei_printf("\tFrame size: %d\n", EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE);
ei_printf("\tNo. of classes: %d\n", sizeof(ei_classifier_inferencing_categories) / sizeof(ei_classifier_inferencing_categories[0]));
delay(2000);
}
/**
@brief Arduino main function
*/
void loop()
{
ei_printf("Edge Impulse standalone inferencing (Arduino)\n");
ei_impulse_result_t result = { 0 };
ei::signal_t signal;
signal.total_length = EI_CLASSIFIER_INPUT_WIDTH * EI_CLASSIFIER_INPUT_HEIGHT;
signal.get_data = &ei_camera_cutout_get_data;
EI_IMPULSE_ERROR ei_error = run_classifier(&signal, &result, false);
if (ei_error != EI_IMPULSE_OK) {
ei_printf("Failed to run impulse (%d)\n", ei_error);
}
delay(5000);
}