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.

Tiny yolo v4 IR model conversion errors

Pranathi
Beginner
649 Views
Hi there, I recently got a intel Neural compute stick and I plan on running a custom yolo v4 model for object detection of 4 classes on my custom dataset. I used darknet to generate this model and tested it using darknet on both validation and other unseen data by the model and both work well. So, I am trying now to convert that .weights file obtained from darknet to .pb file and then to IR model. For the .pb file I used below repo
https://github.com/TNTWEN/OpenVINO-YOLOV4

For weights conversion, I used the below command and I got a protobuf file with no errors
```python3 convert_weights_pb.py --class_names obj.names --weights_file yolov4-tiny-obj_best.weights ---data_format NHWC --tiny```

After that, I am trying to use the most recent openvino version 2021.4 python3.7 and tensorflow 1.15.5 and below command to convert the so obtained pb file, frozen_darknet_yolov4_model.pb

```mo_tf.py --input_model ./OpenVINO-YOLOV4/frozen_darknet_yolov4_model.pb --transformations_config ./OpenVINO-YOLOV4/yolo_v4_tiny.json --reverse_input_channels '--input_shape=[1,416,416, 3]' --data_type=FP32 --log_level=DEBUG```

Could you please help with the error below?
Below is my error traceback with debug enabled
```
[ 2022-01-24 21:38:39,388 ] [ DEBUG ] [ infer:116 ] --------------------
[ 2022-01-24 21:38:39,388 ] [ DEBUG ] [ infer:117 ] Partial infer for detector/yolo-v4-tiny/Pad_1
[ 2022-01-24 21:38:39,388 ] [ DEBUG ] [ infer:118 ] Op: Pad
[ 2022-01-24 21:38:39,388 ] [ DEBUG ] [ infer:119 ] Inputs:
[ 2022-01-24 21:38:39,389 ] [ DEBUG ] [ infer:19 ] input[0]: shape = [ 1 32 208 208], value = <UNKNOWN>
[ 2022-01-24 21:38:39,389 ] [ DEBUG ] [ infer:19 ] input[1]: shape = [4], value = [0 0 1 1]
[ 2022-01-24 21:38:39,389 ] [ DEBUG ] [ infer:19 ] input[2]: shape = [4], value = [0 0 1 1]
[ 2022-01-24 21:38:39,390 ] [ DEBUG ] [ infer:132 ] Outputs:
[ 2022-01-24 21:38:39,391 ] [ DEBUG ] [ infer:19 ] output[0]: shape = [ 1 32 210 210], value = <UNKNOWN>
[ 2022-01-24 21:38:39,391 ] [ DEBUG ] [ infer:116 ] --------------------
[ 2022-01-24 21:38:39,391 ] [ DEBUG ] [ infer:117 ] Partial infer for detector/yolo-v4-tiny/Tile/YoloRegion
[ 2022-01-24 21:38:39,391 ] [ DEBUG ] [ infer:118 ] Op: RegionYolo
[ 2022-01-24 21:38:39,391 ] [ DEBUG ] [ infer:119 ] Inputs:
[ 2022-01-24 21:38:39,392 ] [ DEBUG ] [ infer:19 ] input[0]: shape = [169 6], value = [[ 0. 0. 0. 0. 0. 0.]
[ 1. 0. 1. 0. 1. 0.]
[ 2. 0. 2. 0. 2. 0.]
...
[10. 12. 1...
[ ERROR ] Cannot infer shapes or values for node "detector/yolo-v4-tiny/Tile/YoloRegion".
[ ERROR ] index 2 is out of bounds for axis 0 with size 2
[ ERROR ]
[ ERROR ] It can happen due to bug in custom shape infer function <function RegionYoloOp.regionyolo_infer at 0x7fc843ca8830>.
[ ERROR ] Or because the node inputs have incorrect values/shapes.
[ ERROR ] Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
[ 2022-01-24 21:38:39,393 ] [ DEBUG ] [ infer:184 ] Node "detector/yolo-v4-tiny/Tile/YoloRegion" attributes: {'kind': 'op', 'type': 'RegionYolo', 'op': 'RegionYolo', 'version': 'opset1', 'in_ports_count': 1, 'out_ports_count': 1, 'infer': <function RegionYoloOp.regionyolo_infer at 0x7fc843ca8830>, 'name': 'detector/yolo-v4-tiny/Tile/YoloRegion', 'axis': 1, 'end_axis': 1, 'do_softmax': 0, 'classes': 4, 'anchors': [10, 14, 23, 27, 37, 58, 81, 82, 135, 169, 344, 319], 'coords': 4, 'num': 6, 'entry_points': ['detector/yolo-v4-tiny/Reshape', 'detector/yolo-v4-tiny/Reshape_4'], 'mask': [0, 1, 2], 'dim_attrs': ['channel_dims', 'spatial_dims', 'batch_dims'], 'shape_attrs': ['window', 'stride', 'shape', 'output_shape', 'pad'], 'IE': [('layer', [('id', <function Op.substitute_ie_attrs.<locals>.<lambda> at 0x7fc82db1b050>), 'name', 'type', 'version'], [('data', ['coords', 'classes', 'num', 'axis', 'end_axis', ('do_softmax', <function RegionYoloOp.backend_attrs.<locals>.<lambda> at 0x7fc82db1b0e0>), ('anchors', <function RegionYoloOp.backend_attrs.<locals>.<lambda> at 0x7fc82db1b170>), ('mask', <function RegionYoloOp.backend_attrs.<locals>.<lambda> at 0x7fc82db1b200>)], []), '@ports', '@consts'])], '_in_ports': {0: {}}, '_out_ports': {0: {}}, 'is_output_reachable': True, 'is_undead': False, 'is_const_producer': False, 'is_partial_inferred': False}
[ ERROR ] Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.middle.PartialInfer.PartialInfer'>): Stopped shape/value propagation at "detector/yolo-v4-tiny/Tile/YoloRegion" node.
For more information please refer to Model Optimizer FAQ, question #38. (https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html?question=38#question-38)
[ 2022-01-24 21:38:39,400 ] [ DEBUG ] [ main:410 ] Traceback (most recent call last):
File "/opt/intel/openvino_2021/deployment_tools/model_optimizer/mo/middle/passes/infer.py", line 122, in partial_infer
node.infer(node)
File "/opt/intel/openvino_2021/deployment_tools/model_optimizer/extensions/ops/regionyolo.py", line 71, in regionyolo_infer
width=input_shape[get_width_dim(layout, 4)])
IndexError: index 2 is out of bounds for axis 0 with size 2
```

