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
334 stars 40 forks source link

Number of output channels in GroupConvolution does not match. #111

Closed taisuke-tomida closed 2 years ago

taisuke-tomida commented 2 years ago

Issue Type

Bug

OS

Windows

OS architecture

x86_64

Programming Language

Python

Framework

PyTorch

Download URL for ONNX / OpenVINO IR

ONNX (onnxsimplifier done)

https://drive.google.com/file/d/19ZkP4gJTx8DXBEFBOUuqYYV5jw3mOg_8/view?usp=sharing

OpenVINO IR

https://drive.google.com/file/d/1KHg0mu64E-1mLBFTFPgZ__67N2_ueIf2/view?usp=sharing

Convert Script

python openvino2tensorflow.py --model_path model_512x1024_opt.xml --model_output_path model --output_saved_model --output_no_quant_float32_tflite --output_integer_quant_tflite

Description

GroupConv Add
image image

current

GroupConvolution is determined to be DepthWiseConvolution, and the number of input channels has become the number of output channels.

* channel first
input: [1, 512, 16, 32] 
output: [1, 512, 16, 32]

Then, the number of dimensions do not match in the Add immediately following, resulting in an error.

expected

Ideally, the number of output channels should be halved.

Relevant Log Output

layer_type: GroupConvolution
layer_id: 108
input_layer0: layer_id=106: KerasTensor(type_spec=TensorSpec(shape=(1, 16, 32, 512), dtype=tf.float32, name=None), name='tf.nn.relu_16/Relu:0', description="created by layer 'tf.nn.relu_16'")
input_layer1_value: layer_id=107: [[[[[ 5.78115918e-02 -5.86267188e-02  5.82272224e-02]
    [-3.34660895e-02 -1.84129700e-02  1.08070463e-01]
    [-6.32756799e-02 -1.90970674e-01  2.26492267e-02]]

   [[ 9.20016021e-02  1.72179997e-01  1.05837926e-01]
    [-1.18273929e-01  1.88021347e-01  2.33806986e-02]
    [-1.24895409e-01  2.87319213e-01  1.12432733e-01]]]]

 [[[[-4.27430379e-04 -1.22101836e-01 -7.03499094e-02]
    [-7.52401277e-02 -6.63675368e-02  1.46620110e-01]
    [ 9.17513482e-03 -6.09947965e-02 -5.20268790e-02]]

   [[ 1.92317143e-02  4.32067737e-02 -2.76048779e-02]
    [ 2.01334372e-01 -2.78373539e-01  9.90405157e-02]
    [ 7.02429488e-02 -2.46007547e-01  1.26832023e-01]]]]

 [[[[-7.18617521e-04  1.26475552e-02  6.83869869e-02]
    [-7.36376829e-03  3.53444666e-02 -5.20217381e-02]
    [ 1.10248789e-01  4.43329923e-02 -1.59389656e-02]]

   [[-7.74969580e-03 -1.87172860e-01 -4.31384258e-02]
    [ 2.48163193e-01 -2.13454086e-02 -4.78425100e-02]
    [-3.54977418e-03  1.71056464e-01  1.16566658e-01]]]]

 ...

 [[[[ 3.50890458e-02 -2.44060028e-02  1.02666235e-02]
    [ 1.30802959e-01  1.35804072e-01  3.27628553e-02]
    [-1.49747813e-02  2.66026258e-01 -1.27368048e-01]]

   [[-6.99182553e-03 -7.67629743e-02  4.31379937e-02]
    [-6.24476522e-02 -6.03465475e-02 -2.23146230e-02]
    [-3.39862406e-02 -8.86445642e-02 -6.15392625e-02]]]]

 [[[[-4.58377460e-03  6.69926405e-02 -6.25393763e-02]
    [ 1.36094272e-01  1.81736369e-02  4.27139476e-02]
    [ 2.42245719e-02  8.89152214e-02  3.52703594e-02]]

   [[ 4.92761247e-02 -3.73030640e-02  7.80140534e-02]
    [ 7.06860125e-02 -6.88406825e-02  8.55734795e-02]
    [ 4.40815687e-02  1.10261098e-01  2.11622596e-01]]]]

 [[[[ 4.59359698e-02  3.23943198e-02  3.55403195e-03]
    [ 1.23861842e-02 -2.23860711e-01 -4.26258259e-02]
    [-1.53827686e-02 -8.38709921e-02 -7.42705092e-02]]

   [[ 5.75087443e-02  6.27591684e-02 -2.39009131e-02]
    [ 1.82988971e-01  2.15826333e-01  9.38080028e-02]
    [ 2.22801305e-02 -4.90545481e-02  2.64492410e-04]]]]]
tf_layers_dict: KerasTensor(type_spec=TensorSpec(shape=(1, 16, 32, 512), dtype=tf.float32, name=None), name='depthwise_conv2d/depthwise:0', description="created by layer 'depthwise_conv2d'")
====================================================================================
layer_type: Const
layer_id: 109
tf_layers_dict_shape: (1, 256, 1, 1)
tf_layers_dict_value: [[[[-4.38051105e-01]]

  [[ 2.19055846e-01]]

  [[-2.88665384e-01]]

  [[ 1.35780396e-02]]

  [[ 1.58109516e-01]]

  [[-2.38887161e-01]]

  [[-3.42952102e-01]]

  [[-1.97811365e-01]]

  [[ 2.38079950e-01]]

  [[-3.00383717e-01]]

  [[-3.79415274e-01]]

  [[-1.30230410e-03]]

  [[-1.75636202e-01]]

  [[ 2.26872861e-01]]

  [[ 1.61576495e-01]]

  [[-8.61738101e-02]]

  [[-1.76845565e-01]]

  [[-1.94701985e-01]]

  [[-4.46325362e-01]]

  [[ 7.12524429e-02]]

  [[-2.90709227e-01]]

  [[ 1.70214891e-01]]

  [[ 1.17164202e-01]]

  [[-5.50653219e-01]]

  [[-3.44480097e-01]]

  [[ 1.54580593e-01]]

  [[-4.62583065e-01]]

  [[-3.79618764e-01]]

  [[-5.28968692e-01]]

  [[ 1.48000792e-01]]

  [[-4.25233126e-01]]

  [[-5.78302564e-03]]

  [[ 4.97293532e-01]]

  [[-2.00315788e-01]]

  [[-2.70368993e-01]]

  [[-1.45630240e-01]]

  [[-3.06725234e-01]]

  [[-1.06576309e-01]]

  [[-5.27214468e-01]]

  [[-2.85305828e-01]]

  [[ 9.04806107e-02]]

  [[ 2.00983182e-01]]

  [[-2.48428807e-01]]

  [[-2.66157866e-01]]

  [[ 3.93011749e-01]]

  [[ 3.31952661e-01]]

  [[ 1.65964812e-01]]

  [[-3.65517437e-02]]

  [[-2.23674193e-01]]

  [[-1.38646007e-01]]

  [[-1.49682820e-01]]

  [[-5.39370663e-02]]

  [[-2.81081557e-01]]

  [[-3.71229798e-01]]

  [[-2.04612076e-01]]

  [[-4.88200150e-02]]

  [[-6.52738735e-02]]

  [[-2.77237803e-01]]

  [[-2.74392933e-01]]

  [[-3.74132484e-01]]

  [[-9.32027176e-02]]

  [[-1.05048992e-01]]

  [[ 7.36031681e-02]]

  [[-4.37566787e-01]]

  [[ 2.19656661e-01]]

  [[-9.63449180e-02]]

  [[-5.89542150e-01]]

  [[ 8.71993005e-02]]

  [[-3.21139693e-01]]

  [[-4.21330065e-01]]

  [[ 2.29825228e-01]]

  [[-1.44032342e-02]]

  [[-3.74841958e-01]]

  [[-2.06909880e-01]]

  [[-2.34280884e-01]]

  [[-4.43613082e-02]]

  [[-2.24455640e-01]]

  [[ 1.74495783e-02]]

  [[ 8.29243064e-02]]

  [[-2.51245260e-01]]

  [[-8.34130123e-02]]

  [[ 3.60969812e-01]]

  [[-1.46979559e-02]]

  [[ 1.50575653e-01]]

  [[-2.48566922e-02]]

  [[-8.55817273e-02]]

  [[-7.02287955e-03]]

  [[-7.66570717e-02]]

  [[-4.04711902e-01]]

  [[-4.68300402e-01]]

  [[ 1.78903379e-02]]

  [[-3.16399276e-01]]

  [[-2.55049784e-02]]

  [[ 2.18878463e-01]]

  [[-4.74276751e-01]]

  [[ 4.95921932e-02]]

  [[-1.73477843e-01]]

  [[ 4.13701385e-01]]

  [[-6.25796854e-01]]

  [[-3.44671279e-01]]

  [[-2.27541566e-01]]

  [[-3.50501478e-01]]

  [[ 2.52230585e-01]]

  [[-1.82993680e-01]]

  [[ 1.14594489e-01]]

  [[ 5.61434356e-03]]

  [[-5.73507607e-01]]

  [[-1.83091506e-01]]

  [[ 1.09156683e-01]]

  [[ 2.99489617e-01]]

  [[-1.85676917e-01]]

  [[ 2.21719816e-01]]

  [[-3.13707173e-01]]

  [[-1.75927639e-01]]

  [[ 1.51497126e-01]]

  [[-1.25913113e-01]]

  [[-8.85332406e-01]]

  [[ 4.08227965e-02]]

  [[ 3.19375843e-02]]

  [[-1.87790215e-01]]

  [[-1.93310797e-01]]

  [[ 1.42922431e-01]]

  [[-3.96301538e-01]]

  [[ 1.69964477e-01]]

  [[-7.10625276e-02]]

  [[ 2.91089825e-02]]

  [[-1.68964818e-01]]

  [[ 5.51550463e-02]]

  [[ 4.91583310e-02]]

  [[-1.18682615e-01]]

  [[-5.31681478e-02]]

  [[-3.94332737e-01]]

  [[ 6.95292130e-02]]

  [[ 6.71956167e-02]]

  [[ 8.91256630e-02]]

  [[ 1.14808865e-01]]

  [[-5.01706719e-01]]

  [[-3.63382578e-01]]

  [[ 3.79894814e-03]]

  [[ 1.54746577e-01]]

  [[ 3.78737658e-01]]

  [[-3.64347279e-01]]

  [[ 1.46473855e-01]]

  [[-4.55153048e-01]]

  [[ 2.04525799e-01]]

  [[ 5.11586666e-01]]

  [[ 4.96329784e-01]]

  [[-2.45105065e-02]]

  [[-2.30660811e-01]]

  [[-4.90913302e-01]]

  [[ 2.60759830e-01]]

  [[-4.44954708e-02]]

  [[-3.99450153e-01]]

  [[-8.48353468e-03]]

  [[-2.24783599e-01]]

  [[ 3.19117069e-01]]

  [[-5.61902404e-01]]

  [[-4.65537608e-01]]

  [[ 4.11207467e-01]]

  [[ 1.23415829e-03]]

  [[ 1.42598927e-01]]

  [[-4.55421180e-01]]

  [[-4.29093659e-01]]

  [[-1.12672053e-01]]

  [[-1.02961019e-01]]

  [[-3.07534128e-01]]

  [[-4.18100655e-01]]

  [[ 1.35619462e-01]]

  [[-1.75718442e-01]]

  [[ 4.07180702e-03]]

  [[-2.55745262e-01]]

  [[ 6.82368398e-01]]

  [[-5.71846485e-01]]

  [[ 8.79000057e-04]]

  [[-1.71738327e-01]]

  [[-1.93940818e-01]]

  [[ 4.17013675e-01]]

  [[-3.41771007e-01]]

  [[-2.27950871e-01]]

  [[-5.82421482e-01]]

  [[-3.99521552e-02]]

  [[ 2.29098141e-01]]

  [[-2.78866947e-01]]

  [[-1.96941346e-01]]

  [[ 1.34730920e-01]]

  [[-3.70289356e-01]]

  [[-2.36257151e-01]]

  [[-3.49029042e-02]]

  [[-2.88474977e-01]]

  [[ 1.61376312e-01]]

  [[ 2.76338644e-02]]

  [[-3.59379709e-01]]

  [[ 1.15561545e-01]]

  [[-4.37495977e-01]]

  [[ 1.33056743e-02]]

  [[-1.77574679e-01]]

  [[ 1.54249936e-01]]

  [[ 1.25672072e-01]]

  [[-2.02557713e-01]]

  [[-4.97245789e-02]]

  [[-9.80434790e-02]]

  [[-2.07663611e-01]]

  [[-6.10441387e-01]]

  [[-3.17488730e-01]]

  [[-4.49561357e-01]]

  [[-3.39648217e-01]]

  [[-1.02272294e-02]]

  [[-2.92957991e-01]]

  [[ 1.92538112e-01]]

  [[ 2.91599870e-01]]

  [[ 1.16419509e-01]]

  [[-2.50065565e-01]]

  [[-5.68220139e-01]]

  [[-1.33831337e-01]]

  [[ 5.69325015e-02]]

  [[ 1.74685955e-01]]

  [[ 7.30799884e-02]]

  [[-6.00246117e-02]]

  [[ 3.75379845e-02]]

  [[-3.16989660e-01]]

  [[ 6.29451752e-01]]

  [[ 6.13311157e-02]]

  [[-3.16312879e-01]]

  [[-1.87226444e-01]]

  [[ 1.77003190e-01]]

  [[-1.64150760e-01]]

  [[-6.45186305e-02]]

  [[-1.07377265e-02]]

  [[-4.87804204e-01]]

  [[ 1.33381620e-01]]

  [[-1.71609774e-01]]

  [[-3.14551771e-01]]

  [[ 1.56140909e-01]]

  [[-4.75827426e-01]]

  [[-4.09910798e-01]]

  [[ 3.04118961e-01]]

  [[-3.15654904e-01]]

  [[ 3.96565855e-01]]

  [[-7.73698539e-02]]

  [[-2.54265696e-01]]

  [[ 1.80844471e-01]]

  [[-3.48066419e-01]]

  [[-8.92103165e-02]]

  [[-2.96039492e-01]]

  [[ 1.86911583e-01]]

  [[ 1.55916080e-01]]

  [[-2.51439124e-01]]

  [[-2.51779288e-01]]

  [[ 2.39596799e-01]]

  [[-5.01553655e-01]]

  [[ 8.54653418e-02]]

  [[-4.52772230e-02]]

  [[-2.90785819e-01]]

  [[-2.17076279e-02]]

  [[-6.38328016e-01]]

  [[-1.23690546e-01]]]]
