小编pal*_*ole的帖子

如何修复“运行时错误:使用 TensorFlow 2.0 时‘get_session’不可用。”

我是 python 的新手,我一直在尝试运行此代码。但我不断收到此错误。

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()
self.sess = tf.compat.v1.keras.backend.get_session()
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"] )
Run Code Online (Sandbox Code Playgroud)

我应该得到图像中对象的百分比,但我得到的是:

使用 TensorFlow 后端。回溯(最近一次调用):文件“detector.py”,第 6 行,在检测器 = ObjectDetection() 文件“C:\Python36\lib\site-packages\imageai\Detection__init__.py”,第 88 行,在init self .sess = K.get_session() File "C:\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 379, in get_session ' get_sessionis not available ' RuntimeError: get_sessionis not available when using TensorFlow …

python tensorflow

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

tensorflow ×1