Select Git revision
loss.py 526 B
"""Collection of different customised loss functions."""
from keras import backend as K
from typing import Callable
def l_p_loss(power: int) -> Callable:
"""
Calculate the L<p> loss for given power p.
L1 (p=1) is equal to mean absolute error (MAE), L2 (p=2) is to mean squared error (MSE), ...
:param power: set the power of the error calculus
:return: loss for given power
"""
def loss(y_true, y_pred):
return K.mean(K.pow(K.abs(y_pred - y_true), power), axis=-1)
return loss