====================================================================================
ERROR: Exception encountered when calling layer "tf.math.add_30" (type TFOpLambda).

Dimensions must be equal, but are 512 and 256 for '{{node tf.math.add_30/Add}} = AddV2[T=DT_FLOAT](Placeholder, tf.math.add_30/Add/y)' with input shapes: [1,16,32,512], [1,1,1,256].

Call arguments received:
  • x=tf.Tensor(shape=(1, 16, 32, 512), dtype=float32)
  • y=array([[[[-4.38051105e-01,  2.19055846e-01, -2.88665384e-01,
           1.35780396e-02,  1.58109516e-01, -2.38887161e-01,
          -3.42952102e-01, -1.97811365e-01,  2.38079950e-01,
          -3.00383717e-01, -3.79415274e-01, -1.30230410e-03,
          -1.75636202e-01,  2.26872861e-01,  1.61576495e-01,
          -8.61738101e-02, -1.76845565e-01, -1.94701985e-01,
          -4.46325362e-01,  7.12524429e-02, -2.90709227e-01,
           1.70214891e-01,  1.17164202e-01, -5.50653219e-01,
          -3.44480097e-01,  1.54580593e-01, -4.62583065e-01,
          -3.79618764e-01, -5.28968692e-01,  1.48000792e-01,
          -4.25233126e-01, -5.78302564e-03,  4.97293532e-01,
          -2.00315788e-01, -2.70368993e-01, -1.45630240e-01,
          -3.06725234e-01, -1.06576309e-01, -5.27214468e-01,
          -2.85305828e-01,  9.04806107e-02,  2.00983182e-01,
          -2.48428807e-01, -2.66157866e-01,  3.93011749e-01,
           3.31952661e-01,  1.65964812e-01, -3.65517437e-02,
          -2.23674193e-01, -1.38646007e-01, -1.49682820e-01,
          -5.39370663e-02, -2.81081557e-01, -3.71229798e-01,
          -2.04612076e-01, -4.88200150e-02, -6.52738735e-02,
          -2.77237803e-01, -2.74392933e-01, -3.74132484e-01,
          -9.32027176e-02, -1.05048992e-01,  7.36031681e-02,
          -4.37566787e-01,  2.19656661e-01, -9.63449180e-02,
          -5.89542150e-01,  8.71993005e-02, -3.21139693e-01,
          -4.21330065e-01,  2.29825228e-01, -1.44032342e-02,
          -3.74841958e-01, -2.06909880e-01, -2.34280884e-01,
          -4.43613082e-02, -2.24455640e-01,  1.74495783e-02,
           8.29243064e-02, -2.51245260e-01, -8.34130123e-02,
           3.60969812e-01, -1.46979559e-02,  1.50575653e-01,
          -2.48566922e-02, -8.55817273e-02, -7.02287955e-03,
          -7.66570717e-02, -4.04711902e-01, -4.68300402e-01,
           1.78903379e-02, -3.16399276e-01, -2.55049784e-02,
           2.18878463e-01, -4.74276751e-01,  4.95921932e-02,
          -1.73477843e-01,  4.13701385e-01, -6.25796854e-01,
          -3.44671279e-01, -2.27541566e-01, -3.50501478e-01,
           2.52230585e-01, -1.82993680e-01,  1.14594489e-01,
           5.61434356e-03, -5.73507607e-01, -1.83091506e-01,
           1.09156683e-01,  2.99489617e-01, -1.85676917e-01,
           2.21719816e-01, -3.13707173e-01, -1.75927639e-01,
           1.51497126e-01, -1.25913113e-01, -8.85332406e-01,
           4.08227965e-02,  3.19375843e-02, -1.87790215e-01,
          -1.93310797e-01,  1.42922431e-01, -3.96301538e-01,
           1.69964477e-01, -7.10625276e-02,  2.91089825e-02,
          -1.68964818e-01,  5.51550463e-02,  4.91583310e-02,
          -1.18682615e-01, -5.31681478e-02, -3.94332737e-01,
           6.95292130e-02,  6.71956167e-02,  8.91256630e-02,
           1.14808865e-01, -5.01706719e-01, -3.63382578e-01,
           3.79894814e-03,  1.54746577e-01,  3.78737658e-01,
          -3.64347279e-01,  1.46473855e-01, -4.55153048e-01,
           2.04525799e-01,  5.11586666e-01,  4.96329784e-01,
          -2.45105065e-02, -2.30660811e-01, -4.90913302e-01,
           2.60759830e-01, -4.44954708e-02, -3.99450153e-01,
          -8.48353468e-03, -2.24783599e-01,  3.19117069e-01,
          -5.61902404e-01, -4.65537608e-01,  4.11207467e-01,
           1.23415829e-03,  1.42598927e-01, -4.55421180e-01,
          -4.29093659e-01, -1.12672053e-01, -1.02961019e-01,
          -3.07534128e-01, -4.18100655e-01,  1.35619462e-01,
          -1.75718442e-01,  4.07180702e-03, -2.55745262e-01,
           6.82368398e-01, -5.71846485e-01,  8.79000057e-04,
          -1.71738327e-01, -1.93940818e-01,  4.17013675e-01,
          -3.41771007e-01, -2.27950871e-01, -5.82421482e-01,
          -3.99521552e-02,  2.29098141e-01, -2.78866947e-01,
          -1.96941346e-01,  1.34730920e-01, -3.70289356e-01,
          -2.36257151e-01, -3.49029042e-02, -2.88474977e-01,
           1.61376312e-01,  2.76338644e-02, -3.59379709e-01,
           1.15561545e-01, -4.37495977e-01,  1.33056743e-02,
          -1.77574679e-01,  1.54249936e-01,  1.25672072e-01,
          -2.02557713e-01, -4.97245789e-02, -9.80434790e-02,
          -2.07663611e-01, -6.10441387e-01, -3.17488730e-01,
          -4.49561357e-01, -3.39648217e-01, -1.02272294e-02,
          -2.92957991e-01,  1.92538112e-01,  2.91599870e-01,
           1.16419509e-01, -2.50065565e-01, -5.68220139e-01,
          -1.33831337e-01,  5.69325015e-02,  1.74685955e-01,
           7.30799884e-02, -6.00246117e-02,  3.75379845e-02,
          -3.16989660e-01,  6.29451752e-01,  6.13311157e-02,
          -3.16312879e-01, -1.87226444e-01,  1.77003190e-01,
          -1.64150760e-01, -6.45186305e-02, -1.07377265e-02,
          -4.87804204e-01,  1.33381620e-01, -1.71609774e-01,
          -3.14551771e-01,  1.56140909e-01, -4.75827426e-01,
          -4.09910798e-01,  3.04118961e-01, -3.15654904e-01,
           3.96565855e-01, -7.73698539e-02, -2.54265696e-01,
           1.80844471e-01, -3.48066419e-01, -8.92103165e-02,
          -2.96039492e-01,  1.86911583e-01,  1.55916080e-01,
          -2.51439124e-01, -2.51779288e-01,  2.39596799e-01,
          -5.01553655e-01,  8.54653418e-02, -4.52772230e-02,
          -2.90785819e-01, -2.17076279e-02, -6.38328016e-01,
          -1.23690546e-01]]]], dtype=float32)
  • name=None
