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

Self-supervised learning - BYOL implementation #1305

Merged
merged 39 commits into from
Oct 5, 2021

Conversation

Nimrais
Copy link
Contributor

@Nimrais Nimrais commented Sep 27, 2021

Before submitting (checklist)

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contribution guide?
  • Did you check the code style? catalyst-make-codestyle -l 99 && catalyst-check-codestyle -l 99 (pip install -U catalyst-codestyle).
  • Did you make sure to update the docs? We use Google format for all the methods and classes.
  • Did you check the docs with make check-docs?
  • Did you write any new necessary tests?
  • Did you check that your code passes the unit tests pytest . ?
  • Did you add your new functionality to the docs?
  • Did you update the CHANGELOG?
  • Did you run colab minimal CI/CD with latest and minimal requirements?
  • Did you check XLA integration with single and multiple processes?

Description

Bootstrap Your Own Latent (BYOL) is an approach to self-supervised image representation learning. BYOL relies on two neural networks, referred to as online and target networks, that interact and learn from each other. From an augmented view of an image, we train the online network to predict the target network representation of the same image under a different augmented view.

For this pipeline, we need to implement a callback for updating the target network from the online network (SoftUpdateCallback) and add a multi-encoder strategy in SelfSupervisedRunner.

Related Issue

Type of Change

  • Examples / docs / tutorials / contributors update
  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves an existing feature)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

FAQ

Please review the FAQ before submitting an issue:

@pep8speaks
Copy link

pep8speaks commented Sep 27, 2021

Hello @Nimrais! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-10-04 20:05:48 UTC

catalyst/callbacks/soft_update.py Outdated Show resolved Hide resolved
catalyst/callbacks/soft_update.py Outdated Show resolved Hide resolved
source_model_key: key to the source data inside `runner.model`
tau: smoothing parameter `target * (1.0 - tau) + source * tau`
"""
super().__init__(order=CallbackOrder.Metric)
Copy link
Member

Choose a reason for hiding this comment

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

External, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, it should be on the same level as Criterion (change of the model), but maybe you have another point.

# flake8: noqa
import argparse

from common import add_arguments, ContrastiveModel, datasets
Copy link
Member

Choose a reason for hiding this comment

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

could we use local naming?
like from .common?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will do that.

Copy link
Member

Choose a reason for hiding this comment

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

👀

catalyst/runners/self_supervised.py Outdated Show resolved Hide resolved
examples/self_supervised/common.py Show resolved Hide resolved
@mergify mergify bot dismissed Scitator’s stale review October 4, 2021 06:09

Pull request has been modified.

catalyst/callbacks/soft_update.py Outdated Show resolved Hide resolved
catalyst/callbacks/soft_update.py Outdated Show resolved Hide resolved
catalyst/utils/torch.py Outdated Show resolved Hide resolved
Co-authored-by: Sergey Kolesnikov <scitator@gmail.com>
@mergify mergify bot dismissed Scitator’s stale review October 4, 2021 16:44

Pull request has been modified.

Comment on lines 175 to 178
if isinstance(self.model, (collections.Mapping, nn.ModuleDict)):
encoders = [(encoder_name, self.model[encoder_name]) for encoder_name in self.model]
else:
encoders = [("", self.model)]
Copy link
Member

Choose a reason for hiding this comment

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

let's move it to on_stage_start
so we could set up some internal flag like is_kv_model once per stage rather than every batch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like that?

# flake8: noqa
import argparse

from common import add_arguments, ContrastiveModel, datasets
Copy link
Member

Choose a reason for hiding this comment

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

👀

@mergify mergify bot dismissed Scitator’s stale review October 4, 2021 19:31

Pull request has been modified.

@@ -13,6 +16,7 @@ class ISelfSupervisedRunner(IRunner):
augemention_prefix: key for ``runner.batch`` to sample augumentions
projection_prefix: key for ``runner.batch`` to store model projection
embedding_prefix: key for `runner.batch`` to store model embeddings
encoders: encoder keys inside `model`
Copy link
Member

Choose a reason for hiding this comment

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

👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Scitator
Scitator previously approved these changes Oct 4, 2021
@mergify mergify bot dismissed Scitator’s stale review October 4, 2021 20:05

Pull request has been modified.

@Scitator Scitator merged commit 027e007 into catalyst-team:master Oct 5, 2021
@Nimrais Nimrais deleted the byol-implemention branch October 5, 2021 19:53
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.

None yet

3 participants