0
votes

Why is sess passing into the consumer in training but failing in the eval() in acccracy https://github.com/JasonPrendergast/AccuracyTestingaModel

I am threading a batch accuracy test and come across the error: ValueError("Cannot evaluate tensor using eval(): No default " 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)

I have been using threads for my training and have had no problem passing the session as sess to the consumer class like this:

_, c = self.sess.run([self.optimizer, self.cost], feed_dict={x: np.array(batch_x),y: np.array(batch_y)})

This is running fine I can produce my model using the consumer class. But when I try running:

result = (self.sess.run(tf.argmax(self.prediction.eval(feed_dict={x:[np.array(batch_x)]}),1)))

I get the error

Traceback (most recent call last): File "C:\Users\jimbob\AppData\Local\Programs\Python\Python35\lib\threading.py", line 914, in _bootstrap_inner self.run() File "C:\Users\jimbob\AppData\Local\Programs\Python\Python35\lib\threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "D:/mine/jobs_network/NN_size_10k_batch/testAcc2_threads.py", line 198, in run result = (self.sess.run(tf.argmax(self.prediction.eval(feed_dict={x:[np.array(batch_x)]}),1))) File "C:\Users\jimbob\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 541, in eval return _eval_using_default_session(self, feed_dict, self.graph, session) File "C:\Users\jimbob\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 4071, in _eval_using_default_session raise ValueError("Cannot evaluate tensor using eval(): No default " 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)

1
result = (sess.run(tf.argmax(prediction.eval(feed_dict={x:[features]}),1))) is working when I am not threading - Smith Jones

1 Answers

0
votes

I have reached the result I wanted by replacing result = (self.sess.run(tf.argmax(self.prediction.eval(feed_dict={x:[np.array(batch_x)]}),1))) with result=self.prediction.eval(session = self.sess,feed_dict={x: np.array(batch_x)}) result= np.array(result) outputarray.append(str((labellexicon[int(np.argmax(result))])))