keras-team/keras · error · ValueError
input_tensor must be a valid Keras tensor type; Received
Error message
input_tensor must be a valid Keras tensor type; Received {input_tensor} of type {type(input_tensor)} What it means
MobileNetV2 builder in keras/src/applications/mobilenet_v2.py: the supplied input_tensor did not satisfy the is_keras_tensor type check, so its concrete Python type is reported in the error. It fires when a non-symbolic object (NumPy array, TF eager tensor, placeholder from another library) is passed as input_tensor while input_shape is also set.
Solutions
- Replace input_tensor with a keras.Input symbol, e.g. keras.Input(shape=(224, 224, 3))
- Omit input_tensor and rely on input_shape alone
- Check type(input_tensor) — only Keras symbolic tensors are accepted
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/applications/mobilenet_v2.py:172 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/2db35ab42c18b562.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/applications/mobilenet_v2.py:172
if input_tensor.shape[2] != input_shape[1]:
raise ValueError(
"input_tensor.shape[2] must equal input_shape[1]; "
"Received `input_tensor.shape="
f"{input_tensor.shape}`, "
f"`input_shape={input_shape}`"
)
else:
raise ValueError(
"input_tensor is not a Keras tensor; "
f"Received `input_tensor={input_tensor}`"
)
# If input_shape is None, infer shape from input_tensor.
if input_shape is None and input_tensor is not None:
try:
backend.is_keras_tensor(input_tensor)
except ValueError:
raise ValueError(
"input_tensor must be a valid Keras tensor type; "
f"Received {input_tensor} of type {type(input_tensor)}"
)
if input_shape is None and not backend.is_keras_tensor(input_tensor):
default_size = 224
elif input_shape is None and backend.is_keras_tensor(input_tensor):
if backend.image_data_format() == "channels_first":
rows = input_tensor.shape[2]
cols = input_tensor.shape[3]
else:
rows = input_tensor.shape[1]
cols = input_tensor.shape[2]
if rows == cols and rows in [96, 128, 160, 192, 224]:
default_size = rows
else:
default_size = 224View on GitHub (pinned to 7a34a03db6)