我是 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_session
is not available ' RuntimeError:get_session
is not available when using TensorFlow …