/ObjectDetection-YOLOv4-TensorFlow

Real-time Object Detection with YOLOv4 in TensorFlow. Quick accessible module for AI newbies. Ready for use with official weights. Simple code structure and easy to follow.

Primary LanguagePythonMIT LicenseMIT

Object-Detection-With-YOLOv4-TF

license

Introduction

AI could be as easy as opening a file and one click of "run all"!

We present a quickly accessible Object Detection module for all newbies without AI knowledge. YOLOv4 is the state-of-the-art Object Detection algorithm applicable to mobile devices. Our Tensorflow implementation is ready for use with pretrained weights (the original Darknet weights from AlexeyAB). It has minimal code and easy to follow.

Once you get comfortble with the module, you can either choose to extend the functionality by combineing with other modules, such as OCR (Optical Character Recognition), Object Tracking, Object Counting, Object Detection in Webcam, etc., check out theAIGuysCode for inspirations. Or you can choose to customize the configuration parameters, migrate to TensorFlow Lite for mobile devices, fine-tune weights for your domain, or even transfer learning for other purpose, check out hunglc007 / tensorflow-yolov4-tflite for inspirations.

Performance

Code map

core
  |________config.py                 Configuration for YOLOv4
  |________utils.py                  Utilities for YOLOv4
data
  |________classes
  |          |________coco.names     List of object types for YOLOv4  
  |________kite.jpg                  Example image
  |________road.mp4                  Example video
yolov4-416                           Pretrained weights
detectimage.py                       Object detection for image
detectvideo.py                       Object detection for video
requirements-cpu.txt                 Requirements for running with CPU
requirements-gpu.txt                 Requirements for running with GPU
result.png                           Example output image
results.avi                          Example output video

Demo for running in cloud (Google Colab)

Note you have to download the file and open it with Jupyter Notebook, and click "Runtime/Run all"

Object-Detection-With-YOLOv4-TF.ipynb

Prerequisites

  • Tensorflow 2.3.0rc0

Install requirements

pip install -r requirements-gpu.txt

or

pip install -r requirements-cpu.txt

Unzip pretrained weights

# Go to the directory containing weights
cd /content/Object-Detection-With-YOLOv4-TF/yolov4-416/variables/

# Concatenate the zip parts into a whole one
cat variables.z* > variables-all.zip

# Unzip for the weights
unzip variables-all.zip

Detect objects in images or videos

# Object detection in images
python detectimage.py --image ./data/kite.jpg --output result.png

# Object detection in videos
python detectvideo.py --video ./data/road.mp4 --output result.avi

TODO

  • Supply the demo for running in cloud (Colab)
  • Add results for illustration
  • Supply the code map

References

  • YOLOv4: Optimal Speed and Accuracy of Object Detection YOLOv4.

My project is based on these previous fantastic YOLOv4 implementations: