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

前端 未结 11 1221
长情又很酷
长情又很酷 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:46

    Use --input_layer name as Placeholder. It will work because the retrain.py script has set default value of input_layer as "Placeholder".

        python label_image.py 
              --graph=retrained_graph.pb 
              --labels=retrained_labels.txt 
              --output_layer=final_result 
              --image=testimage654165.jpg 
              --input_layer=Placeholder
    
    0 讨论(0)
  • 2020-12-29 23:46

    You have to make some changes in label_image.py in the scripts folder

    input_height = 299 Change input_height to 299 from 224
    input_width = 299 Change input_width to 299 from 224
    input_mean = 128
    input_std = 128
    input_layer = "Mul" Change input_layer to Mul from input
    output_layer = "final_result"

    Output:

    Evaluation time (1-image): 1.901s

    daisy (score=0.98584)
    sunflowers (score=0.01136)
    dandelion (score=0.00210)
    tulips (score=0.00066)
    roses (score=0.00004)

    For more info, refer this page

    0 讨论(0)
  • 2020-12-29 23:50

    Use this

    curl -LO https://github.com/tensorflow/tensorflow/raw/master/tensorflow/examples/label_image/label_image.py
    python label_image.py \
    --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \
    --input_layer=Placeholder \
    --output_layer=final_result \
    --image=$HOME/flower_photos/daisy/21652746_cc379e0eea_m.jpg
    
    0 讨论(0)
  • 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))
    
    0 讨论(0)
  • 2020-12-29 23:51

    Inside the "retrain.py" code you'll see an argument called '--final_tensor_name'. If you don't pass that argument it will keep 'final_result' or 'Mul' (depending on the version your using) as the default.

    The only way to view the input and output names without the actual training output files is to view the graph in TensorBoard of the 'frozen_graph.pb' or in your case the 'retrained_graph.pb' file.

    This is a nice way of outputting the required files to view it in TensorBoard. https://gist.github.com/jubjamie/2eec49ca1e4f58c5310d72918d991ef6

    Once you run that code and have the output going to your chosen directory, you can start up TensorBoard and view it in Chrome. Viewing the graph helps me alot since I'm a noob in this area.

    0 讨论(0)
  • 2020-12-29 23:53

    Not everyone is getting this error. I'm guessing if you used any other architecture apart from MobileNet this error turns up. In your label_image.py file change the values to:

    input_height = 299
    input_width = 299
    input_layer = "Mul"
    

    This should solve it.

    0 讨论(0)
提交回复
热议问题