Search code examples
tensorflowmachine-learningkerasdeep-learningyolo

How to load darknet YOLOv3 model from .cfg file and weights from .weights file, and save the model with the weights to a .h5 file?


I have downloaded the .weights and .cfg file for YOLOv3 from darknet (link: https://pjreddie.com/darknet/yolo/) I want to create a model and assign the weights from these files, and I want to save the model with the assigned weights to a .h5 file so that I can load the .h5 model into Keras by using keras.models.load_model().

Please help.


Solution

  • You should check the instructions given in this repository. This is basically the keras implementation of YOLOv3 (Tensorflow backend).

    • Download YOLOv3 weights from YOLO website.
    • Convert the Darknet YOLO model to a Keras model.

      python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

    As you have already downloaded the weights and configuration file, you can skip the first step. Download the convert.py script from repository and simply run the above command.

    Note: Above command assumes that yolov3.cfg, yolov3.weights and model_data(folder) are present at the same path as convert.py.