ERROR: model_path  : S2PFN_512x1024_opt.xml
ERROR: weights_path: S2PFN_512x1024_opt.bin
ERROR: layer_id    : 110
ERROR: input_layer0 layer_id=108: KerasTensor(type_spec=TensorSpec(shape=(1, 16, 32, 512), dtype=tf.float32, name=None), name='depthwise_conv2d/depthwise:0', description="created by layer 'depthwise_conv2d'")
ERROR: input_layer1 layer_id=109: Const(ndarray).shape  (1, 256, 1, 1)
array([[[[-4.38051105e-01]],

        [[ 2.19055846e-01]],

        [[-2.88665384e-01]],

        [[ 1.35780396e-02]],

        [[ 1.58109516e-01]],

        [[-2.38887161e-01]],

        [[-3.42952102e-01]],

        [[-1.97811365e-01]],

        [[ 2.38079950e-01]],

        [[-3.00383717e-01]],

        [[-3.79415274e-01]],

        [[-1.30230410e-03]],

        [[-1.75636202e-01]],

        [[ 2.26872861e-01]],

        [[ 1.61576495e-01]],

        [[-8.61738101e-02]],

        [[-1.76845565e-01]],

        [[-1.94701985e-01]],

        [[-4.46325362e-01]],

        [[ 7.12524429e-02]],

        [[-2.90709227e-01]],

        [[ 1.70214891e-01]],

        [[ 1.17164202e-01]],

        [[-5.50653219e-01]],

        [[-3.44480097e-01]],

        [[ 1.54580593e-01]],

        [[-4.62583065e-01]],

        [[-3.79618764e-01]],

        [[-5.28968692e-01]],

        [[ 1.48000792e-01]],

        [[-4.25233126e-01]],

        [[-5.78302564e-03]],

        [[ 4.97293532e-01]],

        [[-2.00315788e-01]],

        [[-2.70368993e-01]],

        [[-1.45630240e-01]],

        [[-3.06725234e-01]],

        [[-1.06576309e-01]],

        [[-5.27214468e-01]],

        [[-2.85305828e-01]],

        [[ 9.04806107e-02]],

        [[ 2.00983182e-01]],

        [[-2.48428807e-01]],

        [[-2.66157866e-01]],

        [[ 3.93011749e-01]],

        [[ 3.31952661e-01]],

        [[ 1.65964812e-01]],

        [[-3.65517437e-02]],

        [[-2.23674193e-01]],

        [[-1.38646007e-01]],

        [[-1.49682820e-01]],

        [[-5.39370663e-02]],

        [[-2.81081557e-01]],

        [[-3.71229798e-01]],

        [[-2.04612076e-01]],

        [[-4.88200150e-02]],

        [[-6.52738735e-02]],

        [[-2.77237803e-01]],

        [[-2.74392933e-01]],

        [[-3.74132484e-01]],

        [[-9.32027176e-02]],

        [[-1.05048992e-01]],

        [[ 7.36031681e-02]],

        [[-4.37566787e-01]],

        [[ 2.19656661e-01]],

        [[-9.63449180e-02]],

        [[-5.89542150e-01]],

        [[ 8.71993005e-02]],

        [[-3.21139693e-01]],

        [[-4.21330065e-01]],

        [[ 2.29825228e-01]],

        [[-1.44032342e-02]],

        [[-3.74841958e-01]],

        [[-2.06909880e-01]],

        [[-2.34280884e-01]],

        [[-4.43613082e-02]],

        [[-2.24455640e-01]],

        [[ 1.74495783e-02]],

        [[ 8.29243064e-02]],

        [[-2.51245260e-01]],

        [[-8.34130123e-02]],

        [[ 3.60969812e-01]],

        [[-1.46979559e-02]],

        [[ 1.50575653e-01]],

        [[-2.48566922e-02]],

        [[-8.55817273e-02]],

        [[-7.02287955e-03]],

        [[-7.66570717e-02]],

        [[-4.04711902e-01]],

        [[-4.68300402e-01]],

        [[ 1.78903379e-02]],

        [[-3.16399276e-01]],

        [[-2.55049784e-02]],

        [[ 2.18878463e-01]],

        [[-4.74276751e-01]],

        [[ 4.95921932e-02]],

        [[-1.73477843e-01]],

        [[ 4.13701385e-01]],

        [[-6.25796854e-01]],

        [[-3.44671279e-01]],

        [[-2.27541566e-01]],

        [[-3.50501478e-01]],

        [[ 2.52230585e-01]],

        [[-1.82993680e-01]],

        [[ 1.14594489e-01]],

        [[ 5.61434356e-03]],

        [[-5.73507607e-01]],

        [[-1.83091506e-01]],

        [[ 1.09156683e-01]],

        [[ 2.99489617e-01]],

        [[-1.85676917e-01]],

        [[ 2.21719816e-01]],

        [[-3.13707173e-01]],

        [[-1.75927639e-01]],

        [[ 1.51497126e-01]],

        [[-1.25913113e-01]],

        [[-8.85332406e-01]],

        [[ 4.08227965e-02]],

        [[ 3.19375843e-02]],

        [[-1.87790215e-01]],

        [[-1.93310797e-01]],

        [[ 1.42922431e-01]],

        [[-3.96301538e-01]],

        [[ 1.69964477e-01]],

        [[-7.10625276e-02]],

        [[ 2.91089825e-02]],

        [[-1.68964818e-01]],

        [[ 5.51550463e-02]],

        [[ 4.91583310e-02]],

        [[-1.18682615e-01]],

        [[-5.31681478e-02]],

        [[-3.94332737e-01]],

        [[ 6.95292130e-02]],

        [[ 6.71956167e-02]],

        [[ 8.91256630e-02]],

        [[ 1.14808865e-01]],

        [[-5.01706719e-01]],

        [[-3.63382578e-01]],

        [[ 3.79894814e-03]],

        [[ 1.54746577e-01]],

        [[ 3.78737658e-01]],

        [[-3.64347279e-01]],

        [[ 1.46473855e-01]],

        [[-4.55153048e-01]],

        [[ 2.04525799e-01]],

        [[ 5.11586666e-01]],

        [[ 4.96329784e-01]],

        [[-2.45105065e-02]],

        [[-2.30660811e-01]],

        [[-4.90913302e-01]],

        [[ 2.60759830e-01]],

        [[-4.44954708e-02]],

        [[-3.99450153e-01]],

        [[-8.48353468e-03]],

        [[-2.24783599e-01]],

        [[ 3.19117069e-01]],

        [[-5.61902404e-01]],

        [[-4.65537608e-01]],

        [[ 4.11207467e-01]],

        [[ 1.23415829e-03]],

        [[ 1.42598927e-01]],

        [[-4.55421180e-01]],

        [[-4.29093659e-01]],

        [[-1.12672053e-01]],

        [[-1.02961019e-01]],

        [[-3.07534128e-01]],

        [[-4.18100655e-01]],

        [[ 1.35619462e-01]],

        [[-1.75718442e-01]],

        [[ 4.07180702e-03]],

        [[-2.55745262e-01]],

        [[ 6.82368398e-01]],

        [[-5.71846485e-01]],

        [[ 8.79000057e-04]],

        [[-1.71738327e-01]],

        [[-1.93940818e-01]],

        [[ 4.17013675e-01]],

        [[-3.41771007e-01]],

        [[-2.27950871e-01]],

        [[-5.82421482e-01]],

        [[-3.99521552e-02]],

        [[ 2.29098141e-01]],

        [[-2.78866947e-01]],

        [[-1.96941346e-01]],

        [[ 1.34730920e-01]],

        [[-3.70289356e-01]],

        [[-2.36257151e-01]],

        [[-3.49029042e-02]],

        [[-2.88474977e-01]],

        [[ 1.61376312e-01]],

        [[ 2.76338644e-02]],

        [[-3.59379709e-01]],

        [[ 1.15561545e-01]],

        [[-4.37495977e-01]],

        [[ 1.33056743e-02]],

        [[-1.77574679e-01]],

        [[ 1.54249936e-01]],

        [[ 1.25672072e-01]],

        [[-2.02557713e-01]],

        [[-4.97245789e-02]],

        [[-9.80434790e-02]],

        [[-2.07663611e-01]],

        [[-6.10441387e-01]],

        [[-3.17488730e-01]],

        [[-4.49561357e-01]],

        [[-3.39648217e-01]],

        [[-1.02272294e-02]],

        [[-2.92957991e-01]],

        [[ 1.92538112e-01]],

        [[ 2.91599870e-01]],

        [[ 1.16419509e-01]],

        [[-2.50065565e-01]],

        [[-5.68220139e-01]],

        [[-1.33831337e-01]],

        [[ 5.69325015e-02]],

        [[ 1.74685955e-01]],

        [[ 7.30799884e-02]],

        [[-6.00246117e-02]],

        [[ 3.75379845e-02]],

        [[-3.16989660e-01]],

        [[ 6.29451752e-01]],

        [[ 6.13311157e-02]],

        [[-3.16312879e-01]],

        [[-1.87226444e-01]],

        [[ 1.77003190e-01]],

        [[-1.64150760e-01]],

        [[-6.45186305e-02]],

        [[-1.07377265e-02]],

        [[-4.87804204e-01]],

        [[ 1.33381620e-01]],

        [[-1.71609774e-01]],

        [[-3.14551771e-01]],

        [[ 1.56140909e-01]],

        [[-4.75827426e-01]],

        [[-4.09910798e-01]],

        [[ 3.04118961e-01]],

        [[-3.15654904e-01]],

        [[ 3.96565855e-01]],

        [[-7.73698539e-02]],

        [[-2.54265696e-01]],

        [[ 1.80844471e-01]],

        [[-3.48066419e-01]],

        [[-8.92103165e-02]],

        [[-2.96039492e-01]],

        [[ 1.86911583e-01]],

        [[ 1.55916080e-01]],

        [[-2.51439124e-01]],

        [[-2.51779288e-01]],

        [[ 2.39596799e-01]],

        [[-5.01553655e-01]],

        [[ 8.54653418e-02]],

        [[-4.52772230e-02]],

        [[-2.90785819e-01]],

        [[-2.17076279e-02]],

        [[-6.38328016e-01]],

        [[-1.23690546e-01]]]], dtype=float32)
