为图像删除 "classify" 中的 argsort 函数?

Remove argsort function in "classify" for images?

我正在尝试删除 argsort 函数,以便它只会按预测顺序打印 类(即,如果我正在尝试预测 "a-d" 分类,它将始终只打印在 "a-d" 而不是从最高分到最低分)。有什么建议吗?

本文来自:https://github.com/llSourcell/tensorflow_image_classifier/blob/master/src/label_image.py

''' 与 tf.Session() 作为 sess: # 将 image_data 作为图形的输入并获得第一个预测,即最有可能的结果 softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')

predictions = sess.run(softmax_tensor, \
         {'DecodeJpeg/contents:0': image_data})

# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]

for node_id in top_k:
    human_string = label_lines[node_id]
    score = predictions[0][node_id]
    print('%s (score = %.5f)' % (human_string, score))'''

是否要遍历相同的 top_k 个值,但要按它们的原始顺序,而不是按 predictions 排序?然后做 for node_id in sort(top_k):.