1

Ask a Question

I success convert mxnet model to onnx but it failed when inference .The model 's shape is (1,1,100,100)
convert code

sym = 'single-symbol.json'
params = '/single-0090.params'
input_shape = (1, 1, 100, 100)
onnx_file = './model.onnx'
converted_model_path = onnx_mxnet.export_model(sym, params, [input_shape], np.float32, onnx_file,verbose=True)
model= onnx.load_model(converted_model_path)
checker.check_graph(model.graph)
checker.check_model(model)

output

INFO:root:Input shape of the model [(1, 1, 100, 100)] 
INFO:root:Exported ONNX file ./model.onnx saved to disk

inference code

sess = ort.InferenceSession("./model.onnx") 

output

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException:
 [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : 
Exception during initialization: 
/onnxruntime/core/providers/cpu/nn/pool_attributes.h:77 
onnxruntime::PoolAttributes::PoolAttributes(const OpNodeProtoHelper<onnxruntime::ProtoHelperNodeContext> &,
                                                  const std::string &, int) pads[dim] < kernel_shape[dim] &&
                                                  pads[dim + kernel_shape.size()] < kernel_shape[dim] was false. 
Pad should be smaller than kernel.

Question

mxnet pooling node json

{
  "op": "Pooling", 
  "name": "pool1_fwd", 
  "attrs": {
    "count_include_pad": "True", 
    "global_pool": "False", 
    "kernel": "(4, 4)", 
    "layout": "NCHW", 
    "pad": "(4, 4)", 
    "pool_type": "avg", 
    "pooling_convention": "valid", 
    "stride": "(4, 4)"
  }, 
  "inputs": [[46, 0, 0]]
}

I change the "pad": "(4, 4)" to "pad": "(3, 3)" smaller than "kernel": "(4, 4), then try convert again.

sess = ort.InferenceSession("./model.onnx")
output = sess.run(None, {"data": data.astype(np.float32)})

it worked,but the output value is not right. how to fix it ? BTW:convert the mxnet model to ncnn all is right(not change anything,pad=(4,4),kernel=(4,4))

Further information

python:3.8 onnx:1.10.2 mxnet:1.8.0

JiaoPaner
  • 25
  • 4

1 Answers1

0

I fix it,recode model by pytorch and copy weights,use nn.ZeroPad2d(4) before avgpooling:

self.pad = nn.ZeroPad2d(4)
self.pool = nn.AvgPool2d(kernel_size=(4,4),stride=(4,4))

X = self.pool(self.pad(self.conv(X)))
JiaoPaner
  • 25
  • 4