Directly on the H7+ board, I am trying to run TFLite models on their own training images (obtained from public image datasets) that were were used to build these models on EdgeImpulse, for diagnostics and cross-checks. I use the 4.1.5 development firmware. However, with many images it fails.
For instance, when loading these attached JPEGs:
image_03.zip (133.9 KB)
…the board either disconnects and reconnects, or starts flashing the RGB LED in quick succession and logs a MemManage error:
VID_20211231_120600.zip (150.3 KB)
This is my code:
#import libraries
import image, os, tf, pyb
#set constants
GREEN_LED_PIN = 2
#import mobilenet model and labels
mobilenet = "trained.tflite"
labels = [line.rstrip('\n') for line in open("labels.txt")]
#scan jpegs on card
files=os.listdir()
jpegs=[files for files in files if "jpg" in files]
# create detection file and "out" folder
if(not 'detections.csv' in os.listdir()):
with open('detections.csv', 'a') as detectionlog:
detectionlog.write("picture" + ',' + "label1" + ',' "confidence1" + ',' + "x_top_left" + ',' + "y_top_left" + ',' + "width" + ',' + "height" + ',' + "label2" + ',' "confidence2" + '\n')
#if not "out" in os.listdir(): os.mkdir("out")
#open and classify each jpeg
for jpeg in jpegs:
print("Loading:",jpeg)
img=image.Image(jpeg,copy_to_fb=True)
img.to_rgb565()
#starting classification
pyb.LED(GREEN_LED_PIN).on()
print("LED on: classifying image", jpeg, "with tensorflow lite...")
for obj in tf.classify(mobilenet, img, min_scale=1, scale_mul=0.5, x_overlap=0.5, y_overlap=0.5):
predictions_list = list(zip(labels, obj.output()))
print(predictions_list)
with open('detections.csv', 'a') as detectionlog:
detectionlog.write(str(jpeg) + ',' + str(predictions_list[1][0]) + ',' + str(predictions_list[1][1]) + ',' + str(obj.rect()[0]) + ',' + str(obj.rect()[1]) + ',' + str(obj.rect()[2]) + ',' + str(obj.rect()[3]) + ',' + str(predictions_list[0][0]) + ',' + str(predictions_list[0][1]) + '\n')
pyb.LED(GREEN_LED_PIN).off()