OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.5k stars 2.18k forks source link

Getting error when trying to initialize the VideoObjectDetection. #76

Closed vpolimenov closed 5 years ago

vpolimenov commented 5 years ago

Here is the error I am getting:

Using Theano backend.
Traceback (most recent call last):
  File "object_detection.py", line 9, in <module>
    detector = VideoObjectDetection()
  File "/Users/ventsislav/anaconda/envs/py3/lib/python3.6/site-packages/imageai/Detection/__init__.py", line 914, in __init__
    self.sess = K.get_session()
AttributeError: module 'keras.backend' has no attribute 'get_session'

I see that in the __init__.py there is this and found out that it should be changed to import keras.backend.tensorflow_backend as K.

Here is the link that helped me find that out.

OlafenwaMoses commented 5 years ago

ImageAI currently supports Tensorflow as the backend for Keras.

vpolimenov commented 5 years ago

I am having difficulties to set the first video example.

Here are the version of all dependencies:

tensorflow==1.8.0
numpy==1.13.3
scipy==0.19.1
keras==2.1.5
opencv-python==3.4.3.18
h5py==2.8.0
imageai==2.0.2

I managed to overcome the error above by forking the repo and changing this line of code. However, I don't think this would be the proper solution as now I am getting:

Traceback (most recent call last):
  File "object_detection.py", line 9, in <module>
    execution_path = os.getcwd()
  File "/Users/ventsislav/Venci/Development/ImageAI/imageai/Detection/__init__.py", line 1076, in loadModel
    iou_threshold=self.__yolo_iou)
  File "/Users/ventsislav/anaconda/envs/py3/lib/python3.6/site-packages/imageai/Detection/YOLOv3/utils.py", line 87, in yolo_eval
    anchors[anchor_mask[l]], num_classes, input_shape, image_shape)
  File "/Users/ventsislav/anaconda/envs/py3/lib/python3.6/site-packages/imageai/Detection/YOLOv3/utils.py", line 64, in yolo_boxes_and_scores
    anchors, num_classes, input_shape)
  File "/Users/ventsislav/anaconda/envs/py3/lib/python3.6/site-packages/imageai/Detection/YOLOv3/utils.py", line 15, in yolo_head
    [1, grid_shape[1], 1, 1])
  File "/Users/ventsislav/anaconda/envs/py3/lib/python3.6/site-packages/keras/backend/theano_backend.py", line 975, in tile
    if n.ndim == 0:
AttributeError: 'list' object has no attribute 'ndim'

when loading the yolo pre-trained model.

EDIT Forgot to mention it's a python 3 environment.

vpolimenov commented 5 years ago

ok got it.

the solution was to set the keras backend variable to use tensorflow.

KERAS_BACKEND=tensorflow python video_detection.py

OlafenwaMoses commented 5 years ago

I am glad you got it fixed.