解释对象检测API上TF lite的输出

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

我正在使用对象检测API来训练我的自定义数据以解决2类问题。我正在使用SSD Mobilenet v2。我正在将模型转换为TF lite,我试图在python解释器上执行它。分数和课程的价值对我来说有点混乱,我无法为此做出有效的理由。我得到以下分数值。

[[ 0.9998122 0.2795332 0.7827836 1.8154384 -1.1171713 0.152002 -0.90076405 1.6943774 -1.1098632 0.6275915 ]]

我为课程获得以下值:

[[ 0. 1.742706 0.5762139 -0.23641224 -2.1639721 -0.6644413 -0.60925585 0.5485272 -0.9775026 1.4633082 ]]

如何获得大于1或小于0的分数,例如-1.10986321.6943774。类也应该是整数理想12因为它是2类对象检测问题

我使用以下代码



    import numpy as np
    import tensorflow as tf
    import cv2

    # Load TFLite model and allocate tensors.
    interpreter = tf.contrib.lite.Interpreter(model_path="C://Users//Admin//Downloads//tflitenew//detect.tflite")
    interpreter.allocate_tensors()

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

    print(input_details)
    print(output_details)
    input_shape = input_details[0]['shape']
    print(input_shape)
    # change the following line to feed into your own data.
    #input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)

    input_data = cv2.imread("C:/Users/Admin/Pictures/fire2.jpg")
    #input_data = cv2.imread("C:/Users/Admin/Pictures/images4.jpg")
    #input_data = cv2.imread("C:\\Users\\Admin\\Downloads\\FlareModels\\lessimages\\video5_image_178.jpg")
    input_data = cv2.resize(input_data, (300, 300)) 

    input_data = np.expand_dims(input_data, axis=0)
    input_data = (2.0 / 255.0) * input_data - 1.0
    input_data=input_data.astype(np.float32)
    interpreter.reset_all_variables()
    interpreter.set_tensor(input_details[0]['index'], input_data)
    interpreter.invoke()
    output_data_scores = []
    output_data_scores = interpreter.get_tensor(output_details[2]['index'])
    print(output_data_scores)

    output_data_class = []
    output_data_class = interpreter.get_tensor(output_details[1]['index'])
    print(output_data_class)

android python tensorflow object-detection-api
1个回答
0
投票

看起来问题是由错误的输入图像通道顺序引起的。 Opencv imread以'BGR'格式读取图像。你可以尝试添加

input_data = cv2.cvtColor(input_data,  cv2.COLOR_BGR2RGB)

获取'RGB'格式图像,然后查看结果是否合理。

参考:ref

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.