openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.08k stars 2.22k forks source link

Model Optimizer cannot produce .bin and .xml for YOLOV3 ? #1516

Closed jediofgever closed 4 years ago

jediofgever commented 4 years ago

I convert yolo_v3.weights to yolov3.pb with https://github.com/jinyu121/DW2TF

and then I try to run model optimizer with ;

 source /opt/intel/openvino/bin/setupvars.sh 
 sudo python3 mo_tf.py --input_model /home/atas/staubli_ws/ws_py3_nn/src/ROS_NNs_FANUC_LRMATE200ID/DW2TF/data/yolov3.pb --tensorflow_use_custom_operations_config  extensions/front/tf/yolo_ --batch 1

I get error indicating ;

[ ERROR ]  'Graph' object has no attribute 'node'
Cannot pre-process TensorFlow graph after reading from model file "/home/atas/staubli_ws/ws_py3_nn/src/ROS_NNs_FANUC_LRMATE200ID/DW2TF/data/yolov3.pb". File is corrupt or has unsupported format. Details: 'Graph' object has no attribute 'node'. 
 For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question openvinotoolkit/open_model_zoo#44. 

My openVINO version is 2019_R3

why I am having this problem

jgespino commented 4 years ago

Hi @jediofgever

Have you tried following the OpenVINO documentation for converting YOLO models to IR? Also, I recommend upgrading your OpenVINO toolkit to the latest 2020.4 release as 2019 R3 is quite old.

Regards, Jesus

jediofgever commented 4 years ago

Hi @jgespino ,

thanks for your answer. I upgraded the version 2020.4 release. It gave another error related to;

Originally, YOLOv3 model includes feature extractor called Darknet-53 with three branches at the end that make detections at three different scales. These branches must end with the YOLO Region layer.

Region layer was first introduced in the DarkNet framework. Other frameworks, including TensorFlow, do not have the Region implemented as a single layer, so every author of public YOLOv3 model creates it using simple layers. This badly affects performance. For this reason, the main idea of YOLOv3 model conversion to IR is to cut off these custom Region-like parts of the model and complete the model with the Region layers where required.

the quote is taken form the tutorial you linked. I used https://github.com/jinyu121/DW2TF to get .pb of pretrained YOLO weights.

The exact error I get is;

[ ERROR ] Exception occurred during running replacer "TFYOLOV3" (<class 'extensions.front.YOLO.YoloV3RegionAddon'>): TensorFlow YOLO V3 conversion mechanism was enabled. Entry points "detector/yolo-v3/Reshape, detector/yolo-v3/Reshape_4, detector/yolo-v3/Reshape_8" were provided in the configuration file. Entry points are nodes that feed YOLO Region layers. Node with name detector/yolo-v3/Reshape doesn't exist in the graph. Refer to documentation about converting YOLO models for more information.

But when I use https://github.com/mystic123/tensorflow-yolo-v3 to obtain .pb , it worked as expected.

Do you know what is the cause ? ,

jgespino commented 4 years ago

Hi @jediofgever

Glad that worked for you!

I used Netron to visualize the models frozen by both repos and they do look different. I could not find detector/yolo-v3/Reshape in the model from frozen with jinyu121/DW2TF. These layers are expected as specified in the configuration file (yolo_v3.json).

Regards, Jesus

Ludwig-Zh commented 4 years ago

Hi @jediofgever

Glad that worked for you!

I used Netron to visualize the models frozen by both repos and they do look different. I could not find detector/yolo-v3/Reshape in the model from frozen with jinyu121/DW2TF. These layers are expected as specified in the configuration file (yolo_v3.json).

Regards, Jesus

Hi,@jgespino

I am in a similar situation. So if I get a new implement of YOLOv3, how to set the "entry_points" in json file? I inspect the .pb file of the offical implement and public implement by NETRON, they are so different.

thx a lot.

TNTWEN commented 4 years ago

@jediofgever @Ludwig-Zh please follow https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_YOLO_From_Tensorflow.html OpenVINO yolo has restrictions on the namespace of the model,and the tensorflow converter must use Ops OpenVINO supports . Openvino inference engine don't support YOLO layer,so we should set entry_points(namespace of YOLO layer) let the program know where to stop the inference engine,and use self-defined YOLOlayer code in the Openvino-yolo-demo to continue the inference So if you want to convert Yolov3darknet ->tensorflow->OpenVINO, you must use https://github.com/mystic123/tensorflow-yolo-v3 as your tensorflow converter . You could also try my unofficial Openvino yolov4 converter:https://github.com/TNTWEN/OpenVINO-YOLOV4

jgespino commented 4 years ago

@TNTWEN Thanks! @Ludwig-Zh Please let us know if TNTWEN's comment helps!

jgespino commented 4 years ago

Closing issue, feel free to re-open or start a new issue.