Skip to content

keras.ops.separable_conv mishandles data_format shape validation and kernel shape inference #22516

@ningxiudg

Description

@ningxiudg

Summary

keras.ops.separable_conv raises shape errors when used with TensorFlow backend, and the error reporting/shape handling appears inconsistent between eager tensors and Keras.Input placeholders.

Reproduction

import keras
import numpy as np

x = np.random.rand(2, 5, 5, 3).astype(np.float32)
dw = np.random.rand(3, 3, 3, 1).astype(np.float32)
pw = np.random.rand(1, 1, 3, 4).astype(np.float32)

# Eager
keras.ops.separable_conv(x, dw, pw, padding="same", data_format="channels_first", dilation_rate=2)

# Symbolic
x2 = keras.Input(shape=(5, 5, 3))
dw2 = keras.Input(shape=(3, 3, 3, 1))
pw2 = keras.Input(shape=(1, 1, 3, 4))
keras.ops.separable_conv(x2, dw2, pw2, padding="same", data_format="channels_first", dilation_rate=2)

Expected

  • The op should either:
    • work correctly for the declared data_format, or
    • raise a clear validation error before dispatching to the backend.
  • Eager and symbolic execution should behave consistently.

Actual

  • Eager execution fails with:
    input depth must be evenly divisible by filter depth: 5 vs 3
  • Symbolic execution fails with:
    Kernel shape must have the same length as input, but received kernel of shape (None, 3, 3, 5, 3) and input of shape (None, 5, 5, 3)

Notes

The reproducer uses the same tensor shapes for both paths, but the backend behavior differs and the op does not appear to handle/validate the data_format and kernel shapes consistently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions