Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Added the Euclidean distance loss function. #509

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ keras_contrib/layers/normalization/groupnormalization.py @titu1994
keras_contrib/layers/capsule.py @SriRangaTarun

# losses

keras-contrib/keras_contrib/losses/euclidean_distance_loss.py @RoadToML

# metrics

Expand Down
1 change: 1 addition & 0 deletions contrib_docs/pydocmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ generate:
- keras_contrib.losses.jaccard_distance
- keras_contrib.losses.crf_loss
- keras_contrib.losses.crf_nll
- keras_contrib.losses.euclidean_distance_loss
- optimizers.md:
- keras_contrib.optimizers:
- keras_contrib.optimizers.FTML
Expand Down
15 changes: 15 additions & 0 deletions keras_contrib/losses/euclidean_distance_loss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import keras.backend as K


def euclidean_distance_loss(y_true, y_pred):
"""
The Euclidean distance between two points in Euclidean space.

# Arguments
y_true: tensor with true targets.
y_pred: tensor with predicted targets.

# Returns
float type Euclidean distance between two data points.
"""
return K.sqrt(K.sum(K.square(y_pred - y_true), axis=-1))