Skip to content
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

TripletLoss #289

Closed
LukeWood opened this issue Apr 8, 2022 · 4 comments
Closed

TripletLoss #289

LukeWood opened this issue Apr 8, 2022 · 4 comments

Comments

@LukeWood
Copy link
Contributor

LukeWood commented Apr 8, 2022

No description provided.

@LukeWood LukeWood added the losses label Apr 8, 2022
@bhack
Copy link
Contributor

bhack commented Apr 8, 2022

@chjort
Copy link
Contributor

chjort commented Apr 13, 2022

Triplet loss is also implemented in TF Similarity.
https://github.com/tensorflow/similarity/blob/master/tensorflow_similarity/losses/triplet_loss.py

We could move these contrastive losses to Keras-CV if it is cool with TF Similarity.

However, I do think we need to think about the implementation design of contrastive losses compared to regular losses.
Contrastive losses are often used in self-supervised learning, where loss is computed for similarities between two different sets of images, and each set with its own labels. Therefore the standard loss(y_true, y_pred) signature is not well suited for contrastive losses. It would need something like loss(y_true_q, y_true_k, y_pred_q, y_pred_k).

See for example this figure from MOCO paper
Screenshot from 2022-04-14 01-43-27

Example of self-supervised losses like this is SimCLR, BYOL, Barlow Twins, MOCO.

Otherwise, we need to design our contrastive losses to expect y_pred to be a similarity matrix and y_true to be a pair-wise label matrix.

@LukeWood
Copy link
Contributor Author

Great points… triplet in particular this is really tricky!!! This will need some thought.

SimCLR at least the loss still just has two inputs so it’s not as bad

@LukeWood
Copy link
Contributor Author

The KerasCV team is attempting to narrow the package scope in order to more efficiently use our limited resources. As such, we are only accepting contributions directly related to items on the 6 month roadmap for the package.

If you feel this feature could be particularly useful, or would like to contribute it - please feel free to re-open this issue and ping LukeWood, ianstenbit or tanzhenyu

Feel free to read more on the roadmap:
https://github.com/keras-team/keras-cv/blob/master/.github/ROADMAP.md

This is already in tf similarity too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants