Error in using ImageAi, TensorFlow, OpenCV

  imageai, opencv, python, tensorflow, tensorflow2.0

I trying ImageAI with Python by Tutorial. Tutorial recorded in 2019. Now this code not working.

Code:

from imageai.Detection import ObjectDetection
import os
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
exec_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(
    exec_path, "resnet.h5")
)
detector.loadModel()

list = detector.detectObjectsFromImage(
    input_image=os.path.join(exec_path, "objects.jpg"),
    output_image_path=os.path.join(exec_path, "new_objects.jpg"),
    minimum_percentage_probability=90,
    display_percentage_probability=True,
    display_object_name=False
)

Output from Run(PyCharm):

AttributeError: module 'tensorflow' has no attribute 'get_default_session'

Source: Python Questions

LEAVE A COMMENT