tf.keras.losses.Poisson

Computes the Poisson loss between y_true and y_pred.

loss = y_pred - y_true * log(y_pred)

Standalone usage:

y_true = [[0., 1.], [0., 0.]]
y_pred = [[1., 1.], [0., 0.]]
# Using 'auto'/'sum_over_batch_size' reduction type.
p = tf.keras.losses.Poisson()
p(y_true, y_pred).numpy()
0.5
# Calling with 'sample_weight'.
p(y_true, y_pred, sample_weight=[0.8, 0.2]).numpy()
0.4
# Using 'sum' reduction type.
p = tf.keras.losses.Poisson(
    reduction=tf.keras.losses.Reduction.SUM)
p(y_true, y_pred).numpy()
0.999
# Using 'none' reduction type.
p = tf.keras.losses.Poisson(
    reduction=tf.keras.losses.Reduction.NONE)
p(y_true, y_pred).numpy()
array([0.999, 0.], dtype=float32)

Usage with the compile() API:

model.compile(optimizer='sgd', loss=tf.keras.losses.Poisson())

reduction (Optional) Type of tf.keras.losses.Reduction to apply to loss. Default