TensorFlow 2 YOLOv4
tensorflow-yolov4
python3 -m pip install yolov4
YOLOv4 Implemented in Tensorflow 2.
Download Weights
- yolov4-tiny.conv.29
- yolov4-tiny.weights
- yolov4-tiny-relu.weigths
- yolov4.conv.137
- yolov4.weights
- yolov4-csp.weights
- yolov4x-mish.weights
- coco.names
- config
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
- v3
- v2
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",
)
from yolov4.tf import YOLOv4
yolo = YOLOv4()
# yolo = YOLOv4(tiny=True)
yolo.classes = "coco.names"
yolo.input_size = (640, 480)
yolo.make_model()
yolo.load_weights("yolov4.weights", weights_type="yolo")
# yolo.load_weights("yolov4-tiny.weights", weights_type="yolo")
yolo.inference(media_path="kite.jpg")
yolo.inference(media_path="road.mp4", is_image=False)
tensorflow lite
- v3
- v2
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")
from yolov4.tf import YOLOv4
yolo = YOLOv4()
yolo.classes = "coco.names"
yolo.input_size = (640, 480)
yolo.make_model()
yolo.load_weights("yolov4.weights", weights_type="yolo")
yolo.save_as_tflite("yolov4_640x480.tflite")
from yolov4.tflite import YOLOv4
yolo = YOLOv4()
yolo.classes = "coco.names"
yolo.load_tflite("yolov4_640x480.tflite")
yolo.inference("kite.jpg")