Car and Object Detection in Python 3 (Tensorflow – ImageAI)
What’s up guys? Been a minute!
In this post we’re gonna take a look at a basic approach to do object detection in Python 3 using ImageAI and TensorFlow.
Unfortunately this post will be kind of short since I’m in the middle of studying for a certification. So let’s get to it!
Python Environment
We’ll need a specific version of Python, which is: Python 3.6.8
Go ahead and download it for your operating system.
Then we’ll need the following libraries (install using pip):
- TensorFlow (pip install tensorflow==1.13.1) *
- OpenCV (pip install opencv-python)
- Keras (pip install keras)
- ImageAI (pip install imageai)
* Make sure to use this specific version for compatibility.
Object Detection Code
Before we get into the code, you’ll need the object detection class, which you can download from the following link: choose “yolo.h5“.
Make sure to place that class in the same folder as the python script:
from imageai.Detection import VideoObjectDetection import os import cv2 # Get current working directory curDir = os.getcwd() # Initialize video capture (webcam) camera = cv2.VideoCapture(0) # Initialize imageAI objects and files detector = VideoObjectDetection() detector.setModelTypeAsYOLOv3() detector.setModelPath(os.path.join(curDir, "yolo.h5")) detector.loadModel() # Start object detection and print frames video_path = detector.detectObjectsFromVideo(camera_input=camera, output_file_path=os.path.join(curDir, "cam1") , frames_per_second=4, log_progress=True) print(video_path)
Note that the frames_per_second parameter will allow for more realistic recording of your webcam/camera. However, since we aren’t yet using a graphics card to process this, you might want to keep it low.
Anyway gotta get back to studying, any questions let me know and I’ll get to it later on in the week! 😉
Hi I’ve implemented your code and its running successfully, Great work!!!
Just wanted to know how to set time limit in this code??
AttributeError: module ‘keras.backend’ has no attribute ‘get_session’ i got this error
and i want run with laptop camera how to make it.
AttributeError: module ‘keras.backend’ has no attribute ‘get_session’ i got this error
and i want run with laptop camera how to make it.
Hi there! Good work! Would be nice if you could write an article on how to deploy these as well.