Intel® Distribution of OpenVINO™ Toolkit
Community support and discussions about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all things computer vision-related on Intel® platforms.

Converting Public Model yolo-v4-tf to IR

at93
Beginner
1,198 Views

Hi Everyone,

I've just downloaded the Intel public model yolo-v4-tf. Can someone explain to me how to convert the darknet weights/cfg file to IR.  I've seen the scripts included in the download but not familiar to keras.

Thanks.

0 Kudos
13 Replies
at93
Beginner
1,184 Views

I am able to convert the darknet weights/cfg to keras file using the convert.py script. However, when I tried to convert from keras to tensorflow using the keras_to_tensorflow.py, I am getting the following errors:

C:\Users\MeAtPlay\Documents\Intel\public\yolo-v4-tf\keras-YOLOv3-model-set\tools\model_converter>python keras_to_tensorflow.py --input_model="C:\Users\MeAtPlay\Documents\Intel\public\yolo-v4-tf\yolov4.h5" --output_model="C:\Users\MeAtPlay\Documents\Intel\public\yolo-v4-tf\yolov4.pb"
WARNING:tensorflow:From C:\Users\MeAtPlay\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\compat\v2_compat.py:68: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
Traceback (most recent call last):
File "keras_to_tensorflow.py", line 188, in <module>
app.run(main)
File "C:\Users\MeAtPlay\AppData\Roaming\Python\Python36\site-packages\absl\app.py", line 303, in run
_run_main(main, args)
File "C:\Users\MeAtPlay\AppData\Roaming\Python\Python36\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "keras_to_tensorflow.py", line 134, in main
model = load_input_model(FLAGS.input_model, FLAGS.input_model_json, FLAGS.input_model_yaml, custom_objects=custom_object_dict)
File "keras_to_tensorflow.py", line 67, in load_input_model
model = load_model(input_model_path, custom_objects=custom_objects)
File "C:\Users\MeAtPlay\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\keras\saving\save.py", line 143, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Users\MeAtPlay\AppData\Roaming\Python\Python36\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 160, in load_model_from_hdf5
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

at93
Beginner
1,174 Views

I am able to fix the error "AttributeError: 'str' object has no attribute 'decode'" by downgrading h5py package to 2.10.0.

So now that I have the frozen TF, how do I use the model optimzer to convert it to IR. The yolov4.json file is not included in the models zoo? Any help is appreciated.

Adli
Moderator
1,153 Views

Hi at93,

 

Thank you for reaching out to us. Please try and run the following command:

python "<openvino_dir>\deployment_tools\model_optimizer\mo.py" --framework=tf --data_type=FP32 --output_dir=<output_dir> --model_name=yolo-v4-tf --input_shape=[1,608,608,3] --input=image_input --scale_values=image_input[255] --reverse_input_channels --input_model="<frozen_file_directory>\<frozen_file_name>.pb"

 

Besides, you can run the following command to convert public model 'yolo-v4-tf' into the IR model:

python converter.py --name yolo-v4-tf

 

Regards,

Adli

 

at93
Beginner
1,144 Views

Thanks Adli,

I was able to convert using

python converter.py --name yolo-v4-tf

 However, when I run the object_detection_demo it does not seems to like the model file. The following is the output of the program.

C:\Users\MeAtPlay\Documents\Intel\OpenVINO\omz_demos_build\intel64\Release>object_detection_demo -at "yolo" -m "C:\DVCell\Common64\models\yolo-v4-tf.xml" -i "C:\DVCell\Common64\Media\WaikikiBeach.mp4" -d "GPU"
[ INFO ] InferenceEngine: API version ......... 2.1
Build ........... 2021.2.0-1877-176bdf51370-releases/2021/2
[ INFO ] Parsing input parameters
[ INFO ] Reading input
MFX: Can't initialize session
[ INFO ] Loading Inference Engine
[ INFO ] Device info:
[ INFO ] GPU
clDNNPlugin version ......... 2.1
Build ........... 2021.2.0-1877-176bdf51370-releases/2021/2
Loading network files
[ INFO ] Batch size is forced to 1.
[ INFO ] Checking that the inputs are as the demo expects
[ INFO ] Checking that the outputs are as the demo expects
[ ERROR ] [ ERROR ] Invalid output type: Add. RegionYolo expected

at93
Beginner
1,141 Views

In addition, I tried the object_detection_demo again with yolov3 model and it worked.

Adli
Moderator
1,113 Views

Hi at93,

 

If possible, could you run the 'object_detection_demo.py' with the 'yolo-v4-tf' IR model? The demo is located in 'python_demos\object_detection_demo' directory. 

 

Regards,

Adli

 

at93
Beginner
1,108 Views

Hi Adli,

The tried the 'object_detection_demo.py' with the 'yolo-v4-tf' IR model. It does run without errors BUT I don't think it inferred properly. The bounding boxes are everywhere as you can see in the image here. 

yolo4_test.png

at93
Beginner
1,107 Views

I also tried the same python script with the Yolo3 model and it is OK. Please see image below.

yolo3_test.png

Adli
Moderator
1,078 Views

Hi at93,


Thank you for your prompt response. We are investigating this issue and will get back to you soon.


Regards,

Adli


Adli
Moderator
1,036 Views

Hi at93,

 

The object detection demo (python) has not been updated to support 'yolo-v4-tf' yet. The supported models for this demo can be found on the 'models.lst' file:

https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/python_demos/object_detection_de...

 

I apologize for the inconvenience.

 

Regards,

Adli


at93
Beginner
1,029 Views

Thank Adli,

Are there other sample code or documentation on how to use the Openvino2021.2 library to infer the yolov4 model or I have to wait till 2021.3 version?

Thanks.

Vladimir_Dudnik
Employee
1,008 Views

You can run accuracy validation for yolo-v4-tf model using Open Model Zoo Accuracy Checker tool (you'll also need MSCOCO validation dataset for that.

Adli
Moderator
964 Views

Hi at93,

 

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,

Adli


Reply