I am new to python and I have be trying to run this code. But I keep getting this error.
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"] )
I am supposed to get the percentage for the objects in the image but instead I am getting this:
Using TensorFlow backend. Traceback (most recent call last): File "detector.py", line 6, in detector = ObjectDetection() File "C:\Python36\lib\site-packages\imageai\Detection__init__.py", line 88, in 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 2.0.
Answer:
In TF 2.0 you should use tf.compat.v1.Session()
instead of tf.Session()
Use the following code to get rid of the error in Tensorflow2.0
:
import tensorflow as tf
tf.compat.v1.Session()
i.e. in your code above, replace this line self.sess = tf.compat.v1.keras.backend.get_session()
of code with
self.sess = tf.compat.v1.Session()
Reference:
'get_session' is not available when using tensorflow 2.0. It is available in tensorflow 1.14.0
Just write in the command line
pip install tensorflow==1.14.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With