Example: 03-Machine-Learning/00-TensorFlow/tf_image_classification.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2024 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# TensorFlow Lite Person Detection Example
#
# This example runs on the OpenMV RT1062 to detect people
# 使用内置的MobileNet模型。

import sensor
import time
import ml

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)

model = ml.Model("person_detect", load_to_fb=True)
print(model)

clock = time.clock()
while True:
    clock.tick()
    img = sensor.snapshot()

    # This combines the labels and confidence values into a list of tuples
    # 然后按置信度值对该列表进行排序。
    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]))

results matching ""

    No results matching ""