keras-team/keras · error · ValueError

Invalid value for argument `depth_multiplier`. Expected a st

Error message

Invalid value for argument `depth_multiplier`. Expected a strictly positive value. Received depth_multiplier={self.depth_multiplier}.

What it means

Separable convolution layers (SeparableConv1D/2D) require depth_multiplier to be strictly positive; the depthwise stage needs at least one output channel per input channel, so __init__ rejects <=0 values.

Source

Thrown at keras/src/layers/convolutional/base_separable_conv.py:135

        self.padding = standardize_padding(padding)
        self.data_format = standardize_data_format(data_format)
        self.activation = activations.get(activation)
        self.use_bias = use_bias
        self.depthwise_initializer = initializers.get(depthwise_initializer)
        self.pointwise_initializer = initializers.get(pointwise_initializer)
        self.bias_initializer = initializers.get(bias_initializer)
        self.depthwise_regularizer = regularizers.get(depthwise_regularizer)
        self.pointwise_regularizer = regularizers.get(pointwise_regularizer)
        self.bias_regularizer = regularizers.get(bias_regularizer)
        self.depthwise_constraint = constraints.get(depthwise_constraint)
        self.pointwise_constraint = constraints.get(pointwise_constraint)
        self.bias_constraint = constraints.get(bias_constraint)
        self.data_format = self.data_format

        self.input_spec = InputSpec(min_ndim=self.rank + 2)

        if self.depth_multiplier is not None and self.depth_multiplier <= 0:
            raise ValueError(
                "Invalid value for argument `depth_multiplier`. Expected a "
                "strictly positive value. Received "
                f"depth_multiplier={self.depth_multiplier}."
            )

        if self.filters is not None and self.filters <= 0:
            raise ValueError(
                "Invalid value for argument `filters`. Expected a strictly "
                f"positive value. Received filters={self.filters}."
            )

        if not all(self.kernel_size):
            raise ValueError(
                "The argument `kernel_size` cannot contain 0. Received: "
                f"kernel_size={self.kernel_size}."
            )

        if not all(self.strides):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use a positive integer for depth_multiplier (1 is the common default).
  2. Validate the config value before constructing: assert isinstance(dm, int) and dm > 0.
  3. Trace where the 0/negative value originates (sweep bounds, env var parsing).

Example fix

# before
keras.layers.SeparableConv2D(32, 3, depth_multiplier=0)

# after
keras.layers.SeparableConv2D(32, 3, depth_multiplier=1)
Defensive patterns

Strategy: validation

Validate before calling

assert depth_multiplier is None or (isinstance(depth_multiplier, int) and depth_multiplier > 0)

Type guard

def valid_depth_multiplier(dm) -> bool:
    return dm is None or (isinstance(dm, int) and dm > 0)

Prevention

When it happens

Trigger: Passing depth_multiplier=0 or negative to keras.layers.SeparableConv1D or SeparableConv2D, including values from config dicts or hyperparameter tuning.

Common situations: Config-driven model builders where depth_multiplier is computed and underflows to 0; defaults dropped when loading JSON/YAML configs.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/4280062e0f864d78. Report an issue: GitHub.