Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF1-Keras ZeroPadding2D + Conv2D Bias Term Not Fused. #1741

Closed
leimao opened this issue Oct 13, 2021 · 1 comment · Fixed by #1796
Closed

TF1-Keras ZeroPadding2D + Conv2D Bias Term Not Fused. #1741

leimao opened this issue Oct 13, 2021 · 1 comment · Fixed by #1796
Assignees
Labels
contribution welcome Community contribution is welcomed keras Issues related to Keras

Comments

@leimao
Copy link
Contributor

leimao commented Oct 13, 2021

Describe the bug

ZeroPadding2D + Conv2D with bias term cannot be exported as single Conv2D ONNX operator. It is exported as Conv2D + Add instead.

Urgency

We wish it could be fixed asap.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 20.04.2 LTS
  • Tensorflow Version: 1.15.5
  • Python version: 3.8.10

To Reproduce

In NVIDIA TensorFlow-1 Docker Container:

docker run -it --rm --gpus all -v $(pwd):/mnt nvcr.io/nvidia/tensorflow:21.08-tf1-py3

Install TF2ONNX (tried both the master branch and the latest release 1.9.2)

pip install git+https://github.com/onnx/tensorflow-onnx

Run the following script to generate ONNX file for Conv2DTranspose.

import onnx
import tf2onnx
import tensorflow as tf

inputs = tf.keras.Input(shape=(64, 256, 256))
middles = tf.keras.layers.ZeroPadding2D(
    padding=(0, 4),
    data_format="channels_first",
    name="padding")(inputs)
outputs = tf.keras.layers.Conv2D(
    filters=1,
    kernel_size=(9, 9),
    strides=(1, 1),
    use_bias=True,
    data_format="channels_first",
    name="conv2d",
)(middles)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

onnx_model, _ = tf2onnx.convert.from_keras(
    model=model,
    opset=13,
    large_model=False,
)

onnx.save_model(onnx_model, "conv2d.onnx")

Screenshots

image

Additional context

N/A

@TomWildenhain-Microsoft
Copy link
Contributor

As before, hopefully someone else will be able to look at this soon, but feel free to do a PR if you want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Community contribution is welcomed keras Issues related to Keras
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants