{"record":{"id":"aa00e93c7aeb841a","repo":"keras-team/keras","slug":"decode-predictions-expects-a-batch-of-prediction","errorCode":null,"errorMessage":"`decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Received array with shape: {preds.shape}","messagePattern":"`decode_predictions` expects a batch of predictions \\(i\\.e\\. a 2D array of shape \\(samples, 1000\\)\\)\\. Received array with shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/imagenet_utils.py","lineNumber":136,"sourceCode":"    \"\"\"Decodes the prediction of an ImageNet model.\n\n    Args:\n        preds: NumPy array encoding a batch of predictions.\n        top: Integer, how many top-guesses to return. Defaults to `5`.\n\n    Returns:\n        A list of lists of top class prediction tuples\n        `(class_name, class_description, score)`.\n        One list of tuples per sample in batch input.\n\n    Raises:\n        ValueError: In case of invalid shape of the `pred` array\n            (must be 2D).\n    \"\"\"\n    global CLASS_INDEX\n\n    if len(preds.shape) != 2 or preds.shape[1] != 1000:\n        raise ValueError(\n            \"`decode_predictions` expects \"\n            \"a batch of predictions \"\n            \"(i.e. a 2D array of shape (samples, 1000)). \"\n            f\"Received array with shape: {preds.shape}\"\n        )\n    if CLASS_INDEX is None:\n        fpath = file_utils.get_file(\n            \"imagenet_class_index.json\",\n            CLASS_INDEX_PATH,\n            cache_subdir=\"models\",\n            file_hash=\"c2c37ea517e94d9795004a39431a14cb\",\n        )\n        with open(fpath) as f:\n            CLASS_INDEX = json.load(f)\n    results = []\n    preds = ops.convert_to_numpy(preds)\n    for pred in preds:\n        top_indices = pred.argsort()[-top:][::-1]","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/imagenet_utils.py#L118-L154","documentation":"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.","triggerScenarios":"Thrown at keras/src/applications/imagenet_utils.py:136 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}