Skip to content

Convert inputs to tensor #2108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
7 changes: 4 additions & 3 deletions tensorflow_addons/losses/triplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def triplet_semihard_loss(
Returns:
triplet_loss: float scalar with dtype of `y_pred`.
"""

labels, embeddings = y_true, y_pred
labels = tf.convert_to_tensor(y_true, name="labels")
embeddings = tf.convert_to_tensor(y_pred, name="embeddings")

convert_to_float32 = (
embeddings.dtype == tf.dtypes.float16 or embeddings.dtype == tf.dtypes.bfloat16
Expand Down Expand Up @@ -242,7 +242,8 @@ def triplet_hard_loss(
Returns:
triplet_loss: float scalar with dtype of `y_pred`.
"""
labels, embeddings = y_true, y_pred
labels = tf.convert_to_tensor(y_true, name="labels")
embeddings = tf.convert_to_tensor(y_pred, name="embeddings")

convert_to_float32 = (
embeddings.dtype == tf.dtypes.float16 or embeddings.dtype == tf.dtypes.bfloat16
Expand Down