Ошибка преобразования модели onnx в keras [keras2onnx] - PullRequest
0 голосов
/ 08 ноября 2019

В основном я пытаюсь использовать модель глубокого обучения onnx для прогнозирования в python 3 с помощью keras (tf backend). Я пытался преобразовать модель onnx в кераты из здесь , но я получил эту ошибку.

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, 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, 3, 5, 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, 3, 5, 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, 3, 5, 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, 3, 5, 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, 3, 5, 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, 3, 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, 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", 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\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, 5, 75, 3) not compatible with provided weight shape (5, 5, 3, 3)

Или есть ли другой способ использовать модель onnx в Python 3.x для прогнозирования?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...