Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6392 Discussions

Not able to convert yolov4 model to tensorflow format

vk_007
Beginner
1,484 Views

I am following openvino documentation for converting YoloV4 model to IR. In the process given, the 3rd step is that where i am getting error while loading yolov4 darknet model. I am using YoloV4 darknet custom model to do tensorflow conversion.

Pl explain me how to properly execute the 3rd step of the process ?

 

Here is a link to docs content : https://docs.openvino.ai/latest/openvino_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_YOLO_From_Tensorflow.html

0 Kudos
6 Replies
IntelSupport
Community Manager
1,448 Views

Hi Vk_007,

Thanks for reaching out.

Would you share the error that you see? Are you getting errors when running the converter.py script? Please share your models and all the relevant files(.weights file,.cfg file,.h5) for us to test it on our end.

 

Regards,

Aznie


0 Kudos
vk_007
Beginner
1,438 Views

Hi @IntelSupport , thanks for the response,

I am actually getting error while converting my yolov4 darknet model to keras format. 

Error is "TypeError: buffer is too small for requested array"
Here is a screenshot of error:

vk_007_0-1637126820843.png



I am using this github repo to convert yolov4 darknet to keras format which is given in the steps of docs.
Github repo link : https://github.com/Ma-Dan/keras-yolo4 


And where should i share weights & cfg files?




0 Kudos
IntelSupport
Community Manager
1,427 Views

Hi Vk_001,

The error is caused by the mismatch between the config file and weights file. I have tried the same workaround and got the same error as you.

 

To solve that, I just skip the convert.py step and download the yolov4_weight.h5 file directly from this repository:

https://github.com/bubbliiiing/yolov4-keras/releases/

 

The yolov4.weight file you can get from the repo before at their first step. Then, proceed to run the converter.py with some code editing as below:

 

from yolo4.model import Mish

import tensorflow as tf

 

model = tf.keras.models.load_model('yolo4_weight.h5', custom_objects={'Mish': Mish})

 

tf.saved_model.save(model, 'yolov4')

 

Make sure the weights file,.h5 file and converter.py are in the same folder(Keras-yolo4). After running converter.py, a saved_model_dir (assets, variables,saved_model.pb) is generated and successfully converts to Intermediate Representation(IR) of OpenVINO.

 

Command to convert .pb into IR format:

python mo.py --saved_model_dir yolov4 --input_shape [1,608,608,3] --output_dir yolov4

 

Regards,

Aznie


0 Kudos
vk_007
Beginner
1,424 Views

Hi @IntelSupport ,

 

FYI, I am using custom Yolov4 darknet weights file, Then how can i generate it in .h5 format ?

0 Kudos
IntelSupport
Community Manager
1,402 Views

Hi VK_001,

It seems like there is a missing python module from the script in the repository. There are many users who encountered the same error:

https://github.com/Ma-Dan/keras-yolo4/issues/21

 

Unfortunately, the repository is out of our control. However, there are some folks that able to get the .pb file using this link: git clone  https://github.com/Runist/YOLOv4/ 

Then, save the code below to the converter.py file in the same folder of your yolov4.weights and run it to get the .pb file.

 

from keras-yolo4.model import Mish

 

model = tf.keras.models.load_model('yolo4_weight.h5', custom_objects={'Mish': Mish})

tf.saved_model.save(model, 'yolov4')

 

I hope this will help you.

 

Regards,

Aznie

 

0 Kudos
IntelSupport
Community Manager
1,345 Views

Hi VK_007,

This thread will no longer be monitored since we have provided a solution. If you need any additional information from Intel, please submit a new question.


Regards,

Aznie


0 Kudos
Reply