错误:
代码语言:javascript复制import sys
sys.path.append('/home/pi/ssd-detect')
import ssd_detect
ssd_detect.detect('/home/pi/ssd-detect/test.jpg')
报错如下:
代码语言:javascript复制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 ,这样就会报错。