Skip to content

Commit

Permalink
Merge pull request tensorflow#26423 from duncandean:master
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 249537363
  • Loading branch information
tensorflower-gardener committed May 22, 2019
2 parents 57eae4b + 5064f76 commit 9e0f4e9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tensorflow/python/keras/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,28 @@ def kullback_leibler_divergence(y_true, y_pred): # pylint: disable=missing-docs

@keras_export('keras.metrics.poisson', 'keras.losses.poisson')
def poisson(y_true, y_pred):
"""Computes the Poisson loss between y_true and y_pred.
The Poisson loss is the mean of the elements of the `Tensor`
`y_pred - y_true * log(y_pred)`.
Usage:
```python
loss = tf.keras.losses.poisson([1.4, 9.3, 2.2], [4.3, 8.2, 12.2])
print('Loss: ', loss.numpy()) # Loss: -0.8045559
```
Args:
y_true: Tensor of true targets.
y_pred: Tensor of predicted targets.
Returns:
A `Tensor` with the mean Poisson loss.
Raises:
InvalidArgumentError: If `y_true` and `y_pred` have incompatible shapes.
"""
y_pred = ops.convert_to_tensor(y_pred)
y_true = math_ops.cast(y_true, y_pred.dtype)
return K.mean(y_pred - y_true * math_ops.log(y_pred + K.epsilon()), axis=-1)
Expand Down

0 comments on commit 9e0f4e9

Please sign in to comment.