mxnet模型转onnx失败

以下的讨论是基于:
MXNet版本: 1.4.1
ONNX版本:1.5.0
操作系统: win10

我使用crnn+lstm训练了一个字符识别的模型,想要把这个模型转换成onnx,遇到了一些错误。
转换代码:

import mxnet as mx
import numpy as np
from mxnet.contrib import onnx as onnx_mxnet
import logging
logging.basicConfig(level=logging.INFO)

sym = "./model-v1.0.0-symbol.json"
params = "model-v1.0.0-0020.params"

onnx_file = './mxnet_exported_crnn.onnx'
converted_model_path = onnx_mxnet.export_model(sym, params, [(1, 1, 32, 280)], np.float32, onnx_file, True)

错误描述:

  data: (1, 1, 32, 280)
  conv-0_weight: (64, 1, 3, 3)
  conv-0_bias: (64,)
  batchnorm-0_gamma: (64,)
  batchnorm-0_beta: (64,)
  conv-0-1x1_weight: (64, 64, 1, 1)
  conv-0-1x1_bias: (64,)
  batchnorm-0-1x1_gamma: (64,)
  batchnorm-0-1x1_beta: (64,)
  conv-2_weight: (256, 64, 3, 3)
  conv-2_bias: (256,)
  batchnorm-2_gamma: (256,)
  batchnorm-2_beta: (256,)
  conv-2-1x1_weight: (256, 256, 1, 1)
  conv-2-1x1_bias: (256,)
  batchnorm-2-1x1_gamma: (256,)
  batchnorm-2-1x1_beta: (256,)
  conv-3_weight: (512, 256, 3, 3)
  conv-3_bias: (512,)
  batchnorm-3_gamma: (512,)
  batchnorm-3_beta: (512,)
  conv-3-1x1_weight: (512, 512, 1, 1)
  conv-3-1x1_bias: (512,)
  batchnorm-3-1x1_gamma: (512,)
  batchnorm-3-1x1_beta: (512,)
  conv-4_weight: (512, 512, 3, 3)
  conv-4_bias: (512,)
  batchnorm-4_gamma: (512,)
  batchnorm-4_beta: (512,)
  conv-4-1x1_weight: (512, 512, 1, 1)
  conv-4-1x1_bias: (512,)
  batchnorm-4-1x1_gamma: (512,)
  batchnorm-4-1x1_beta: (512,)
  conv-5_weight: (512, 512, 3, 3)
  conv-5_bias: (512,)
  batchnorm-5_gamma: (512,)
  batchnorm-5_beta: (512,)
  conv-5-1x1_weight: (512, 512, 1, 1)
  conv-5-1x1_bias: (512,)
  batchnorm-5-1x1_gamma: (512,)
  batchnorm-5-1x1_beta: (512,)
  lstm0_l0_i2h_weight: (400, 512)
  lstm0_l0_h2h_weight: (400, 100)
  lstm0_r0_i2h_weight: (400, 512)
  lstm0_r0_h2h_weight: (400, 100)
  lstm0_l1_i2h_weight: (400, 200)
  lstm0_l1_h2h_weight: (400, 100)
  lstm0_r1_i2h_weight: (400, 200)
  lstm0_r1_h2h_weight: (400, 100)
  lstm0_l0_i2h_bias: (400,)
  lstm0_l0_h2h_bias: (400,)
  lstm0_r0_i2h_bias: (400,)
  lstm0_r0_h2h_bias: (400,)
  lstm0_l1_i2h_bias: (400,)
  lstm0_l1_h2h_bias: (400,)
  lstm0_r1_i2h_bias: (400,)
  lstm0_r1_h2h_bias: (400,)
  pred_fc_weight: (6426, 200)
  pred_fc_bias: (6426,)
  batchnorm-0_moving_mean: (64,)
  batchnorm-0_moving_var: (64,)
  batchnorm-0-1x1_moving_mean: (64,)
  batchnorm-0-1x1_moving_var: (64,)
  batchnorm-2_moving_mean: (256,)
  batchnorm-2_moving_var: (256,)
  batchnorm-2-1x1_moving_mean: (256,)
  batchnorm-2-1x1_moving_var: (256,)
  batchnorm-3_moving_mean: (512,)
  batchnorm-3_moving_var: (512,)
  batchnorm-3-1x1_moving_mean: (512,)
  batchnorm-3-1x1_moving_var: (512,)
  batchnorm-4_moving_mean: (512,)
  batchnorm-4_moving_var: (512,)
  batchnorm-4-1x1_moving_mean: (512,)
  batchnorm-4-1x1_moving_var: (512,)
  batchnorm-5_moving_mean: (512,)
  batchnorm-5_moving_var: (512,)
  batchnorm-5-1x1_moving_mean: (512,)
  batchnorm-5-1x1_moving_var: (512,)
