onnx模型到keras的转换[keras2onnx]错误

基本上,我正在尝试使用onnx深度学习模型在带有keras(tf后端)的python 3中进行预测。我试图将onnx模型从here转换为keras,但出现此错误。

Using TensorFlow backend.
INFO:onnx2keras:Converter is called.
DEBUG:onnx2keras:List input shapes:
DEBUG:onnx2keras:None
DEBUG:onnx2keras:List inputs:
DEBUG:onnx2keras:Input 0 -> imageinput_AvgImg.
DEBUG:onnx2keras:Input 1 -> conv_1_1_W.
DEBUG:onnx2keras:Input 2 -> conv_1_1_B.
DEBUG:onnx2keras:Input 3 -> batchnorm_1_1_scale.
DEBUG:onnx2keras:Input 4 -> batchnorm_1_1_B.
DEBUG:onnx2keras:Input 5 -> batchnorm_1_1_mean.
DEBUG:onnx2keras:Input 6 -> batchnorm_1_1_var.
DEBUG:onnx2keras:Input 7 -> conv_1_2_W.
DEBUG:onnx2keras:Input 8 -> conv_1_2_B.
DEBUG:onnx2keras:Input 9 -> batchnorm_1_2_scale.
DEBUG:onnx2keras:Input 10 -> batchnorm_1_2_B.
DEBUG:onnx2keras:Input 11 -> batchnorm_1_2_mean.
DEBUG:onnx2keras:Input 12 -> batchnorm_1_2_var.
DEBUG:onnx2keras:Input 13 -> conv_2_2_W.
DEBUG:onnx2keras:Input 14 -> conv_2_2_B.
DEBUG:onnx2keras:Input 15 -> batchnorm_2_2_scale.
DEBUG:onnx2keras:Input 16 -> batchnorm_2_2_B.
DEBUG:onnx2keras:Input 17 -> batchnorm_2_2_mean.
DEBUG:onnx2keras:Input 18 -> batchnorm_2_2_var.
DEBUG:onnx2keras:Input 19 -> conv_2_1_W.
DEBUG:onnx2keras:Input 20 -> conv_2_1_B.
DEBUG:onnx2keras:Input 21 -> batchnorm_2_1_scale.
DEBUG:onnx2keras:Input 22 -> batchnorm_2_1_B.
DEBUG:onnx2keras:Input 23 -> batchnorm_2_1_mean.
DEBUG:onnx2keras:Input 24 -> batchnorm_2_1_var.
DEBUG:onnx2keras:Input 25 -> conv_3_2_W.
DEBUG:onnx2keras:Input 26 -> conv_3_2_B.
DEBUG:onnx2keras:Input 27 -> batchnorm_3_2_scale.
DEBUG:onnx2keras:Input 28 -> batchnorm_3_2_B.
DEBUG:onnx2keras:Input 29 -> batchnorm_3_2_mean.
DEBUG:onnx2keras:Input 30 -> batchnorm_3_2_var.
DEBUG:onnx2keras:Input 31 -> conv_3_1_W.
DEBUG:onnx2keras:Input 32 -> conv_3_1_B.
DEBUG:onnx2keras:Input 33 -> batchnorm_3_1_scale.
DEBUG:onnx2keras:Input 34 -> batchnorm_3_1_B.
DEBUG:onnx2keras:Input 35 -> batchnorm_3_1_mean.
DEBUG:onnx2keras:Input 36 -> batchnorm_3_1_var.
DEBUG:onnx2keras:Input 37 -> fc_1_W.
DEBUG:onnx2keras:Input 38 -> fc_1_B.
DEBUG:onnx2keras:Input 39 -> fc_2_W.
DEBUG:onnx2keras:Input 40 -> fc_2_B.
DEBUG:onnx2keras:Input 41 -> imageinput.
DEBUG:onnx2keras:List outputs:
DEBUG:onnx2keras:Output 0 -> softmax.
DEBUG:onnx2keras:Gathering weights to dictionary.
DEBUG:onnx2keras:Found weight imageinput_AvgImg with shape (1,3,75,75).
DEBUG:onnx2keras:Found weight conv_1_1_W with shape (3,5,5).
DEBUG:onnx2keras:Found weight conv_1_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_1_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_1_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_1_var with shape (3,).
DEBUG:onnx2keras:Found weight conv_1_2_W with shape (3,5).
DEBUG:onnx2keras:Found weight conv_1_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_2_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_2_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_1_2_var with shape (3,).
DEBUG:onnx2keras:Found weight conv_2_2_W with shape (3,5).
DEBUG:onnx2keras:Found weight conv_2_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_2_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_2_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_2_var with shape (3,).
DEBUG:onnx2keras:Found weight conv_2_1_W with shape (3,5).
DEBUG:onnx2keras:Found weight conv_2_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_1_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_1_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_2_1_var with shape (3,).
DEBUG:onnx2keras:Found weight conv_3_2_W with shape (3,5).
DEBUG:onnx2keras:Found weight conv_3_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_2_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_2_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_2_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_2_var with shape (3,).
DEBUG:onnx2keras:Found weight conv_3_1_W with shape (3,5).
DEBUG:onnx2keras:Found weight conv_3_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_1_scale with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_1_B with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_1_mean with shape (3,).
DEBUG:onnx2keras:Found weight batchnorm_3_1_var with shape (3,).
DEBUG:onnx2keras:Found weight fc_1_W with shape (100,59,59).
DEBUG:onnx2keras:Found weight fc_1_B with shape (100,).
DEBUG:onnx2keras:Found weight fc_2_W with shape (2,100,1,1).
DEBUG:onnx2keras:Found weight fc_2_B with shape (2,).
DEBUG:onnx2keras:Found input imageinput with shape [3,75]
DEBUG:onnx2keras:######
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Converting ONNX operation
DEBUG:onnx2keras:type: Sub
DEBUG:onnx2keras:node_name: imageinput_Sub
DEBUG:onnx2keras:node_params: {'change_ordering': False,'name_policy': None}
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Check if all inputs are available:
DEBUG:onnx2keras:Check input 0 (name imageinput).
DEBUG:onnx2keras:Check input 1 (name imageinput_AvgImg).
DEBUG:onnx2keras:The input not found in layers / model inputs.
DEBUG:onnx2keras:Found in weights,add as a numpy constant.
DEBUG:onnx2keras:... found all,continue
DEBUG:onnx2keras:sub:Convert inputs to Keras/TF layers if needed.
Traceback (most recent call last):
  File "o2k.py",line 7,in <module>
    k_model = onnx_to_keras(onnx_model,['imageinput'])
  File "D:\Users\Phuntsho Wangdi\Desktop\onnx\onnx2keras\converter.py",line 174,in onnx_to_keras
    keras_names
  File "D:\Users\Phuntsho Wangdi\Desktop\onnx\onnx2keras\elementwise_layers.py",line 140,in convert_elementwise_sub
    input_1 = ensure_tf_type(layers[node.input[1]],layers[list(layers)[0]],name="%s_const2" % keras_name)
  File "D:\Users\Phuntsho Wangdi\Desktop\onnx\onnx2keras\utils.py",line 45,in ensure_tf_type
    return lambda_layer(fake_input_layer)
  File "D:\Anaconda3\envs\onnx\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py",line 842,in __call__
    outputs = call_fn(cast_inputs,*args,**kwargs)
  File "D:\Anaconda3\envs\onnx\lib\site-packages\tensorflow_core\python\keras\layers\core.py",line 795,in call
    return self.function(inputs,**arguments)
  File "D:\Users\Phuntsho Wangdi\Desktop\onnx\onnx2keras\utils.py",line 42,in target_layer
    return tf.constant(inp,dtype=inp.dtype,verify_shape=True)
TypeError: constant() got an unexpected keyword argument 'verify_shape'

我删除了“ verify_shape”参数,现在出现以下错误。

Traceback (most recent call last):
  File "o2k.py",in onnx_to_keras
    keras_names
  File "D:\Users\Phuntsho Wangdi\Desktop\onnx\onnx2keras\convolution_layers.py",line 123,in convert_conv
    layers[node_name] = conv(input_0)
  File "D:\Anaconda3\envs\onnx\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py",line 817,in __call__
    self._maybe_build(inputs)
  File "D:\Anaconda3\envs\onnx\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py",line 2148,in _maybe_build
    self.set_weights(self._initial_weights)
  File "D:\Anaconda3\envs\onnx\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py",line 1336,in set_weights
    'provided weight shape ' + str(w.shape))
ValueError: Layer weight shape (5,3) not compatible with provided weight shape (5,3)

或者还有其他方法可以在python 3.x中使用onnx模型进行预测吗?

masycq 回答:onnx模型到keras的转换[keras2onnx]错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3140032.html

大家都在问