python - 使用 TensorFlow 2.0 时,`get_session` 不可用
问题描述
我尝试使用 Python 3.7 和 PyCharm 2019 CE 运行此脚本,已经安装了所有必需的库。
https://towardsdatascience.com/object-detection-with-10-lines-of-code-d6cb4d86f606
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg"))
for eachObject in detections:
print(eachObject["name"] , " : " , eachObject["percentage_probability"] )
然后,我收到了以下错误消息:
C:\Program Files\Python37\python.exe" "D:/Kuliah/SMT 5/AI/TR/FirstDetection.py"
Using TensorFlow backend.
2020-03-31 00:40:15.115871: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-03-31 00:40:15.116113: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "D:/Kuliah/SMT 5/AI/TR/FirstDetection.py", line 6, in <module>
detector = ObjectDetection()
File "C:\Program Files\Python37\lib\site-packages\imageai\Detection\__init__.py", line 88, in __init__
self.sess = K.get_session()
File "C:\Program Files\Python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 379, in get_session
'`get_session` is not available '
RuntimeError: `get_session` is not available when using TensorFlow 2.0.
Process finished with exit code 1
解决方案
推荐阅读
- sql - Teradata SQL 格式化十进制字段
- python - 由嵌入的子节点产生的 Elementtree 重复
- javascript - localStorage 返回 null,即使它可以通过浏览器登录到控制台
- python - 无法理解 __lt__ 方法
- html - 即使在使用 Multer 和 HTML 的 Nodejs 项目中表单提交失败时,图像也会保存
- javascript - 如何在 JavaScript 中执行 GPS 坐标三角测量?
- javascript - 更改下拉 Javascript 后结果不更新
- reactjs - 我应该使用什么类型来匹配返回 div 的 FunctionComponent?
- c - 正确使用“volatile”是否仍然(总是)导致程序与该数据具有未定义的交互?
- java - 将 MongoDB Java 驱动程序添加为 Maven 依赖项的问题