Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

python - Getting objectiveness and class score beyond the range [0, 1] while executing Yolov3 TFlite model

I trained a YOLOv3 model for counter detection, and it output two files of the following formats: '.weights' and '.cfg.' I used these files for detection on some test images, and it was working appropriately.

Since I wanted to use this model in an app, I converted these files into .tflite format using this trail: (.weights & .cfg) -> (.pb file) -> (freeze the graph) -> (.tflite file). I verified its (.tflite file's) input and output format.

But, when I ran the below-mentioned code in the Colab, I noticed that the objectiveness score and the class score exceeded beyond the [0, 1] range, which is impractical.

## Code

import tensorflow as tf
import cv2
import numpy as np

interpreter=tf.lite.Interpreter(model_path='tflite_files/tflite3_yolov3.tflite')
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

image_path='Image1.jpg'
img=cv2.imread(image_path)
img=cv2.resize(img,(608,608))

input_shape = input_details[0]['shape']
input_tensor = np.array(np.expand_dims(img,0), dtype=np.float32)
input_tensor=input_tensor/255

input_index = interpreter.get_input_details()[0]["index"]
interpreter.set_tensor(input_index,input_tensor)

interpreter.invoke()

predictions = [interpreter.get_tensor(output_details[i]['index']) for i in range(len(output_details))]
print(predictions[0][0][0][0])

'''

## Output

[ 2.0600404e-01 -1.1882504e-02  1.0720440e+00 -5.5199629e-01
 -1.3288206e+01  9.2173815e-01  4.8205411e-01  2.3956555e-01
  2.2842890e-01 -8.5250042e-02 -1.3612757e+01  1.4530812e-01
  6.0065955e-01  3.5657447e-02  2.6185828e-01 -6.3486624e-01
 -1.2317422e+01  1.7624218e+00]

Can anyone please help me find out the reason behind it or maybe a solution to correct this?

Thanks for your help in advance.

question from:https://stackoverflow.com/questions/65924527/getting-objectiveness-and-class-score-beyond-the-range-0-1-while-executing-yo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...