A Keras implementation of YOLOv4 (Tensorflow backend)

Overview

keras-yolo4

license

请使用更完善的版本:

https://github.com/miemie2013/Keras-YOLOv4

Please visit here for more complete model:

https://github.com/miemie2013/Keras-YOLOv4

Introduction

A Keras implementation of YOLOv4 (Tensorflow backend) inspired by https://github.com/AlexeyAB/darknet.

Frame code from https://github.com/qqwweee/keras-yolo3.


Quick Start

  1. Download YOLOv4 weights from yolov4.weights.
  2. Convert the Darknet YOLOv4 model to a Keras model.
  3. Run YOLOv4 detection.
python convert.py

Running convert.py will get keras yolov4 weight file yolo4_weight.h5.

Usage

Inference

python test.py

Todo

Debug train code with CIoU loss. Loss code from https://github.com/david8862/keras-YOLOv3-model-set.

Comments
  • Error while converting to keras model

    Error while converting to keras model

    I have trained yolo.weights (with my custom dataset having 3 classes) and the detections are coming fine while testing with that model. But when i am converting it to keras model, I am getting below error

    File "convert.py", line 172, in <module>
        yolo4_model = Yolo4(score, iou, anchors_path, classes_path, model_path, weights_path)
      File "convert.py", line 157, in __init__
        self.load_yolo()
      File "convert.py", line 98, in load_yolo
        buffer=weights_file.read(weights_size * 4))
    TypeError: buffer is too small for requested array
    
    

    Could someone tell me why it is happening and what changes I should make

    opened by vihari1729 11
  • any experiences about the training loss ?

    any experiences about the training loss ?

    thanks for the nice repo.

    I am training yolov4 on coco dataset for only the first 7 classes with a split 70:30, any experiences or hints about the training loss when the model seems acceptable?

    below is my traing log, seem a long time to train.

    Train on 82801 samples, val on 35486 samples, with batch size 32.
    Epoch 1/50
    
       1/2587 [..............................] - ETA: 28:56:58 - loss: 17721.8926
       2/2587 [..............................] - ETA: 16:33:45 - loss: 17243.4922
       3/2587 [..............................] - ETA: 12:32:28 - loss: 16760.1377
       4/2587 [..............................] - ETA: 10:10:04 - loss: 16299.9021
       5/2587 [..............................] - ETA: 9:24:35 - loss: 15857.3045 
       6/2587 [..............................] - ETA: 9:14:57 - loss: 15430.3268
       7/2587 [..............................] - ETA: 9:07:24 - loss: 15008.8902
       8/2587 [..............................] - ETA: 9:01:51 - loss: 14608.8591
       9/2587 [..............................] - ETA: 9:12:25 - loss: 14219.5904
      10/2587 [..............................] - ETA: 9:20:37 - loss: 13848.0055
      11/2587 [..............................] - ETA: 9:18:39 - loss: 13490.1777
      12/2587 [..............................] - ETA: 8:59:26 - loss: 13150.2271
      13/2587 [..............................] - ETA: 8:44:20 - loss: 12822.8066
      14/2587 [..............................] - ETA: 8:34:12 - loss: 12509.4747
      15/2587 [..............................] - ETA: 8:32:09 - loss: 12211.5387
      16/2587 [..............................] - ETA: 8:26:59 - loss: 11925.6479
      17/2587 [..............................] - ETA: 8:20:37 - loss: 11649.0334
      18/2587 [..............................] - ETA: 8:21:20 - loss: 11381.8880
      19/2587 [..............................] - ETA: 8:14:07 - loss: 11124.9040
      20/2587 [..............................] - ETA: 8:11:29 - loss: 10882.4443
      21/2587 [..............................] - ETA: 8:07:56 - loss: 10645.2164
      22/2587 [..............................] - ETA: 8:03:53 - loss: 10420.4502
      23/2587 [..............................] - ETA: 7:58:37 - loss: 10203.8660
      24/2587 [..............................] - ETA: 7:54:08 - loss: 9995.8066 
      25/2587 [..............................] - ETA: 7:50:39 - loss: 9794.8682
      26/2587 [..............................] - ETA: 7:48:39 - loss: 9599.6988
      27/2587 [..............................] - ETA: 7:45:55 - loss: 9411.8161
      28/2587 [..............................] - ETA: 7:42:36 - loss: 9234.4692
      29/2587 [..............................] - ETA: 7:39:51 - loss: 9060.8342
      30/2587 [..............................] - ETA: 7:35:15 - loss: 8894.1920
      31/2587 [..............................] - ETA: 7:33:45 - loss: 8733.4837
      32/2587 [..............................] - ETA: 7:31:51 - loss: 8577.9887
      33/2587 [..............................] - ETA: 7:29:49 - loss: 8425.8984
      34/2587 [..............................] - ETA: 7:27:43 - loss: 8280.7446
      35/2587 [..............................] - ETA: 7:26:30 - loss: 8139.6654
      36/2587 [..............................] - ETA: 7:26:01 - loss: 8004.0953
      37/2587 [..............................] - ETA: 7:26:13 - loss: 7872.3828
      38/2587 [..............................] - ETA: 7:24:52 - loss: 7746.5956
      39/2587 [..............................] - ETA: 7:23:28 - loss: 7624.6465
      40/2587 [..............................] - ETA: 7:29:19 - loss: 7506.7023
      41/2587 [..............................] - ETA: 7:35:16 - loss: 7391.7025
      42/2587 [..............................] - ETA: 7:34:34 - loss: 7280.5936
      43/2587 [..............................] - ETA: 7:31:58 - loss: 7172.5243
      44/2587 [..............................] - ETA: 7:29:56 - loss: 7067.7942
      45/2587 [..............................] - ETA: 7:30:26 - loss: 6965.9564
      46/2587 [..............................] - ETA: 7:31:08 - loss: 6867.1803
      47/2587 [..............................] - ETA: 7:34:20 - loss: 6771.7925
    
    opened by Papageno2 5
  • "Unknown layer: Mish" while loading converted model from "yolo4_weight.h5"

    Source code

    from tensorflow import keras
    new_model = keras.models.load_model('yolo4_weight.h5')
    

    Error occurred:

    Traceback (most recent call last):
      File "/home/source/keras-yolo4/mytest.py", line 13, in <module>
        new_model = keras.models.load_model(h5)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 146, in load_model
        return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 212, in load_model_from_hdf5
        custom_objects=custom_objects)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config
        return deserialize(config, custom_objects=custom_objects)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 89, in deserialize
        printable_module_name='layer')
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 192, in deserialize_keras_object
        list(custom_objects.items())))
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1121, in from_config
        process_layer(layer_data)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1105, in process_layer
        layer = deserialize_layer(layer_data, custom_objects=custom_objects)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 89, in deserialize
        printable_module_name='layer')
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 181, in deserialize_keras_object
        config, module_objects, custom_objects, printable_module_name)
      File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 166, in class_and_config_for_serialized_keras_object
        raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
    ValueError: Unknown layer: Mish
    
    opened by shangdibufashi 3
  • TypeError: buffer is too small for requested array

    TypeError: buffer is too small for requested array

    Loading weights. Weights Header: 1329865020 1348031555 1952981061 [1010723949] Converting 0 Traceback (most recent call last): File "convert.py", line 173, in yolo4_model = Yolo4(score, iou, anchors_path, classes_path, model_path, weights_path) File "convert.py", line 157, in init self.load_yolo() File "convert.py", line 130, in load_yolo buffer=weights_file.read(weights_size * 4)) TypeError: buffer is too small for requested array

    opened by saanuregh 3
  • Your some layers are different from miemie2013's.

    Your some layers are different from miemie2013's.

    in @miemie2013's code

    x = layers.ZeroPadding2D(padding=((1, 0), (1, 0)))(x)
    x = conv2d_unit(x, i512, 3, strides=2)
    s16 = conv2d_unit(x, i256, 1, strides=1)
    x = conv2d_unit(x, i256, 1, strides=1)
    x = stack_residual_block(x, i256, i256, n=8)
    x = conv2d_unit(x, i256, 1, strides=1)
    s16 = layers.Concatenate()([x, s16])
    x = conv2d_unit(s16, i512, 1, strides=1)
    

    where s16 is the output of Concatenate()

    x = layers.UpSampling2D(2)(x)
    s16 = conv2d_unit(s16, i256, 1, strides=1, act='leaky')
    x = layers.Concatenate()([s16, x])
    

    s16 then computer through conv2d_unit and concatenate with upsampling output x

    as for your code:

    y38 = DarknetConv2D_BN_Leaky(256, (1,1))(darknet.layers[204].output)
    y38 = Concatenate()([y38, y19_upsample])
    

    where darknet.layers[204].output is the output of DarknetConv2D_BN_Mish, not the concatenate layer darknet.layers[201].outputs.

    So, I am curious which version is right, or both right?

    opened by RuaHU 1
  • Lambda laye not compatible in tf2+

    Lambda laye not compatible in tf2+

    in tf2+, Lambda layer could not be used anymore, is there any solution to solve the issue especially th error:
    ValueError: tf.function-decorated function tried to create variables on non-first call.

    opened by robbebluecp 0
  • Batching with inference

    Batching with inference

    I have converted a custom YOLO4 model to the tensorflow saved_model format. I can successfully use this for single image inference. Now when I feed in a batch of images for client side batching I get the results back in one list without separation of the results into frames so I can't work out which detections go with which frames. Can you provide any info on whether this behavior is expected or how I might remedy it?

    opened by tylertroy 0
  • ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible

    ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible

    Traceback (most recent call last):
      File "test.py", line 58, in <module>
        yolo4_model.load_weights(model_path)
      File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 492, in load_wrapper
        return load_function(*args, **kwargs)
      File "/usr/local/lib/python3.6/dist-packages/keras/engine/network.py", line 1230, in load_weights
        f, self.layers, reshape=reshape)
      File "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py", line 1237, in load_weights_from_hdf5_group
        K.batch_set_value(weight_value_tuples)
      File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 2960, in batch_set_value
        tf_keras_backend.batch_set_value(tuples)
      File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 3323, in batch_set_value
        x.assign(np.asarray(value, dtype=dtype(x)))
      File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 819, in assign
        self._shape.assert_is_compatible_with(value_tensor.shape)
      File "/home/mayur/.local/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_shape.py", line 1110, in assert_is_compatible_with
        raise ValueError("Shapes %s and %s are incompatible" % (self, other))
    ValueError: Shapes (1, 1, 1024, 75) and (255, 1024, 1, 1) are incompatible
    
    opened by mayurmahurkar 5
  • [BUG] iou computation in preprocess_true_boxes() should not use scaled bbox

    [BUG] iou computation in preprocess_true_boxes() should not use scaled bbox

    in model.py, preprocess_true_boxes(): for i in range(3): anchors_xywh = np.zeros((3, 4)) anchors_xywh[:, 0:2] = np.floor(bbox_xywh_scaled[i, 0:2]).astype(np.int32) + 0.5 anchors_xywh[:, 2:4] = anchors[i] iou_scale = bbox_iou_data(bbox_xywh_scaled[i][np.newaxis, :], anchors_xywh) iou.append(iou_scale)

    since anchors_xywh is in original scale, we shouldn't use bbox_xywh instead of bbox_xywh_scaled to compute iou?

    opened by maoqingy 0
  • What do the four parameters after loss mean during training, loss of each category or other else?

    What do the four parameters after loss mean during training, loss of each category or other else?

    Epoch 89/150 loss: [70.428894][6.8589654][49.6575623][13.912364] 1234/1234 [==============================] - 638s 517ms/step - loss: 48.12988.202549][5.05134583][33.3962708][9.7549324]]]]]]] Epoch end eval mAP on weight logs/222/ep089-loss48.130.h5 Epoch 89 mAP 0.2658832599269524 Epoch 90/150 loss: [59.5338707][5.99079227][46.7998619][6.74321651] 1234/1234 [==============================] - 655s 531ms/step - loss: 47.88505.1289482][3.23023152][27.289856][4.60885954]]]]] Epoch end eval mAP on weight logs/222/ep090-loss47.885.h5 Epoch 90 mAP 0.26986168503362695

    opened by Kuuuo 0
