完美解决丨RuntimeError: create_session() called before __init__().

简介: 完美解决丨RuntimeError: create_session() called before __init__().

错误:

import sys

sys.path.append('/home/pi/ssd-detect')

import ssd_detect

ssd_detect.detect('/home/pi/ssd-detect/test.jpg')

报错如下:

Traceback (most recent call last):

File "test.py", line 6, in <module

ssd_detect.detect('/home/pi/ssd-detect/test.jpg')

File "/home/pi/ssd-detect/ssd_detect.py", line 31, in detect

output_dict = run_inference_for_single_image(image_np, detection_graph)

File "/home/pi/ssd-detect/ssd_detect.py", line 15, in run_inference_for_single_image

with tf.Session() as sess:

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1551, in enter

return self._default_session().enter()

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 536, in _default_session

self._session_impl_fn)

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 633, in _create_session

return self._session_factory.create_session()

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 662, in create_session

raise RuntimeError('create_session() called before init().')

RuntimeError: create_session() called before init().

解决办法:

链接:https://www.jianshu.com/p/6c8e611d73b7

原因分析:

根据错误的描述,也就是说调用了 sess.run() 这个函数之前没有初始化 sess ,这样就会报错。

这个错误是因为 sess.run() 这个函数是在 sess 被初始化之后才能被调用。


相关文章
|
9月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
191 1
|
7月前
|
Python
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
加载模型出现-RuntimeError: Error(s) in loading state_dict for Net:unexpected key(s) in state_dict: XXX
加载模型出现-RuntimeError: Error(s) in loading state_dict for Net:unexpected key(s) in state_dict: XXX
603 0
|
8月前
|
Python
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
243 0
|
机器学习/深度学习 Windows
raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}‘.format( RuntimeError: Error(s)..报错
即load_state_dict(fsd,strict=False) 属性strict;当strict=True,要求预训练练权重层数的键值与新构建的模型中的权重层数名称完全吻合;
1651 0
|
PyTorch 算法框架/工具
torch中报错:AttributeError: 'builtin_function_or_method' object has no attribute 'detach'怎么解决?
这个错误信息 "AttributeError: 'builtin_function_or_method' object has no attribute 'detach'" 表示你尝试在一个内置函数或方法对象上调用 detach() 方法,而这种对象没有这个属性。 detach() 是 PyTorch 张量和变量的方法,允许它们从计算图中分离出来,因此不能在其他类型的对象上调用。要解决这个错误,请确保你正在一个 PyTorch 张量或变量上调用 detach() 方法。
1150 0
BeanFactory not initialized or already closed - call 'refresh' before access
BeanFactory not initialized or already closed - call 'refresh' before access
372 0