Tensorflow TypeError: Fetch argument None has invalid type ?

后端 未结 2 1623
不思量自难忘°
不思量自难忘° 2020-12-06 09:50

I\'m building a RNN loosely based on the TensorFlow tutorial.

The relevant parts of my model are as follows:

input_sequence = tf.placeholder(tf.float         


        
相关标签:
2条回答
  • 2020-12-06 10:04

    You are re-assigning the train_step variable to the second element of the result of sess.run() (which happens to be None). Hence, on the second iteration, train_step is None, which leads to the error.

    The fix is fortunately simple:

    for i in xrange(1, ITERATIONS):
    
        # ...
    
        # Discard the second element of the result.
        numpy_state, _ = sess.run([final_state, train_step], feed_dict={
            initial_state: numpy_state,
            input_sequence: batch[0],
            output_actual: batch[1]
            })
    
    0 讨论(0)
  • 2020-12-06 10:10

    Another common reason to get this error is if you include the summary fetch operation but have not written any summaries.

    Example:

    # tf.summary.scalar("loss", loss) # <- uncomment this line and it will work fine
    summary_op = tf.summary.merge_all()
    sess = tf.Session()
    # ...
    summary = sess.run([summary_op, ...], feed_dict={...}) # TypeError, summary_op is "None"!
    

    What's extra confusing is that summary_op is not itself None, that's just the error that bubbles up from inside the session's run method.

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