Owner
null
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )

Yolo v4, v3 and v2 for Windows and Linux (neural networks for object detection) Paper YOLO v4: https://arxiv.org/abs/2004.10934 Paper Scaled YOLO v4:

Alexey 20.2k Jan 9, 2023
Cascaded Pyramid Network (CPN) based on Keras (Tensorflow backend)

ML2 Takehome Project Reimplementing the paper: Cascaded Pyramid Network for Multi-Person Pose Estimation Dataset The model uses the COCO dataset which

Vo Van Tu 1 Nov 22, 2021
Object tracking implemented with YOLOv4, DeepSort, and TensorFlow.

Object tracking implemented with YOLOv4, DeepSort, and TensorFlow. YOLOv4 is a state of the art algorithm that uses deep convolutional neural networks to perform object detections. We can take the output of YOLOv4 feed these object detections into Deep SORT (Simple Online and Realtime Tracking with a Deep Association Metric) in order to create a highly accurate object tracker.

The AI Guy 1.1k Dec 29, 2022
PyTorch ,ONNX and TensorRT implementation of YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4

null 4.2k Jan 1, 2023
Implementation of "Scaled-YOLOv4: Scaling Cross Stage Partial Network" using PyTorch framwork.

YOLOv4-large This is the implementation of "Scaled-YOLOv4: Scaling Cross Stage Partial Network" using PyTorch framwork. YOLOv4-CSP YOLOv4-tiny YOLOv4-

