如何解释TFLite输出张量

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

我正在python上执行TFLite模型,以便根据输入数据进行预测。该模型已经在AutoML-Google-API上进行了训练,然后我下载了其TFLite模型。我使用tf.lite.Interpreter加载模型并按如下所示进行推断

input_details = interpreter.get_input_details();print(input_details )
output_details = interpreter.get_output_details();print(output_details )
//...preparing input_data
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index']);print(output_data )

结果如下:

input_details: 
[{'name': 'image',
  'index': 0,
  'shape': array([  1, 224, 224,   3]),
  'dtype': numpy.uint8,
  'quantization': (0.007874015718698502, 128)}]
output_details: 
[{'name': 'scores',
  'index': 173,
  'shape': array([ 1, 10]),
  'dtype': numpy.uint8,
  'quantization': (0.00390625, 0)}]
output_data : 
array([[ 34, 100,  67,  14,  15,  24,  21,  18,  25,  37]], dtype=uint8)

output_data有一些整数,可以说“其最大数字的索引对应于预测的标签”是真的,我怎么将这些数字转换为概率?

python tensorflow google-api tensorflow-lite softmax
1个回答
0
投票

您可以使用softmax将数字转换为概率分布,并使用argmax获得具有最大概率的标签索引。

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