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.

RuntimeError: Error reading network, when trying to run Yolo v3 object detection demo

Bralic__Ivan
初学者
4,923 次查看

I wanted to test Yolo v3 network on NCS2 using OpenVino toolkit.  I followed the tutorial on how to convert Yolo v3 model to the Intermediate Representation form found here . I cloned the suggested github repo and made the frozen model with given commands. Then I used the made frozen Tensorflow model (pb file) and turned it into IR form with the following command:

python3 /opt/intel/openvino/deployment_tools/model_optimizer/mo_tf.py --input_model ~/tensorflow-yolo-v3/frozen_darknet_yolov3_model.pb --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/yolo_v3.json --input_shape '(1, 416, 416, 3)' --data_type FP16

Model was successfully turned into IR form, xml and bin files were generated. To test the model I ran the object detection demo found here. I ran the following command:

python3 /opt/intel/openvino/inference_engine/samples/python_samples/object_detection_demo_yolov3_async/object_detection_demo_yolov3_async.py -i ~/tensorflow-yolo-v3/Test_video_for_Object_Detection.mp4 -m ~/tensorflow-yolo-v3/frozen_darknet_yolov3_model.xml -d MYRIAD

After running the command I got the error:

Traceback (most recent call last):
  File "/opt/intel/openvino/inference_engine/samples/python_samples/object_detection_demo_yolov3_async/object_detection_demo_yolov3_async.py", line 349, in <module>
    sys.exit(main() or 0)
  File "/opt/intel/openvino/inference_engine/samples/python_samples/object_detection_demo_yolov3_async/object_detection_demo_yolov3_async.py", line 175, in main
    net = IENetwork(model=model_xml, weights=model_bin)
  File "ie_api.pyx", line 271, in openvino.inference_engine.ie_api.IENetwork.__cinit__
RuntimeError: Error reading network: in Layer detector/darknet-53/Conv_1/Conv2D: trying to connect an edge to non existing output port: 2.1

I'm not sure why did this happen. Did I make a mistake in one of the steps or is the model incorrectly translated ? I would appreciate some advices.

0 项奖励
14 回复数
Shubha_R_Intel
4,922 次查看

Dear Ivan, 

Please use this as the documentation for Yolo v3 : 

yolo v3 openvino how to

But I believe it's probably similar to the doc you used.

It seems to me that you did everything correctly. Did this happen on OpenVino 2019 R1 ?

Thanks,

Shubha

0 项奖励
Bralic__Ivan
初学者
4,922 次查看

Hi Shubha,

I looked at the documentation link that you posted and steps given seem the same to me. Nevertheless, I ran everything again like it was described and I still got the same result. Also, yes, I'm using OpenVino 2019 R1, I didn't use or install any toolkits before this one.

Thanks,

Ivan

0 项奖励
Shubha_R_Intel
4,922 次查看

Dear Ivan, definitely I believe you. Let me reproduce this also. 

Thanks for your patience !

Shubha

0 项奖励
Shubha_R_Intel
4,922 次查看

Dear Ivan, 

I just now ran through the yolov3 mo tensorflow tutorial on 2019 R1 and did not have your problems. The following is the command I used to run the inference:

C:\Program Files (x86)\IntelSWTools\openvino\inference_engine\samples\python_samples\object_detection_demo_yolov3_async\python object_detection_demo_yolov3_sample_async.py -m c:\users\sdramani\Downloads\tensorflow-yolo-v3\frozen_darknet_yolov3_model.xml -i c:\users\sdramani\Downloads\sample-videos\person-bicycle-car-detection.mp4 -d MYRIAD

And the following is the command I used for MO (similar to yours):

C:\Program Files (x86)\IntelSWTools\openvino\inference_engine\samples\python_samples\object_detection_demo_yolov3_async\python "c:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo_tf.py" --input_model frozen_darknet_yolov3_model.pb --input_shape (1,416,416,3) --tensorflow_use_custom_operations_config yolo_v3_changed.json  --data_type FP16