ERROR: The trace log is below.
Traceback (most recent call last):
  File "C:\Users\20-0365\Desktop\tflite_tools\openvino2tensorflow1.31.3\openvino2tensorflow\openvino2tensorflow.py", line 1301, in convert
    tf_layers_dict[layer_id] = tf.math.add(
  File "C:\Users\20-0365\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\20-0365\AppData\Roaming\Python\Python39\site-packages\keras\layers\core\tf_op_layer.py", line 107, in handle
    return TFOpLambda(op)(*args, **kwargs)
  File "C:\Users\20-0365\AppData\Roaming\Python\Python39\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
ValueError: Exception encountered when calling layer "tf.math.add_30" (type TFOpLambda).

Dimensions must be equal, but are 512 and 256 for '{{node tf.math.add_30/Add}} = AddV2[T=DT_FLOAT](Placeholder, tf.math.add_30/Add/y)' with input shapes: [1,16,32,512], [1,1,1,256].

Call arguments received:
  • x=tf.Tensor(shape=(1, 16, 32, 512), dtype=float32)
  • y=array([[[[-4.38051105e-01,  2.19055846e-01, -2.88665384e-01,
           1.35780396e-02,  1.58109516e-01, -2.38887161e-01,
          -3.42952102e-01, -1.97811365e-01,  2.38079950e-01,
          -3.00383717e-01, -3.79415274e-01, -1.30230410e-03,
          -1.75636202e-01,  2.26872861e-01,  1.61576495e-01,
          -8.61738101e-02, -1.76845565e-01, -1.94701985e-01,
          -4.46325362e-01,  7.12524429e-02, -2.90709227e-01,
           1.70214891e-01,  1.17164202e-01, -5.50653219e-01,
          -3.44480097e-01,  1.54580593e-01, -4.62583065e-01,
          -3.79618764e-01, -5.28968692e-01,  1.48000792e-01,
          -4.25233126e-01, -5.78302564e-03,  4.97293532e-01,
          -2.00315788e-01, -2.70368993e-01, -1.45630240e-01,
          -3.06725234e-01, -1.06576309e-01, -5.27214468e-01,
          -2.85305828e-01,  9.04806107e-02,  2.00983182e-01,
          -2.48428807e-01, -2.66157866e-01,  3.93011749e-01,
           3.31952661e-01,  1.65964812e-01, -3.65517437e-02,
          -2.23674193e-01, -1.38646007e-01, -1.49682820e-01,
          -5.39370663e-02, -2.81081557e-01, -3.71229798e-01,
          -2.04612076e-01, -4.88200150e-02, -6.52738735e-02,
          -2.77237803e-01, -2.74392933e-01, -3.74132484e-01,
          -9.32027176e-02, -1.05048992e-01,  7.36031681e-02,
          -4.37566787e-01,  2.19656661e-01, -9.63449180e-02,
          -5.89542150e-01,  8.71993005e-02, -3.21139693e-01,
          -4.21330065e-01,  2.29825228e-01, -1.44032342e-02,
          -3.74841958e-01, -2.06909880e-01, -2.34280884e-01,
          -4.43613082e-02, -2.24455640e-01,  1.74495783e-02,
           8.29243064e-02, -2.51245260e-01, -8.34130123e-02,
           3.60969812e-01, -1.46979559e-02,  1.50575653e-01,
          -2.48566922e-02, -8.55817273e-02, -7.02287955e-03,
          -7.66570717e-02, -4.04711902e-01, -4.68300402e-01,
           1.78903379e-02, -3.16399276e-01, -2.55049784e-02,
           2.18878463e-01, -4.74276751e-01,  4.95921932e-02,
          -1.73477843e-01,  4.13701385e-01, -6.25796854e-01,
          -3.44671279e-01, -2.27541566e-01, -3.50501478e-01,
           2.52230585e-01, -1.82993680e-01,  1.14594489e-01,
           5.61434356e-03, -5.73507607e-01, -1.83091506e-01,
           1.09156683e-01,  2.99489617e-01, -1.85676917e-01,
           2.21719816e-01, -3.13707173e-01, -1.75927639e-01,
           1.51497126e-01, -1.25913113e-01, -8.85332406e-01,
           4.08227965e-02,  3.19375843e-02, -1.87790215e-01,
          -1.93310797e-01,  1.42922431e-01, -3.96301538e-01,
           1.69964477e-01, -7.10625276e-02,  2.91089825e-02,
          -1.68964818e-01,  5.51550463e-02,  4.91583310e-02,
          -1.18682615e-01, -5.31681478e-02, -3.94332737e-01,
           6.95292130e-02,  6.71956167e-02,  8.91256630e-02,
           1.14808865e-01, -5.01706719e-01, -3.63382578e-01,
           3.79894814e-03,  1.54746577e-01,  3.78737658e-01,
          -3.64347279e-01,  1.46473855e-01, -4.55153048e-01,
           2.04525799e-01,  5.11586666e-01,  4.96329784e-01,
          -2.45105065e-02, -2.30660811e-01, -4.90913302e-01,
           2.60759830e-01, -4.44954708e-02, -3.99450153e-01,
          -8.48353468e-03, -2.24783599e-01,  3.19117069e-01,
          -5.61902404e-01, -4.65537608e-01,  4.11207467e-01,
           1.23415829e-03,  1.42598927e-01, -4.55421180e-01,
          -4.29093659e-01, -1.12672053e-01, -1.02961019e-01,
          -3.07534128e-01, -4.18100655e-01,  1.35619462e-01,
          -1.75718442e-01,  4.07180702e-03, -2.55745262e-01,
           6.82368398e-01, -5.71846485e-01,  8.79000057e-04,
          -1.71738327e-01, -1.93940818e-01,  4.17013675e-01,
          -3.41771007e-01, -2.27950871e-01, -5.82421482e-01,
          -3.99521552e-02,  2.29098141e-01, -2.78866947e-01,
          -1.96941346e-01,  1.34730920e-01, -3.70289356e-01,
          -2.36257151e-01, -3.49029042e-02, -2.88474977e-01,
           1.61376312e-01,  2.76338644e-02, -3.59379709e-01,
           1.15561545e-01, -4.37495977e-01,  1.33056743e-02,
          -1.77574679e-01,  1.54249936e-01,  1.25672072e-01,
          -2.02557713e-01, -4.97245789e-02, -9.80434790e-02,
          -2.07663611e-01, -6.10441387e-01, -3.17488730e-01,
          -4.49561357e-01, -3.39648217e-01, -1.02272294e-02,
          -2.92957991e-01,  1.92538112e-01,  2.91599870e-01,
           1.16419509e-01, -2.50065565e-01, -5.68220139e-01,
          -1.33831337e-01,  5.69325015e-02,  1.74685955e-01,
           7.30799884e-02, -6.00246117e-02,  3.75379845e-02,
          -3.16989660e-01,  6.29451752e-01,  6.13311157e-02,
          -3.16312879e-01, -1.87226444e-01,  1.77003190e-01,
          -1.64150760e-01, -6.45186305e-02, -1.07377265e-02,
          -4.87804204e-01,  1.33381620e-01, -1.71609774e-01,
          -3.14551771e-01,  1.56140909e-01, -4.75827426e-01,
          -4.09910798e-01,  3.04118961e-01, -3.15654904e-01,
           3.96565855e-01, -7.73698539e-02, -2.54265696e-01,
           1.80844471e-01, -3.48066419e-01, -8.92103165e-02,
          -2.96039492e-01,  1.86911583e-01,  1.55916080e-01,
          -2.51439124e-01, -2.51779288e-01,  2.39596799e-01,
          -5.01553655e-01,  8.54653418e-02, -4.52772230e-02,
          -2.90785819e-01, -2.17076279e-02, -6.38328016e-01,
          -1.23690546e-01]]]], dtype=float32)
  • name=None
ERROR: Please refer to 6-7 in the README first. https://github.com/PINTO0309/openvino2tensorflow

Source code for simple inference testing code

The goal is to convert to tflite.

taisuke-tomida commented 2 years ago

https://www.tensorflow.org/api_docs/python/tf/keras/layers/SeparableConv2D

openvino2tensorflow1.31.3

image

I was having problems with a particular layer, so I used SeparableConv2D in keras.
Added on line 2818.

Convert Command

replace.zip

python openvino2tensorflow.py --model_path model_512x1024_opt.xml --model_output_path model --output_saved_model --output_no_quant_float32_tflite --output_integer_quant_tflite --weight_replacement_config replace.json

Successful output of tflite. Comparing the output (masked images) of Pytorch, onnx, and tflite, they were almost identical.
I would appreciate any guidance you could give me on this operation.

thanks.

PINTO0309 commented 2 years ago

Thanks for the suggestion. Your suggestion seems to work. However, under limited conditions.

I am wondering how I should determine the conditions for using SeparableConv2D. image

Furthermore, I can't think of a good idea how to implement the case of [N, C, D, H, W] in 5D. Very distressed.

taisuke-tomida commented 2 years ago

It is a difficult problem. In DepthWiseConv2d, the number of output channels is the number of input channels, right?
Only in 4D, but how about looking at the number of channels in the output and if it is reduced, we can adopt your example?

I am not familiar with it and I am sorry I cannot make a good suggestion.

PINTO0309 commented 2 years ago

Only in 4D, but how about looking at the number of channels in the output and if it is reduced, we can adopt your example?

That is correct.

I will attempt to implement this with limited conditions.

taisuke-tomida commented 2 years ago

I am glad we had a good discussion. Thank you!

taisuke-tomida commented 2 years ago

@PINTO0309 Is JSON correct weight_replacement_config.json?

PINTO0309 commented 2 years ago

I noticed this attached to the reply above.

PINTO0309 commented 2 years ago

LGTM image

taisuke-tomida commented 2 years ago

I am amazed at the speed of response....
I think it is good too!

PINTO0309 commented 2 years ago

Released v1.31.5 . https://github.com/PINTO0309/openvino2tensorflow/releases/tag/v1.31.5

taisuke-tomida commented 2 years ago

Thanks for the quick response!