728x90
Deep MNIST for Experts 튜토리얼 실행시 발생할 수 있는 텐서플로우 코드 에러
value error 가 발생하는 경우
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | for i in range(20000): batch = mnist.train.next_batch(50) if i%100 == 0: train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0}) print "step %d, training accuracy %g" % (i, train_accuracy) train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5}) ------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-21-ea20ade49f79> in <module>() 2 batch = mnist.train.next_batch(50) 3 if i%100 == 0: ----> 4 train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0}) 5 print "step %d, training accuracy %g" % (i, train_accuracy) 6 train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5}) /root/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in eval(self, feed_dict, session) 553 554 """ --> 555 return _eval_using_default_session(self, feed_dict, self.graph, session) 556 557 /root/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in _eval_using_default_session(tensors, feed_dict, graph, session) 3482 session = get_default_session() 3483 if session is None: -> 3484 raise ValueError("Cannot evaluate tensor using `eval()`: No default " 3485 "session is registered. Use `with " 3486 "sess.as_default()` or pass an explicit session to " ValueError: Cannot evaluate tensor using `eval()`: No default session is registered. Use `with sess.as_default()` or pass an explicit session to `eval(session=sess)` | cs |
아래와 같이 명시적으로 세션을 넘긴다.
1 2 3 4 5 6 | if i%100 == 0: train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0}) if i%100 == 0: train_accuracy = accuracy.eval(session=sess, feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0}) | cs |
728x90
'프로그래밍 Programming' 카테고리의 다른 글
Deep MNIST for Experts - 전체 코드 (1) (0) | 2016.10.31 |
---|---|
텐서플로우 코드 에러 - FailedPreconditionError (0) | 2016.10.30 |
주피터 노트북 html 파일로 변환하기 How to copy/paste from IPython Notebook to other format (0) | 2016.10.29 |
텐서플로우 따라잡기 MNIST For ML Beginners (3) -Training & Evaluating Our Model (0) | 2016.10.29 |
텐서플로우 따라잡기 MNIST For ML Beginners (2) - Implementing the Regression (0) | 2016.10.29 |