从 google Vertex AutoML 导出的 tflite 边缘对象检测模型预测分数较低

问题描述 投票:0回答:1

我使用 Google 的 AutoML 训练了一个对象检测模型。我将模型导出为 .tflite 文件,并通过 python 进行了一些预测,但我得到的结果比 Vertex 在相同图像上显示的结果更糟糕,分数也更低。该模型应该找到外壳仍然完好无损的坚果。这是 Vertex 上显示的预测、分数,然后是我通过 Python 从导出模型中获得的分数。

正如您在本例中所看到的,导出的模型无法预测正确的 bbox。在某些情况下,bbox 是正确的,但分数远低于 Vertex 上显示的分数。

这是我使用的代码:

import numpy as np
import tensorflow as tf
import cv2
import os
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
def draw_rect(image, box):
    y_min = int(max(1, (box[0] * image.shape[0])))
    x_min = int(max(1, (box[1] * image.shape[1])))
    y_max = int(min(image.shape[0], (box[2] * image.shape[0])))
    x_max = int(min(image.shape[1], (box[3] * image.shape[1])))

    # draw a rectangle on the image
    cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (255, 0, 0), 2)
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="langhe_gusci_interi.tflite")

# Get input and output tensors.
input_details = interpreter.get_input_details()
print(input_details)
output_details = interpreter.get_output_details()

interpreter.allocate_tensors()
dir = "shell"
for file in os.listdir(dir):
    print(file)
    img = cv2.imread(os.path.join(dir, file))
    new_img = cv2.resize(img, (512, 512))

    interpreter.set_tensor(input_details[0]['index'], [new_img])

    interpreter.invoke()
    rects = interpreter.get_tensor(output_details[0]['index'])
    scores = interpreter.get_tensor(
    output_details[2]['index'])

    # print highest score prediction
    print(rects[0][0])
    print(scores[0][0])
    draw_rect(new_img,rects[0][0])
      
    cv2.imshow("image", new_img)
    cv2.waitKey(0)
python google-cloud-platform object-detection google-cloud-vertex-ai google-cloud-automl
1个回答
0
投票

您在 AutoML Vision 模型训练中为边缘模型选择哪个选项?有不同的选择(您可以检查 here

MOBILE_TF_LOW_LATENCY_1
选项为您提供一个预测速度更快但预测准确度可能较低的边缘模型,而它的另一侧是
MOBILE_TF_HIGH_ACCURACY_1
,这可能会为您提供更好的准确度但预测速度更慢.

© www.soinside.com 2019 - 2024. All rights reserved.