Traceback (most recent call last):
  File "d:\pyproject\mxnet-project\mxnet-example\mxnet_to_onnx.py", line 28, in <module>
    converted_model_path = onnx_mxnet.export_model(sym, params, [(1, 1, 32, 280)], np.float32, onnx_file, True)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_model.py", line 83, in export_model
    verbose=verbose)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py", line 214, in create_onnx_graph_proto
    graph_outputs = MXNetGraph.get_outputs(sym, params, in_shape, output_label)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py", line 145, in get_outputs
    _, out_shapes, _ = sym.infer_shape(**inputs)
  File "D:\anaconda\lib\site-packages\mxnet\symbol\symbol.py", line 996, in infer_shape
    res = self._infer_shape_impl(False, *args, **kwargs)
  File "D:\anaconda\lib\site-packages\mxnet\symbol\symbol.py", line 1126, in _infer_shape_impl
    ctypes.byref(complete)))
  File "D:\anaconda\lib\site-packages\mxnet\base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator ctc_loss0: [10:40:15] c:\jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\./ctc_loss-inl.h:220: Check failed: lshape.ndim() == 2U (0 vs. 2) The number of dimensions of labels array must be 2.

之后修改了输入的shape:
converted_model_path = onnx_mxnet.export_model(sym, params, [(1, 1, 32, 280), (1, 5)], np.float32, onnx_file, True)
错误如下:

INFO:root:Converting idx: 0, op: null, name: data
INFO:root:Converting idx: 1, op: null, name: conv-0_weight
INFO:root:Converting idx: 2, op: null, name: conv-0_bias
INFO:root:Converting idx: 3, op: Convolution, name: conv-0
INFO:root:Converting idx: 4, op: null, name: batchnorm-0_gamma
INFO:root:Converting idx: 5, op: null, name: batchnorm-0_beta
INFO:root:Converting idx: 6, op: null, name: batchnorm-0_moving_mean
INFO:root:Converting idx: 7, op: null, name: batchnorm-0_moving_var
INFO:root:Converting idx: 8, op: BatchNorm, name: batchnorm-0
INFO:root:Converting idx: 9, op: LeakyReLU, name: leakyrelu-0
...
INFO:root:Converting idx: 89, op: Convolution, name: conv-5-1x1
INFO:root:Converting idx: 90, op: null, name: batchnorm-5-1x1_gamma
INFO:root:Converting idx: 91, op: null, name: batchnorm-5-1x1_beta
INFO:root:Converting idx: 92, op: null, name: batchnorm-5-1x1_moving_mean
INFO:root:Converting idx: 93, op: null, name: batchnorm-5-1x1_moving_var
INFO:root:Converting idx: 94, op: BatchNorm, name: batchnorm-5-1x1
INFO:root:Converting idx: 95, op: LeakyReLU, name: leakyrelu-5-1x1
INFO:root:Converting idx: 96, op: Pooling, name: pool1
Traceback (most recent call last):
  File "d:\pyproject\mxnet-project\mxnet-example\mxnet_to_onnx.py", line 28, in <module>
    converted_model_path = onnx_mxnet.export_model(sym, params, [(1, 1, 32, 280), (1, 10)], np.float32, onnx_file, True)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_model.py", line 83, in export_model
    verbose=verbose)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py", line 256, in create_onnx_graph_proto
    idx=idx
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\export_onnx.py", line 92, in convert_layer
    return convert_func(node, **kwargs)
  File "D:\anaconda\lib\site-packages\mxnet\contrib\onnx\mx2onnx\_op_translations.py", line 606, in convert_pooling
    name=name
  File "C:\Users\AppData\Roaming\Python\Python36\site-packages\onnx\helper.py", line 56, in make_node
    for key, value in sorted(kwargs.items()))
  File "C:\Users\\AppData\Roaming\Python\Python36\site-packages\onnx\helper.py", line 56, in <genexpr>
    for key, value in sorted(kwargs.items()))
  File "C:\Users\\AppData\Roaming\Python\Python36\site-packages\onnx\helper.py", line 255, in make_attribute
    'Value "{}" is not valid attribute data type.'.format(value))
ValueError: Value "None" is not valid attribute data type.

想请教一下,这个要怎么解决。