0

I tried to run this script with Python 3.7 and PyCharm 2019 CE, already installed every required libraries.

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"] )

And then, I got this error messages :

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
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 2
    Have you tried running it with tensorflow 1.x instead of 2.x? Under dependencies in https://github.com/OlafenwaMoses/ImageAI it says "Tensorflow 2.0 coming soon" – simon Mar 30 '20 at 19:10
  • Please try to give descriptive and meaningful titles in your posts (edited for you this time). As for the error, as already suggested, it seems you are trying to run TF 1.x code in TF 2.0 – desertnaut Mar 31 '20 at 08:40
  • Thanks, I forgot this code using Tensorflow 1.0 and I'm running it with 2.0. – Valen Brata Apr 01 '20 at 06:50

0 Answers0