Kin-Yiu, Wong 2k Jan 2, 2023
This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras)

Yogi-Optimizer_Keras This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras) The NeurIPS-Paper can be found here: http://papers.nips.c

null 14 Sep 13, 2022
Keras udrl - Keras implementation of Upside Down Reinforcement Learning

keras_udrl Keras implementation of Upside Down Reinforcement Learning This is me

Eder Santana 7 Jan 24, 2022
这是一个mobilenet-yolov4-lite的库,把yolov4主干网络修改成了mobilenet,修改了Panet的卷积组成,使参数量大幅度缩小。

YOLOV4:You Only Look Once目标检测模型-修改mobilenet系列主干网络-在Keras当中的实现 2021年2月8日更新: 加入letterbox_image的选项,关闭letterbox_image后网络的map一般可以得到提升。

Bubbliiiing 65 Dec 1, 2022
YOLTv4 builds upon YOLT and SIMRDWN, and updates these frameworks to use the most performant version of YOLO, YOLOv4

YOLTv4 builds upon YOLT and SIMRDWN, and updates these frameworks to use the most performant version of YOLO, YOLOv4. YOLTv4 is designed to detect objects in aerial or satellite imagery in arbitrarily large images that far exceed the ~600×600 pixel size typically ingested by deep learning object detection frameworks.

