From 2c605ce17fccdee2fddc816af86921dd3e4a3820 Mon Sep 17 00:00:00 2001 From: sushreebarsa <84765720+sushreebarsa@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:46:48 +0530 Subject: [PATCH] Updating a typo in TF doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the line from if (y_pred_rank - y_true_rank != 1) or y_pred_shape[-1] == 1: to if (y_pred_rank - y_true_rank == 1) or y_pred_shape[-1] == 1: as the current behavior will squeeze the y_pred tensor even when it’s the same rank and shape as the y_pred tensor. Fixes #62718 Please have a look at this and do the needful. Thank you! --- tf_keras/utils/losses_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf_keras/utils/losses_utils.py b/tf_keras/utils/losses_utils.py index 49d5e1cc7..1a7d100f2 100644 --- a/tf_keras/utils/losses_utils.py +++ b/tf_keras/utils/losses_utils.py @@ -195,7 +195,7 @@ def squeeze_or_expand_dimensions(y_pred, y_true=None, sample_weight=None): y_true_rank = y_true_shape.ndims if (y_true_rank is not None) and (y_pred_rank is not None): # Use static rank for `y_true` and `y_pred`. - if (y_pred_rank - y_true_rank != 1) or y_pred_shape[-1] == 1: + if (y_pred_rank - y_true_rank == 1) or y_pred_shape[-1] == 1: y_true, y_pred = remove_squeezable_dimensions(y_true, y_pred) else: # Use dynamic rank.