2017-05-03 118 views
0

Tensorflow以來我試圖從tensorflow網站上的這個圖像識別教程: https://www.tensorflow.org/tutorials/image_retraining 並將其與巴澤爾BU命令行 succefully工作是否有可能把這種以來模型編程方式使用巴澤勒或通過例如Python腳本,所以我可以用圖片給它容易無巴澤爾

+0

你能澄清你的意思了一下?本教程本身正在運行一個Python腳本來進行培訓,所以如果我瞭解您的問題,您可以根據自己的目的對其進行修改。 –

+0

要使用本教程,IHAVE使用巴澤勒命令: 巴澤勒濱/ tensorflow /示例/ label_image/label_image這不是一個Python腳本,它是一個命令行,我想使用Python腳本所以可以預測的圖像使用代碼 – Aggounix

回答

1

您可以使用tmp目錄下生成文件,寫一個python腳本加載模型,並生成預測。

而且,最好是保持文件比TMP文件夾以外的目錄文件夾中的內容可以被沖走。

import tensorflow as tf 
import sys 


image_path = sys.argv[1] 
image_data = tf.gfile.FastGFile(image_path, 'rb').read() 

#loads label file, strips off carriage return 
label_lines = [line.strip() for line in tf.gfile.GFile("/tmp/output_labels.txt")] 

# Unpersists graph from file 
with tf.gfile.FastGFile("/tmp/output_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: 
    # Feed the image data as input to the graph an get first prediction 
    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 = %.2f)' % (human_string, score)) 
+0

THX的另一部分的預測,我會嘗試這個劇本今晚,我使用Tensorflow 1.0+ – Aggounix

+0

如果有幫助,請接受 – user6083088