I think the big difference is that you used yolo_v3.json straight up from C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\extensions\front\tf . I am using the json from PINTO, which looks like the below. Moral of the story, you cannot just use the yolo_v3.json from the above directory. As the documentation states, 

id and match_kind are parameters that you cannot change.

custom_attributes is a parameter that stores all the YOLOv3 specific attributes:

classes, coords, num, and mask are attributes that you should copy from the configuration file file that was used for model training. If you used DarkNet officially shared weights, you can use yolov3.cfg or yolov3-tiny.cfg configuration file from https://raw.githubusercontent.com/pjreddie/darknet/master/cfg. Replace the default values in custom_attributes with the parameters that follow the [yolo] title in the configuration file.

entry_points

[
  {
    "id": "TFYOLOV3",
    "match_kind": "general",
    "custom_attributes": {
      "classes": 80,
      "coords": 4,
      "num": 9,
      "mask": [3,4,5],
      "jitter":0.3,
      "ignore_thresh":0.7,
      "truth_thresh":1,
      "random":1,
      "anchors":[10,13,16,30,33,23,30,61,62,45,59,119,116,90,156,198,373,326],
      "entry_points": ["detector/yolo-v3/Reshape", "detector/yolo-v3/Reshape_4", "detector/yolo-v3/Reshape_8"]
    }
  }
]

Hope it helps. Thanks for using OpenVino !

Shubha

 

0 项奖励
Bralic__Ivan
初学者
4,922 次查看

Hi Shubha,

I actually found out that Tensorflow was the one that was causing issues! I had the newest 1.13 version installed and it apparently wasn't able to properly generate the frozen file from the Github repo which was made in an earlier version. I installed 1.12 version and everything worked fine. I believe it should be noted in the tutorials that Tensorflow version should be <= 1.12 from now on.

Anyways, thank you for your effort!

Ivan

0 项奖励
Shubha_R_Intel
4,922 次查看

Dearest Bralic, Ivan, 

Yep. OpenVino (Model Optimizer) today does not support Tensorflow 1.13 but it's in the pipeline. Glad you figured it out !

Thanks for using OpenVino !

Shubha

0 项奖励
Chou__Yvonne
初学者
4,922 次查看

Hi,

 I met some similar error here.

 

 I work on Ubuntu 16.04

 I download darknet yolov3-tiny model from: https://pjreddie.com/darknet/yolo/

 and I convert it to IR format by follow the steps of: http://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_YOLO_From_Tensorflow.html

I also uninstall Tensorflow 1.13 and install 1.12 version, but it still doesn't resolve the following error:

python3 object_detection_demo_yolov3_async
.py -i /home/convert/dog.jpg -m /home/convert/frozen_tiny_model.xml -d MYRIAD
[ INFO ] Loading network files:
    /home/convert/frozen_tiny_model.xml
    /home/convert/frozen_tiny_model.bin
Traceback (most recent call last):
  File "object_detection_demo_yolov3_async.py", line 349, in <module>
    sys.exit(main() or 0)
  File "object_detection_demo_yolov3_async.py", line 175, in main
    net = IENetwork(model=model_xml, weights=model_bin)
  File "ie_api.pyx", line 271, in openvino.inference_engine.ie_api.IENetwork.__cinit__
RuntimeError: Error reading network: in Layer detector/yolo-v3-tiny/pool2/MaxPool: trying to connect an edge to non existing output port: 2.1

 

0 项奖励
JesusE_Intel
主持人
4,922 次查看

Hi Yvonne,

I believe your model optimizer is not configured. You can figure the Tensorflow framework only or all three frameworks at the same time.

Navigate to <INSTALL_DIR>/deployment_tools/model_optimizer/install_prerequisites and run the following command:

install_prerequisites.sh (configure all three frameworks)

install_prerequisites_tf.sh (configure only Tensorflow)

Hope this helps!

 

Regards,

