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
Depthwise convolution layers require depth_multiplier to be strictly positive; zero or negative values would produce zero output channels. __init__ of DepthwiseConv1D/2D/3D validates this immediately.
Source
Thrown at keras/src/layers/convolutional/base_depthwise_conv.py:132
self.strides = standardize_tuple(strides, rank, "strides")
self.dilation_rate = standardize_tuple(
dilation_rate, rank, "dilation_rate"
)
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.bias_initializer = initializers.get(bias_initializer)
self.depthwise_regularizer = regularizers.get(depthwise_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.depthwise_constraint = constraints.get(depthwise_constraint)
self.bias_constraint = constraints.get(bias_constraint)
self.input_spec = InputSpec(min_ndim=self.rank + 2)
self.data_format = self.data_format
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 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):
raise ValueError(
"The argument `strides` cannot contains 0. Received "
f"strides={self.strides}"
)
def build(self, input_shape):View on GitHub (pinned to 7a34a03db6)
Solutions
- Set depth_multiplier to a positive integer (typically 1).
- Clamp computed values: max(1, int(value)).
- Check the config/sweep bounds producing the value.
Example fix
# before layer = keras.layers.DepthwiseConv2D(3, depth_multiplier=0) # after layer = keras.layers.DepthwiseConv2D(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
- Validate config values before building models
- Clamp computed multipliers to max(1, dm)
When it happens
Trigger: Passing depth_multiplier=0 or a negative value (often computed from config or a sweep) when constructing keras.layers.DepthwiseConv2D or 1D/3D variants.
Common situations: Hyperparameter search yielding 0; depth_multiplier computed from a channel count or ratio that underflows to 0; copy-paste from a SeparableConv config.
Related errors
- The argument `kernel_size` cannot contain 0. Received kernel
- The argument `strides` cannot contains 0. Received strides={
- Invalid value for argument `depth_multiplier`. Expected a st
- If using `weights="imagenet"` as true, `classes` should be 1
- The number of repeats in `EfficientNet` must be > 0. Receive
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/bfb62b41fcecefe1.
Report an issue: GitHub.