onnx / keras-onnx

Convert tf.keras/Keras models to ONNX
Apache License 2.0
379 stars 109 forks source link

Variables in slicing are incorrectly applied when converted to onnx #698

Open tommy2is opened 3 years ago

tommy2is commented 3 years ago

Tensorflow version: 2.2 Keras onnx version: 1.7.0

Description: Slicing does not produce the same shape output after conversion if a variable is used as index.

code snippet

input = tf.keras.Input(shape=(( 114*4,122*5, 3)))
h = tf.shape(input)[1]
h2 = tf.cast(tf.math.divide(h,2), tf.int32)
x = input[:, h2: , : , :]
model = tf.keras.Model(input, x)
onnx_model = keras2onnx.convert_keras(model, model.name)

Running a (1, 456, 610, 3) input using tensorflow returns an output of shape (1, 228, 610, 3) while the onnx output returns a tensor of shape (1, 456, 610, 3).

I am fairly new to the Onnx, and am attempting to convert a custom model, but ran into the above issue in a middle layer where I attempt to half the image. I would appreciate any help getting the simple operation above to work, thank you.

jiafatom commented 3 years ago

Can you try keras2onnx master?

tommy2is commented 3 years ago

The mismatch still occurs when I use !pip install -U git+https://github.com/onnx/keras-onnx