关于运用inception-V3模型识别自己的图片时遇到的一个小问题

关于这个代码网上很多,以下是我贴的一段省略部分内容的代码:

...............

proto_as_ascii = tf.gfile.GFile(label_lookup_path).readlines()

node_id_to_uid = {}

for line in proto_as_ascii:

if line.startswith(' target_class:'):

target_class = int(line.split(': ')[1])

if line.startswith(' target_class_string:'):

target_class_string = line.split(': ')[1]

node_id_to_uid[target_class] = target_class_string[1:-2]

..................

for node_id in top_k:

human_string = node_lookup.id_to_string(node_id)

score = predictions[node_id]

print('%s (score = %.5f)' %(human_string, score))

print('\n')

输出结果:

images/cat.jpg
 (score = 0.84975)
 (score = 0.05602)
 (score = 0.02284)
 (score = 0.02027)
 (score = 0.00359)

问题:只输出了置信度,没有输出图片所属类别

原因:if line.startswith(' target_class:')和if line.startswith(' target_class_string:')这两句括号内输入的内容应该是:‘按两空格+target_class:'

注意:运用inception-V3分类自己的图片,当建立字典时,注意搜索位置、分割符的正确界定

猜你喜欢

转载自blog.csdn.net/wuliangcai_/article/details/86160177