I have the following code
from imageai.Detection import ObjectDetection
detector = ObjectDetection()
then I got this error
AttributeError Traceback (most recent call last)
<ipython-input-30-0381e3fc0028> in <module>
----> 1 detector = ObjectDetection()
2
3 # model_path = "./models/yolo-tiny.h5"
4 # execution_path = os.getcwd()
5
~\anaconda3\lib\site-packages\imageai\Detection\__init__.py in __init__(self)
86 self.__yolo_model_image_size = (416, 416)
87 self.__yolo_boxes, self.__yolo_scores, self.__yolo_classes = "", "", ""
---> 88 self.sess = K.get_session()
89
90 # Unique instance variables for TinyYOLOv3.
AttributeError: module 'keras.backend' has no attribute 'get_session'
I imported tensorflow and keras after this was ran and these are the versions respectively
print(tensorflow.__version__)
print(keras.__version__)
2.3.1
2.4.3
I tried installing tensorflow=1.13.1 because I read it should help somewhere but that was from 2018 and it didn't work.
What can I do to fix this bug?
Or is there any other way to use pre-trained object detection models?
You are using https://github.com/OlafenwaMoses/ImageAI.
Despite it is not deprecated, the last commit from this repository is from January 2019.
Also, they integrate in their framework outdated networks
( keras-retinanet is deprecated, for instance )
Given that, I will answer your last question:
'is there any other way to use pre-trained object detection models?':
Yes, there are.
Both
tensorflow
andpytorch
,that are currently the main libraries for deep learning, offer them.
For instance, pytorch has few detection models coded in
torchvision.models.detection
: https://github.com/pytorch/vision/tree/master/torchvision/models/detectionNote 1: to install pytorch, you have to run in your conda environment:
conda install torchvision -c pytorch
Note 2: the following code has been made functional, combining the docstrings in : https://github.com/pytorch/vision/blob/master/torchvision/models/detection/retinanet.py
and this tutorial:
https://debuggercafe.com/faster-rcnn-object-detection-with-pytorch/
I suggest you to have a look at them, too.
Output: