From 1898c17bab1ef56564c814bb52492ef2b3844aea Mon Sep 17 00:00:00 2001 From: Reza Gharibi Date: Sat, 22 Nov 2025 05:25:38 +0330 Subject: [PATCH] Fix keras 12 buggy commit id --- projects/keras/bugs/12/bug.info | 2 +- projects/keras/bugs/12/bug_patch.txt | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/projects/keras/bugs/12/bug.info b/projects/keras/bugs/12/bug.info index 999f51bd..506b23e9 100644 --- a/projects/keras/bugs/12/bug.info +++ b/projects/keras/bugs/12/bug.info @@ -1,4 +1,4 @@ python_version="3.7.3" -buggy_commit_id="6dff721a3a8755356b2e89d02ef63ad8ab38ec95" +buggy_commit_id="3fcb5e38a1470bf0aa5fa1b9b0dd712b7992e493" fixed_commit_id="6dff721a3a8755356b2e89d02ef63ad8ab38ec95" test_file="tests/keras/metrics_test.py" diff --git a/projects/keras/bugs/12/bug_patch.txt b/projects/keras/bugs/12/bug_patch.txt index e69de29b..535831be 100644 --- a/projects/keras/bugs/12/bug_patch.txt +++ b/projects/keras/bugs/12/bug_patch.txt @@ -0,0 +1,22 @@ +diff --git a/keras/metrics.py b/keras/metrics.py +index 8e3df1f365f8..b0c500b2c570 100644 +--- a/keras/metrics.py ++++ b/keras/metrics.py +@@ -34,10 +34,13 @@ def categorical_accuracy(y_true, y_pred): + + + def sparse_categorical_accuracy(y_true, y_pred): +- # flatten y_true in case it's in shape (num_samples, 1) instead of (num_samples,) +- return K.cast(K.equal(K.flatten(y_true), +- K.cast(K.argmax(y_pred, axis=-1), K.floatx())), +- K.floatx()) ++ # reshape in case it's in shape (num_samples, 1) instead of (num_samples,) ++ if K.ndim(y_true) == K.ndim(y_pred): ++ y_true = K.squeeze(y_true, -1) ++ # convert dense predictions to labels ++ y_pred_labels = K.argmax(y_pred, axis=-1) ++ y_pred_labels = K.cast(y_pred_labels, K.floatx()) ++ return K.cast(K.equal(y_true, y_pred_labels), K.floatx()) + + + def top_k_categorical_accuracy(y_true, y_pred, k=5):