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

Adding an example for Supervised Contrastive Learning #283

Merged
merged 22 commits into from
Dec 2, 2020

Conversation

ksalama
Copy link
Contributor

@ksalama ksalama commented Oct 18, 2020

Supervised Contrastive Learning: https://arxiv.org/abs/2004.11362

@ksalama
Copy link
Contributor Author

ksalama commented Oct 18, 2020

@fchollet - kindly review the PR

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Please only include the Python file in the PR for now.

@ksalama
Copy link
Contributor Author

ksalama commented Oct 19, 2020

Done - Only the Python file is included in the PR.

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
@ksalama
Copy link
Contributor Author

ksalama commented Oct 21, 2020

@fchollet - Have addressed your comments. Kindly review my revisions.
Thanks!

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update!

examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
@ksalama
Copy link
Contributor Author

ksalama commented Oct 26, 2020

@fchollet kindly find my revisions. Cheers

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few minor comments.

examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good, please use preprocessing layers and address the remaining comments.

@ksalama
Copy link
Contributor Author

ksalama commented Nov 21, 2020

@fchollet - I think I have addressed all your comments, including:

  1. Using preprocessing layers for data augmentation (maintaining the same or slightly better results compared to the DataGenerator)
  2. Adding a conclusion section
  3. Fixing the ReLU and BatchNorm layers ordering

Please let me know if there is anything else need to be modified.

@ksalama
Copy link
Contributor Author

ksalama commented Nov 21, 2020

I have simplified the models by removing the BatchNorm layers as they don't improve the results

@fchollet
Copy link
Contributor

Using preprocessing layers for data augmentation (maintaining the same or slightly better results compared to the DataGenerator)

The code I'm seeing still uses ImageDataGenerator; did you push the changes to the PR?

@ksalama
Copy link
Contributor Author

ksalama commented Nov 26, 2020

@fchollet - Sorry for the confusion. I've just pushed the changes and they should be now part of the PR

@ksalama
Copy link
Contributor Author

ksalama commented Nov 26, 2020

Also made some formatting updates

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Please address the remaining nits and add the autogenerated .md and .ipynb files (you can generate them with the python autogen.py add_example command)

examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
examples/vision/supervised-contrastive-learning.py Outdated Show resolved Hide resolved
@ksalama
Copy link
Contributor Author

ksalama commented Nov 28, 2020

Nits addressed

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, please add the generated files to the PR!

Copy link
Contributor

@8bitmp3 8bitmp3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ksalama I'm a tf.keras user here and just came across the PR. This example is awesome.

Can you please check and change RestNet to ResNet (assuming you're discussing residual networks like in https://arxiv.org/abs/1512.03385).

architecture, like ResNet, and multi-class problems with many labels.

Can I also suggest to improve the introduction just a little bit to help the readers understand what they're about to learn? You could, for example, write about 1) what the user will learn about - in a bit more detail (can be summarized from the paper on arXiv (with the link included) before going into the two-phase structure that you already mentioned; 2) what the user will do - it's a classification task for X using Y dataset. Both of these could be just 1-2 short sentences.

Also, I'd advise to copy-paste the Markdown text into Google Docs just to check that all grammar and spelling is 👍 - but I've not spotted anything out of the ordinary here.

Anyway, these are just suggestions from experience. I really enjoyed the paper, thanks for sharing the work!

outperformed the conventional technique in terms of the test accuracy. Note that
the same training budget (i.e., number of epochs) was given to each technique.
Supervised contrastive learning pays off when the encoder involves a complex
architecture, like RestNet, and multi-class problems with many labels.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change RestNet to ResNet (assuming you're discussing residual networks like in https://arxiv.org/abs/1512.03385)?

Suggested change
architecture, like RestNet, and multi-class problems with many labels.
architecture, like ResNet, and multi-class problems with many labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @8bitmp3 for spotting this. I have applied the fixes 👍

@fchollet
Copy link
Contributor

fchollet commented Dec 1, 2020

Thanks @8bitmp3 for the feedback. @ksalama, I believe the example is ready, so you can add the .md and .ipynb files to the PR.

@ksalama
Copy link
Contributor Author

ksalama commented Dec 2, 2020

@fchollet I have added the generated .md and .ipynb files to the PR

Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you for the great contribution! I'll take it from there 👍

@fchollet fchollet merged commit e447af2 into keras-team:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants