要使用python Interpreter在图像上测试我的YOLO tflite模型,我使用opencv将图像转换为numpy数组作为模型的输入,现在输出也是一个数组。 tflite输出数组包含一些负值,据我所知无法将其转换回图像。
如何将输出数组转换为一些有意义的数据,例如边界框位置,置信度得分等。
import numpy as np
import tensorflow as tf
interpreter = tf.contrib.lite.Interpreter(model_path="tiny2-coco.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
import numpy as np
import cv2
img = cv2.imread('puppy.jpg',cv2.IMREAD_COLOR)
img = img.astype('float32')
imag = cv2.resize(img,(416,416))
y = np.expand_dims(imag, axis=0)
interpreter.set_tensor(input_details[0]['index'], y)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
我得到的输出是
[[[[-18.708311 -19.140907 -9.404704 ... -8.558794
-8.679184 -6.1807327 ]
[ -7.146568 -37.765293 7.656766 ... 32.93371
-6.5944066 -12.9268265 ]
[ 8.780166 -34.024113 11.608881 ... 18.419674
-4.50978 -18.002728 ]
...
[ -0.5073218 -61.516804 15.7385235 ... 16.619457
-12.972085 -35.770042 ]
[ 11.582869 -59.8134 10.499412 ... 10.717136
-7.9241986 -31.583939 ]
[ 29.751947 -30.872608 -7.399159 ... 16.946598
-22.264465 -32.576305 ]]
[[-31.514568 -22.54831 -22.797688 ... 16.928051
-23.231544 9.627623 ]
[ 8.211807 -31.252861 0.17072257 ... 15.147108
-17.256422 15.339517 ]
[ 13.836715 -21.551594 4.9094105 ... -12.295872
-16.939335 -0.27065754]
...
[-12.46416 -23.16856 3.9521372 ... 2.152897
-19.273735 -12.365814 ]
[ 17.254292 -23.621433 -1.9767655 ... 4.2235527
-33.236694 -1.7379608 ]
[ 37.07825 -17.03125 -14.468444 ... -22.137184
-36.210835 14.084095 ]]
[[-14.829106 -17.782665 -17.90064 ... 11.731684
-26.496943 12.288475 ]
[ 5.655488 -24.84076 -0.88530886 ... 12.143456
-7.1536856 20.183329 ]
[ -0.69370216 -22.514439 4.545768 ... -12.53299
-1.3771544 -16.546385 ]
...
[ -8.763594 -10.624026 0.35217753 ... 1.0329571
-25.207586 -26.1149 ]
[ 15.280627 -12.536571 -0.7920344 ... 0.99967
-50.91318 -13.986186 ]
[ 23.503666 -16.119858 -7.671796 ... -14.216487
-37.40868 9.055368 ]]
...
[[ 0.36325702 -0.43133396 -8.367475 ... 22.630064
-1.2070451 -12.344746 ]
[ 4.354168 -1.1188095 5.4560947 ... 21.334703
19.12783 -14.452235 ]
[ -4.1446376 -2.3607342 6.829689 ... -1.5461197
34.462128 -12.5735445 ]
...
[ -5.5922422 7.6366577 3.2678854 ... 21.423256
18.479763 -45.36464 ]
[ 1.0862936 -3.7676053 1.0449435 ... 16.79606
-0.57969856 -22.865871 ]
[ 20.236639 -3.359812 -6.019146 ... 7.93563
-1.7014084 1.6122441 ]]
[[ -1.5342582 -0.61697936 -5.683201 ... 19.183613
1.7769499 -16.447048 ]
[ -7.015096 -5.3712997 10.198931 ... 11.756607
29.678719 -8.627062 ]
[-10.380391 -8.144315 12.323125 ... -14.795822
44.091267 3.079174 ]
...
[-15.24005 15.201032 5.95317 ... 7.567139
35.36886 -33.20351 ]
[ -2.2153966 10.429498 3.887171 ... -2.0311356
8.00519 -8.532336 ]
[ 23.694601 -1.5635908 1.3407854 ... 8.957392
16.448212 5.9922814 ]]
[[ -1.5094694 11.815613 3.8775017 ... 12.449184
-6.1369114 -14.079491 ]
[ -1.7617725 16.59518 15.433371 ... 10.685811
6.7460938 -0.89323044]
[ -1.6778792 13.752986 17.948227 ... -3.5498176
11.10699 13.446217 ]
...
[-12.956201 9.840577 18.334051 ... 3.1748471
5.6134043 1.6439075 ]
[-10.641678 18.121891 13.631485 ... 0.06601667
-19.43385 6.193119 ]
[ 9.784319 2.754364 11.644993 ... -10.280966
-11.553482 25.476086 ]]]]