microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.18k stars 2.86k forks source link

ConvTranspose output_shape seems wrong for dynamic input shape when auto_pad='SAME_LOWER' #6067

Closed jiafatom closed 3 years ago

jiafatom commented 3 years ago

Describe the bug ConvTranspose output_shape seems wrong for dynamic input shape when auto_pad='SAME_LOWER'

Urgency none

System information master

To Reproduce I have a keras model and convert to ONNX. See attached please remove 'zip' at the end. conv_transpose.onnx.zip The python code running ORT:

import numpy as np
import onnxruntime
sess = onnxruntime.InferenceSession('conv_transpose.onnx')
data1 = np.random.rand(2 * 3 * 4 * 5).astype(np.float32).reshape(2, 3, 4, 5)
data = [data1]
input_names = sess.get_inputs()
feed = zip(sorted(i_.name for i_ in input_names), data)
feed_input = dict(feed)
actual = sess.run(None, feed_input)

The output shape is (2,3,6,8), but keras output shape is (2,2,2,8). With some debug, the issue is that output_shape in ComputePadsAndOutputShape() is unknown for auto_pad='SAME_LOWER'. In this case, it seems wrong to apply out_size = (in_size - 1) * stride + adj + (kernel - 1) * dilation + 1; because there is no guarantee that input_size=output_size which is suggested by SAME_LOWER.

hariharans29 commented 3 years ago

Any chance this will solve it ? - https://github.com/microsoft/onnxruntime/pull/4271

jiafatom commented 3 years ago

Yes it does resolve the issue for stride=1 case. For stride>1, need onnx spec change, so raise an issue there. We can close this onnxruntime issue once the above mentioned PR gets checked in.

hariharans29 commented 3 years ago

Makes sense, thank David. Btw - do all the new 4 keras models need stride > 1 ? Or is there s a model that uses stride == 1 ? If there is a real model that uses stride == 1 and auto_pad attribute, we can run a final verification and merge that fix in.

jiafatom commented 3 years ago

These four models don't use stride=1. They use strides=2 (this is the most common case) unet_plusplus unet center-net (this include actually two models when enable nms or not)

hariharans29 commented 3 years ago

Quick clarification though - do we need the auto_pad attribute ? Can we use explicit padding or is it because the model consumes dynamic shaped inputs ?

jiafatom commented 3 years ago

Yes it is because the model consumes dynamic shaped inputs, so we have to use auto_pad.

hariharans29 commented 3 years ago

Closing as the ORT change supporting auto_pad in ConvTranspose is checked-in