TensorFlow Error found in Tutorial

后端 未结 2 1396
暗喜
暗喜 2021-02-02 10:04

Dare I even ask? This is such a new technology at this point that I can\'t find a way to solve this seemingly simple error. The tutorial I\'m going over can be found here- http:

相关标签:
2条回答
  • 2021-02-02 10:25

    I figured it out. As you see in the value error, it says No default session is registered. Use 'with DefaultSession(sess)' or pass an explicit session to eval(session=sess) so the answer I came up with is to pass an explicit session to eval, just like it says. Here is where I made the changes.

    if i%100 == 0:
            train_accuracy = accuracy.eval(session=sess, feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0})
    

    And

    train_step.run(session=sess, feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    

    Now the code is working fine.

    0 讨论(0)
  • 2021-02-02 10:35

    I encountered a similar error when I tried a simple tensorflow example.

    import tensorflow as tf
    v = tf.Variable(10, name="v")
    sess = tf.Session()
    sess.run(v.initializer)
    print(v.eval())
    

    My solution is to use sess.as_default(). For example, I changed my code to the following and it worked:

    import tensorflow as tf
    v = tf.Variable(10, name="v")
    with tf.Session().as_default() as sess:
      sess.run(v.initializer)      
      print(v.eval())
    

    Another solution can be use InteractiveSession. The difference between InteractiveSession and Session is that an InteractiveSession makes itself the default session so you can run() or eval() without explicitly call the session.

    v = tf.Variable(10, name="v")
    sess = tf.InteractiveSession()
    sess.run(v.initializer)
    print(v.eval())
    
    0 讨论(0)
提交回复
热议问题