tf_image_classification.py
# Эта работа лицензирована по лицензии MIT.
# Copyright (c) 2013-2024 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Пример обнаружения людей TensorFlow Lite
#
# Этот пример работает на OpenMV RT1062 для обнаружения людей
# с помощью встроенной модели MobileNet.
import csi
import time
import ml
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
model = ml.Model("/rom/person_detect.tflite")
print(model)
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
# Это объединяет метки и значения достоверности в список кортежей,
# а затем сортирует этот список по значениям достоверности.
scores = sorted(
zip(model.labels, model.predict([img])[0].flatten().tolist()),
key=lambda x: x[1],
reverse=True
)
print(clock.fps(), "fps\t", "%s = %f\t" % (scores[0][0], scores[0][1]))