PINTO0309 / openvino2tensorflow

This script converts the ONNX/OpenVINO IR model to Tensorflow's saved_model, tflite, h5, tfjs, tftrt(TensorRT), CoreML, EdgeTPU, ONNX and pb. PyTorch (NCHW) -> ONNX (NCHW) -> OpenVINO (NCHW) -> openvino2tensorflow -> Tensorflow/Keras (NHWC/NCHW) -> TFLite (NHWC/NCHW). And the conversion from .pb to saved_model and from saved_model to .pb and from .pb to .tflite and saved_model to .tflite and saved_model to onnx. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support.
MIT License
338 stars 40 forks source link

Trouble Converting vehicle-license-plate-detection-barrier-0106 Model #52

Closed hesamsheikh closed 3 years ago

hesamsheikh commented 3 years ago

UBUNTU 18 TensorFlow v2.4.1 OpenVINO 2021.4

I want to convert the open model zoo , vehicle-license-plate-detection-barrier-0106 into saved_model format, Using the following command: python3 openvino2tensorflow.py --model_path /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/intel/vehicle-license-plate-detection-barrier-0106/FP16/vehicle-license-plate-detection-barrier-0106.xml --model_output_path /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/intel/vehicle-license-plate-detection-barrier-0106/FP16/weights --output_saved_model

But I recieve this log: ===== ERROR: Cannot convert 2147483647.0 to EagerTensor of dtype int64 ERROR: model_path : /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/intel/vehicle-license-plate-detection-barrier-0106/FP16/vehicle-license-plate-detection-barrier-0106.xml ERROR: weights_path: /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/intel/vehicle-license-plate-detection-barrier-0106/FP16/vehicle-license-plate-detection-barrier-0106.bin ERROR: layer_id : 405 ERROR: input_layer0 layer_id=404: tf.Tensor([3], shape=(1,), dtype=int64) ERROR: The trace log is below. Traceback (most recent call last): File "openvino2tensorflow.py", line 555, in convert clip_value_max=cmax File "/home/hessam/.local/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper return target(*args, **kwargs) File "/home/hessam/.local/lib/python3.6/site-packages/tensorflow/python/ops/clip_ops.py", line 111, in clip_by_value t_min = math_ops.minimum(values, clip_value_max) File "/home/hessam/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 5929, in minimum _ctx, "Minimum", name, x, y) TypeError: Cannot convert 2147483647.0 to EagerTensor of dtype int64

How can I see the weights of this layer and is there a way to convert this model into saved_model?

PINTO0309 commented 3 years ago

Clamp bugs have been fixed and released. f03d58074bca4da333fa5b812dac71ba683c74ad However, the last DetectionOutput cannot be converted to TensorFlow, so it is necessary to delete the layer and implement post-processing programmatically. https://github.com/PINTO0309/openvino2tensorflow/releases/tag/v1.15.4

hesamsheikh commented 3 years ago

Clamp bugs have been fixed and released. f03d580 However, the last DetectionOutput cannot be converted to TensorFlow, so it is necessary to delete the layer and implement post-processing programmatically. https://github.com/PINTO0309/openvino2tensorflow/releases/tag/v1.15.4

How can I exactly delete that layer and implement it later? @PINTO0309

PINTO0309 commented 3 years ago

XML Edit. Screenshot 2021-08-03 14:14:29

Delete.

        <layer id="421" name="DetectionOutput_" type="DetectionOutput" version="opset1">
            <data background_label_id="0" clip_after_nms="false" clip_before_nms="false" code_type="caffe.PriorBoxParameter.CENTER_SIZE" confidence_threshold="0.0099999997764825821" decrease_label_id="false" input_height="1" input_width="1" keep_top_k="200" nms_threshold="0.44999998807907104" normalized="true" num_classes="3" objectness_score="0" share_location="true" top_k="400" variance_encoded_in_target="false"/>
            <input>
                <port id="0" precision="FP32">
                    <dim>1</dim>
                    <dim>4504</dim>
                </port>
                <port id="1" precision="FP32">
                    <dim>1</dim>
                    <dim>3378</dim>
                </port>
                <port id="2" precision="FP32">
                    <dim>1</dim>
                    <dim>2</dim>
                    <dim>4504</dim>
                </port>
            </input>
            <output>
                <port id="3" precision="FP32">
                    <dim>1</dim>
                    <dim>1</dim>
                    <dim>200</dim>
                    <dim>7</dim>
                </port>
            </output>
        </layer>

Edit.

        <edge from-layer="345" from-port="0" to-layer="346" to-port="1"/>
        <edge from-layer="346" from-port="2" to-layer="421" to-port="0"/>
        <edge from-layer="347" from-port="0" to-layer="348" to-port="1"/>

Edit.

        <edge from-layer="418" from-port="0" to-layer="419" to-port="1"/>
        <edge from-layer="419" from-port="2" to-layer="421" to-port="1"/>
        <edge from-layer="420" from-port="0" to-layer="421" to-port="2"/>
        <edge from-layer="421" from-port="3" to-layer="422" to-port="0"/>
hesamsheikh commented 3 years ago

Thank you very much for the thorough answer, But I'm new to the program and still have difficulty. Could you maybe provide the saved_model format? If not, how can I implement those deleted layers later and also, to what should I edit those edges? @PINTO0309

PINTO0309 commented 3 years ago

Edit it like this. Do a Diff yourself to see what has changed before and after the modification.

hesamsheikh commented 3 years ago

Thank you for the effort, Though now I get this error: python3 openvino2tensorflow.py --output_saved_model --model_path /home/hessam/Downloads/Compressed/openvino2tensorflow-1.15.4/models/vehicle-license-plate-detection-barrier-0106.xml --model_output_path /home/hessam/Downloads/Compressed/openvino2tensorflow-1.15.4/models/vehicle-license-plate-detection-barrier-0106-CONVERTED TensorFlow/Keras model building process starts ====================================== Segmentation fault (core dumped)