Thanks!
Labels (1)
0 Kudos
2 Replies
Peh_Intel
Moderator
608 Views

Hi Pranathi,


Thanks for reaching out to us.


For your information, we have yolo-v4-tiny-tf in Open Model Zoo and it is implemented in Keras framework and then converted to TensorFlow and IR.


Please try convert your weights file and cgf file into Keras model and then to TensorFlow model according to repository below:

https://github.com/david8862/keras-YOLOv3-model-set


Convert from weights and cgf files to Keras model (.h5):

python3 keras-YOLOv3-model-set/tools/model_converter/convert.py <config_path>.cfg <weight_path>.weights <output_path>.h5


Convert from Keras model to TensorFlow model (.pb):

python3 keras-YOLOv3-model-set/tools/model_converter/keras_to_tensorflow.py --input_model <path>.h5 --output_model <output-path>.pb

 

Convert from TensorFlow model to Intermediate Representation (IR):

python3 mo_tf.py --input_model <model>.pb --reverse_input_channels --input_shape=[1,416,416, 3] --data_type=FP32



We would like to request your weights and cfg files if this method doesn’t helpful for you.



Regards,

Peh


0 Kudos
Munesh_Intel
Moderator
575 Views

Hi Pranathi,

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,

Munesh

 

0 Kudos
Reply