keras-team/keras · error · ValueError
When backend.image_data_format()=channels_first, input_shape
Error message
When backend.image_data_format()=channels_first, input_shape[1] must equal input_tensor.shape[1]. Received input_shape={input_shape}, input_tensor.shape={input_tensor.shape} What it means
Error "When backend.image_data_format()=channels_first, input_shape[1] must equal input_tensor.shape[1]. Received input_shape={input_shape}, input_tensor.shape={input_tensor.shape}" thrown in keras-team/keras.
Source
Thrown at keras/src/applications/mobilenet_v3.py:206
if input_shape is not None and input_tensor is not None:
try:
is_input_t_tensor = backend.is_keras_tensor(input_tensor)
except ValueError:
try:
is_input_t_tensor = backend.is_keras_tensor(
operation_utils.get_source_inputs(input_tensor)
)
except ValueError:
raise ValueError(
"input_tensor: ",
input_tensor,
"is not type input_tensor. "
f"Received type(input_tensor)={type(input_tensor)}",
)
if is_input_t_tensor:
if backend.image_data_format() == "channels_first":
if input_tensor.shape[1] != input_shape[1]:
raise ValueError(
"When backend.image_data_format()=channels_first, "
"input_shape[1] must equal "
"input_tensor.shape[1]. Received "
f"input_shape={input_shape}, "
"input_tensor.shape="
f"{input_tensor.shape}"
)
else:
if input_tensor.shape[2] != input_shape[1]:
raise ValueError(
"input_shape[1] must equal "
"input_tensor.shape[2]. Received "
f"input_shape={input_shape}, "
"input_tensor.shape="
f"{input_tensor.shape}"
)
else:
raise ValueError(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/applications/mobilenet_v3.py:206 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/76a44b2ce37c9ca2.
Report an issue: GitHub.