Adam Van Etten 161 Jan 6, 2023
I tried to apply the CAM algorithm to YOLOv4 and it worked.

YOLOV4:You Only Look Once目标检测模型在pytorch当中的实现 2021年2月7日更新: 加入letterbox_image的选项,关闭letterbox_image后网络的map得到大幅度提升。 目录 性能情况 Performance 实现的内容 Achievement

null 55 Dec 5, 2022
People movement type classifier with YOLOv4 detection and SORT tracking.

Movement classification The goal of this project would be movement classification of people, in other words, walking (normal and fast) and running. Yo

null 4 Sep 21, 2021
Vehicles Counting using YOLOv4 + DeepSORT + Flask + Ngrok

A project for counting vehicles using YOLOv4 + DeepSORT + Flask + Ngrok

Duong Tran Thanh 37 Dec 16, 2022
Implementing yolov4 target detection and tracking based on nao robot

Implementing yolov4 target detection and tracking based on nao robot

null 6 Apr 19, 2022
A tutorial on training a DarkNet YOLOv4 model for the CrowdHuman dataset

YOLOv4 CrowdHuman Tutorial This is a tutorial demonstrating how to train a YOLOv4 people detector using Darknet and the CrowdHuman dataset. Table of c

JK Jung 118 Nov 10, 2022
YOLOv4-v3 Training Automation API for Linux

This repository allows you to get started with training a state-of-the-art Deep Learning model with little to no configuration needed! You provide your labeled dataset or label your dataset using our BMW-LabelTool-Lite and you can start the training right away and monitor it in many different ways like TensorBoard or a custom REST API and GUI. NoCode training with YOLOv4 and YOLOV3 has never been so easy.

BMW TechOffice MUNICH 626 Dec 31, 2022
Torchyolo - Yolov3 ve Yolov4 modellerin Pytorch uygulamasıdır

TORCHYOLO : Yolo Modellerin Pytorch Uygulaması Yapılacaklar: Yolov3 model.py ve

Kadir Nar 3 Aug 22, 2022
Train Yolov4 using NBX-Jobs

yolov4-trainer-nbox Train Yolov4 using NBX-Jobs. Use the powerfull functionality available in nbox-SDK repo to train a tiny-Yolo v4 model on Pascal VO

Yash Bonde 1 Jan 12, 2022
Example-custom-ml-block-keras - Custom Keras ML block example for Edge Impulse

Custom Keras ML block example for Edge Impulse This repository is an example on

Edge Impulse 8 Nov 2, 2022