keras-team/keras · error · ValueError
`decode_predictions` expects a batch of predictions (i.e. a
Error message
`decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Received array with shape: {preds.shape} What it means
Error "`decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Received array with shape: {preds.shape}" thrown in keras-team/keras.
Source
Thrown at keras/src/applications/imagenet_utils.py:136
"""Decodes the prediction of an ImageNet model.
Args:
preds: NumPy array encoding a batch of predictions.
top: Integer, how many top-guesses to return. Defaults to `5`.
Returns:
A list of lists of top class prediction tuples
`(class_name, class_description, score)`.
One list of tuples per sample in batch input.
Raises:
ValueError: In case of invalid shape of the `pred` array
(must be 2D).
"""
global CLASS_INDEX
if len(preds.shape) != 2 or preds.shape[1] != 1000:
raise ValueError(
"`decode_predictions` expects "
"a batch of predictions "
"(i.e. a 2D array of shape (samples, 1000)). "
f"Received array with shape: {preds.shape}"
)
if CLASS_INDEX is None:
fpath = file_utils.get_file(
"imagenet_class_index.json",
CLASS_INDEX_PATH,
cache_subdir="models",
file_hash="c2c37ea517e94d9795004a39431a14cb",
)
with open(fpath) as f:
CLASS_INDEX = json.load(f)
results = []
preds = ops.convert_to_numpy(preds)
for pred in preds:
top_indices = pred.argsort()[-top:][::-1]View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/applications/imagenet_utils.py:136 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/aa00e93c7aeb841a.
Report an issue: GitHub.