Jesus

0 项奖励
Chou__Yvonne
初学者
4,922 次查看

Thank you for replying

 

I pretty sure I had did the step you suggest

but I still run the command again > ./install_prerequisites.sh

and try to run object_detection_demo_yolov3_async.py

unfortunately, it still got same error

0 项奖励
JesusE_Intel
主持人
4,922 次查看

Hi Yvonne,

I was able to replicate and fix the exact same error with the following steps:

  1. Remove tensorflow: sudo pip3 uninstall tensorflow
  2. Install tensorflow 1.12.0: pip3 install tensorflow==1.12.0
  3. Convert the weights to pb file (important to have tf 1.12.0 installed at this point)
    • python3 convert_weights_pb.py --class_names coco.names --data_format NHWC --weights_file yolov3-tiny.weights --tiny
  4. Generate the IR
    • python3 mo_tf.py --input_model /path/to/yolo_v3_tiny.pb --tensorflow_use_custom_operations_config <your config file>.json --batch 1

If you continue to see the same issue, please provide me your json file and link to the weights file you are downloading.

Regards,

Jesus

0 项奖励
Dong__Jinxin
初学者
4,922 次查看

Hi JESUS E, 

I have the same problem, my tensorflow version is 1.12, but I still got this problem 

(OpenCv) C:\Users\hp\Documents\Intel\OpenVINO\inference_engine_samples_build\intel64\Release>object_detection_demo_yolov3_async.exe -i cam -m C:\Users\hp\Desktop\yolov3\frozen_darknet_yolov3_model2.xml


InferenceEngine:
        API version ............ 1.6
        Build .................. 23224
[ INFO ] Parsing input parameters
[ INFO ] Reading input
[ INFO ] Loading plugin

        API version ............ 1.6
        Build .................. 23224
        Description ....... MKLDNNPlugin
[ INFO ] Loading network files
[ WARN:0] terminating async callback
[ ERROR ] Error reading network: in Layer detector/darknet-53/Conv_1/Conv2D: trying to connect an edge to non existing output port: 2.1

 

 

0 项奖励
JesusE_Intel
主持人
4,922 次查看

Hi Jinxin,

 

Could you share the model, configuration file (.json) and model optimizer command you used to convert to IR? I would like to reproduce your issue on my end. 

 

Regards,

 

Jesus

0 项奖励
Hart__Kostas
初学者
4,922 次查看

Hi, 
I believe I have the same issue, when trying to run the object_detection_demo_yolov3_async.py example. I'm trying to test this on IOT-DevCloud.

[ INFO ] Loading network files:
        frozen_darknet_yolov3_model.xml
        frozen_darknet_yolov3_model.bin
Traceback (most recent call last):
  File "object_detection_demo_yolov3_async.py", line 349, in <module>
    sys.exit(main() or 0)
  File "object_detection_demo_yolov3_async.py", line 175, in main
    net = IENetwork(model=model_xml, weights=model_bin)
  File "ie_api.pyx", line 271, in openvino.inference_engine.ie_api.IENetwork.__cinit__
RuntimeError: Error reading network: in Layer detector/darknet-53/Conv_1/Conv2D: trying to connect an edge to non existing output port: 2.1

 

I am following these guides: 

  1. https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_YOLO_From_Tensorflow.html
  2. https://docs.openvinotoolkit.org/latest/_inference_engine_ie_bridges_python_sample_object_detection_demo_yolov3_async_README.html
  3. The json config for creating the IR models is the default one.

 

Could you please let me know if there is any workaround or update to this issue?
Many thanks,

Kostas

 

0 项奖励
TNguy219
初学者
4,922 次查看

i success run yolo3 (darknet) on nc2, please see here. Thanks to Intel & the forum.

https://forums.intel.com/s/question/0D50P00004bYSyUSAW/how-quickly-convert-a-model-py-to-a-graph-and-upload-to-ncs2?language=en_US

/tuan

0 项奖励
回复