完美解决丨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 被初始化之后才能被调用。


相关文章
|
7月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
156 1
|
4月前
|
缓存 Dart 开发工具
解决Flutter报错The method ‘File.create‘ has fewer named arguments than those of overridden method
解决Flutter报错The method ‘File.create‘ has fewer named arguments than those of overridden method
66 3
成功解决:Error in created hook: “ReferenceError: params is not defined“
该博客文章描述了作者解决"ReferenceError: params is not defined"错误的过程,原因是路由传递的params参数与调用方法中的参数名称冲突,最终通过检查接口参数解决了问题。
成功解决:Error in created hook: “ReferenceError: params is not defined“
|
5月前
|
Python
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
|
6月前
|
Python
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
180 0
加载模型出现-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
569 0
|
PHP
set_error_handler()
set_error_handler()
56 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,要求预训练练权重层数的键值与新构建的模型中的权重层数名称完全吻合;
1574 0