Skip to content

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

Closed
@leimao

Description

@leimao

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

Metadata

Metadata

Assignees

Labels

contribution welcomeCommunity contribution is welcomedkerasIssues related to Keras

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions