Skip to main content

TensorFlow 2 YOLOv4

license pypi language

tensorflow-yolov4#

python3 -m pip install yolov4

YOLOv4 Implemented in Tensorflow 2.

Download Weights#

Dependencies#

python3 -m pip install opencv-python
python3 -m pip install tensorflow

TFlite#

Ref: https://www.tensorflow.org/lite/guide/python

Objective#

  • Train and predict using TensorFlow 2 only
  • Run yolov4-tiny-relu on Coral board(TPU).
  • Train tiny-relu with coco 2017 dataset
  • Update Docs
  • Optimize model and operations

Performance#

Help#

>>> from yolov4.tf import YOLOv4
>>> help(YOLOv4)

Inference#

tensorflow#

import cv2
from yolov4.tf import YOLOv4
yolo = YOLOv4()
yolo.config.parse_names("coco.names")
yolo.config.parse_cfg("yolov4-tiny.cfg")
yolo.make_model()
yolo.load_weights("yolov4-tiny.weights", weights_type="yolo")
yolo.summary(summary_type="yolo")
yolo.summary()
yolo.inference(media_path="kite.jpg")
yolo.inference(media_path="road.mp4", is_image=False)
yolo.inference(
"/dev/video0",
is_image=False,
cv_apiPreference=cv2.CAP_V4L2,
cv_frame_size=(640, 480),
cv_fourcc="YUYV",
)

tensorflow lite#

from yolov4.tf import YOLOv4, save_as_tflite
yolo = YOLOv4()
yolo.config.parse_names("coco.names")
yolo.config.parse_cfg("yolov4-tiny.cfg")
yolo.make_model()
yolo.load_weights("yolov4-tiny.weights", weights_type="yolo")
save_as_tflite(
model=yolo.model,
tflite_path="yolov4-tiny-float16.tflite",
quantization="float16",
)
from yolov4.tflite import YOLOv4
yolo = YOLOv4()
yolo.config.parse_names("coco.names")
yolo.config.parse_cfg("yolov4-tiny.cfg")
yolo.load_tflite("yolov4-tiny-float16.tflite")
yolo.inference("kite.jpg")
Last updated on