From 92540e9917ace547dfc35a23eca4f0026ffb3212 Mon Sep 17 00:00:00 2001 From: ragmani Date: Tue, 14 Jan 2025 10:54:25 +0000 Subject: [PATCH] Remove __call__ --- .../package/experimental/train/losses/cce.py | 18 ------------------ .../package/experimental/train/losses/mse.py | 15 --------------- 2 files changed, 33 deletions(-) diff --git a/runtime/onert/api/python/package/experimental/train/losses/cce.py b/runtime/onert/api/python/package/experimental/train/losses/cce.py index 832ac7bfb08..0fb1fa89729 100644 --- a/runtime/onert/api/python/package/experimental/train/losses/cce.py +++ b/runtime/onert/api/python/package/experimental/train/losses/cce.py @@ -13,21 +13,3 @@ def __init__(self, reduction="mean"): reduction (str): Reduction type ('mean', 'sum'). """ super().__init__(reduction) - - def __call__(self, y_true, y_pred): - """ - Compute the Categorical Cross-Entropy loss. - Args: - y_true (np.ndarray): One-hot encoded ground truth values. - y_pred (np.ndarray): Predicted probabilities. - Returns: - float or np.ndarray: Computed loss value(s). - """ - epsilon = 1e-7 # Prevent log(0) - y_pred = np.clip(y_pred, epsilon, 1 - epsilon) - loss = -np.sum(y_true * np.log(y_pred), axis=1) - - if self.reduction == "mean": - return np.mean(loss) - elif self.reduction == "sum": - return np.sum(loss) diff --git a/runtime/onert/api/python/package/experimental/train/losses/mse.py b/runtime/onert/api/python/package/experimental/train/losses/mse.py index fe42b293ea4..ed9e37e3482 100644 --- a/runtime/onert/api/python/package/experimental/train/losses/mse.py +++ b/runtime/onert/api/python/package/experimental/train/losses/mse.py @@ -13,18 +13,3 @@ def __init__(self, reduction="mean"): reduction (str): Reduction type ('mean', 'sum'). """ super().__init__(reduction) - - def __call__(self, y_true, y_pred): - """ - Compute the Mean Squared Error (MSE) loss. - Args: - y_true (np.ndarray): Ground truth values. - y_pred (np.ndarray): Predicted values. - Returns: - float or np.ndarray: Computed MSE loss value(s). - """ - loss = (y_true - y_pred)**2 - if self.reduction == "mean": - return np.mean(loss) - elif self.reduction == "sum": - return np.sum(loss)