【发布时间】:2016-11-22 17:37:54
【问题描述】:
我对 TensorFlow 和 stackoverflow 都很陌生。我正在做一个项目,我应该为照片推荐 5 个最合适的标签。 Tensorflow 为您训练最后一层的每个标签都提供了一个预测值,因为它也旨在找到准确度超过 0.5 的标签,而其他标签最终的值小于 0.1。 但我如何确定是否有超过 1 个标签成为最相关的标签? 例如对于红色鸟的图像,TF (Tensorflow) 将鸟作为最佳标签,将红色作为次佳标签,尽管两者具有同等相关性。
我的问题是 如果 TF 足够相关,我怎样才能让超过 1 个标签具有相同的价值? (如果不一样,非常接近的数字会为我做。)另外,有没有办法我可以在 .txt 文件中获取这些标签的输出及其对应的值?(最后一部分这个问题之前也被问过,但仍然没有答案,所以我想我会把它作为我问题的一部分)
我的 label_image.py 的代码与教程中给出的相同 - 用于诗人的 TensorFlow。这是它的代码,
import tensorflow as tf
image_path = sys.argv[1]
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
label_lines = [line.rstrip() for line
in tf.gfile.GFile("/tf_files/retrained_labels.txt")]
with tf.gfile.FastGFile("/tf_files/retrained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
with tf.Session() as sess:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
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))
【问题讨论】:
标签: python tags tensorflow tagging photo-tagging