cannot evaluate tensor using `eval()`: no default session is registered. use `with sess.as_default()` or pass an explicit session to `eval(session=sess)`
时间: 2023-05-03 07:02:34 浏览: 73
这个错误的意思是“无法使用'eval()'评估张量:没有默认会话被注册。使用'sess.as_default()'或将明确的会话传递给'eval(session = sess)'”。解决方法是在TensorFlow代码中添加“with sess.as_default():”或者将明确的会话传递给“eval(session = sess)”。
相关问题
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)`
这个错误表示代码尝试使用`eval()`函数评估张量,但没有默认的TensorFlow会话。可以使用`with sess.as_default()`或将一个显式的会话传递给`eval(session=sess)`。
Traceback (most recent call last): File "test.py", line 190, in <module> evaluate_images(test_img) File "test.py", line 169, in evaluate_images threads = tf.train.start_queue_runners(coord=coord) File "E:\anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\python\util\deprecation.py", line 324, in new_func return func(*args, **kwargs) File "E:\anaconda\envs\tensorflow1\lib\site-packages\tensorflow_core\python\training\queue_runner_impl.py", line 456, in start_queue_runners raise ValueError("Cannot start queue runners: No default session is " ValueError: Cannot start queue runners: No default session is registered. Use `with sess.as_default()` or pass an explicit session to tf.start_queue_runners(sess=sess)
这个错误通常是因为在使用`tf.train.start_queue_runners()`函数之前没有创建或指定默认的会话(session)。您可以尝试以下两种解决方法:
1. 在调用`tf.train.start_queue_runners()`之前,使用`with tf.Session() as sess:`来创建一个会话,并将其作为默认会话。例如:
```python
with tf.Session() as sess:
# 创建会话后,设置为默认会话
sess.as_default()
# 执行其他代码
threads = tf.train.start_queue_runners(coord=coord)
```
2. 将会话对象作为参数传递给`tf.train.start_queue_runners()`函数。例如:
```python
sess = tf.Session()
# 执行其他代码
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
```
这些方法都可以确保在调用`tf.train.start_queue_runners()`时,会话对象已经存在,并且可以成功启动队列运行器。请根据您的代码结构选择适合的解决方法。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)