chrismolli / loss-funs-for-uncertainty

Custom loss functions for Keras models to estimate predictive uncertainty.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

loss-funs-for-uncertainty

Custom loss functions for Keras models to estimate predictive uncertainty. The loss implementations are based on [Kendall2017] and contain a logistic loss for classification and a mse-like regression loss function.

Usage

Import the wanted loss constructor from its source and pass the y_true and y_pred tensors to it.

  from aleatoric_log_loss import AleatoricLogLoss

  lfun = AleatoricLogLoss()
  loss = lfun(y_true, y_pred)

Alternatively, it can also be used upon model compilation.

  from tensorflow import keras

  model = keras.Sequential()
  ...

  model.compile(loss = AleatoricLogLoss())

Make sure that the prediction tensor is a tuple containing (y_pred, std_pred).

About

Custom loss functions for Keras models to estimate predictive uncertainty.

License:MIT License


Languages

Language:Python 100.0%