tensorflow for poets: “The name 'import/input' refers to an Operation not in the graph.”

前端 未结 11 1283
长情又很酷
长情又很酷 2020-12-29 23:17

I was following the codelabs tensorflow for poets and the training worked fine but when I runned the script to evaluate a image:

python -m scripts.label_imag         


        
11条回答
  •  [愿得一人]
    2020-12-29 23:50

    Sorry for late answer. I run python script below with a retrained model. Can you try this one?

    Requirements: labels.txt and output.pb(retrained model) should be at same directory with my python scipt. Save code below as test.py And call it as: python test.py xxx.jpg

    import sys
    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("./labels.txt")]
    
    
    with tf.gfile.FastGFile("./output.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))
    

提交回复
热议问题