From 320b357f658c411b153ce941eb89cc020abfe0b6 Mon Sep 17 00:00:00 2001 From: DonkeyShot21 Date: Wed, 29 Sep 2021 21:37:19 +0200 Subject: [PATCH 1/2] added docs and note --- README.md | 4 +++- docs/source/solo/methods/nnbyol.rst | 36 +++++++++++++++++++++++++++++ docs/source/solo/methods/nnsiam.rst | 36 +++++++++++++++++++++++++++++ solo/methods/nnbyol.py | 8 ++++++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 docs/source/solo/methods/nnbyol.rst create mode 100644 docs/source/solo/methods/nnsiam.rst diff --git a/README.md b/README.md index 1b03b1e6..5516d77f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ While the library is self contained, it is possible to use the models outside of --- ## News -* **[Sep 27 2021]**: :pizza: Added [NNSiam](https://arxiv.org/abs/2104.14548), NNBYOL, new tutorials for implementing new methods [1](https://solo-learn.readthedocs.io/en/latest/tutorials/add_new_method.html) and [2](https://solo-learn.readthedocs.io/en/latest/tutorials/add_new_method_momentum.html), more testing and fixed issues with custom data and linear evaluation. +* **[Sep 27 2021]**: :pizza: Added [NNSiam](https://arxiv.org/abs/2104.14548), [NNBYOL]((https://arxiv.org/abs/2104.14548), new tutorials for implementing new methods [1](https://solo-learn.readthedocs.io/en/latest/tutorials/add_new_method.html) and [2](https://solo-learn.readthedocs.io/en/latest/tutorials/add_new_method_momentum.html), more testing and fixed issues with custom data and linear evaluation. * **[Sep 19 2021]**: :kangaroo: Added online k-NN evaluation. * **[Sep 17 2021]**: :robot: Added [ViT](https://arxiv.org/abs/2010.11929) and [Swin](https://arxiv.org/abs/2103.14030). * **[Sep 13 2021]**: :book: Improved [Docs](https://solo-learn.readthedocs.io/en/latest/?badge=latest) and added tutorials for [pretraining](https://solo-learn.readthedocs.io/en/latest/tutorials/overview.html) and [offline linear eval](https://solo-learn.readthedocs.io/en/latest/tutorials/offline_linear_eval.html). @@ -33,7 +33,9 @@ While the library is self contained, it is possible to use the models outside of * [DeepCluster V2](https://arxiv.org/abs/2006.09882) * [DINO](https://arxiv.org/abs/2104.14294) * [MoCo V2+](https://arxiv.org/abs/2003.04297) +* [NNBYOL](https://arxiv.org/abs/2104.14548) * [NNCLR](https://arxiv.org/abs/2104.14548) +* [NNSiam](https://arxiv.org/abs/2104.14548) * [ReSSL](https://arxiv.org/abs/2107.09282) * [SimCLR](https://arxiv.org/abs/2002.05709) + [Supervised Contrastive Learning](https://arxiv.org/abs/2004.11362) * [SimSiam](https://arxiv.org/abs/2011.10566) diff --git a/docs/source/solo/methods/nnbyol.rst b/docs/source/solo/methods/nnbyol.rst new file mode 100644 index 00000000..2f39598b --- /dev/null +++ b/docs/source/solo/methods/nnbyol.rst @@ -0,0 +1,36 @@ +NNBYOL +====== + +.. automethod:: solo.methods.nnbyol.NNBYOL.__init__ + :noindex: + + +add_model_specific_args +~~~~~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnbyol.NNBYOL.add_model_specific_args + :noindex: + +learnable_params +~~~~~~~~~~~~~~~~ +.. autoattribute:: solo.methods.nnbyol.NNBYOL.learnable_params + :noindex: + +dequeue_and_enqueue +~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnbyol.NNBYOL.dequeue_and_enqueue + :noindex: + +find_nn +~~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnbyol.NNBYOL.find_nn + :noindex: + +forward +~~~~~~~ +.. automethod:: solo.methods.nnbyol.NNBYOL.forward + :noindex: + +training_step +~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnbyol.NNBYOL.training_step + :noindex: diff --git a/docs/source/solo/methods/nnsiam.rst b/docs/source/solo/methods/nnsiam.rst new file mode 100644 index 00000000..8f35a9f4 --- /dev/null +++ b/docs/source/solo/methods/nnsiam.rst @@ -0,0 +1,36 @@ +NNSiam +===== + +.. automethod:: solo.methods.nnsiam.NNSiam.__init__ + :noindex: + + +add_model_specific_args +~~~~~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnsiam.NNSiam.add_model_specific_args + :noindex: + +learnable_params +~~~~~~~~~~~~~~~~ +.. autoattribute:: solo.methods.nnsiam.NNSiam.learnable_params + :noindex: + +dequeue_and_enqueue +~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnsiam.NNSiam.dequeue_and_enqueue + :noindex: + +find_nn +~~~~~~~~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnsiam.NNSiam.find_nn + :noindex: + +forward +~~~~~~~ +.. automethod:: solo.methods.nnsiam.NNSiam.forward + :noindex: + +training_step +~~~~~~~~~~~~~ +.. automethod:: solo.methods.nnsiam.NNSiam.training_step + :noindex: diff --git a/solo/methods/nnbyol.py b/solo/methods/nnbyol.py index 46da3653..802fbd7b 100644 --- a/solo/methods/nnbyol.py +++ b/solo/methods/nnbyol.py @@ -45,6 +45,12 @@ def __init__( proj_hidden_dim (int): number of neurons of the hidden layers of the projector. pred_hidden_dim (int): number of neurons of the hidden layers of the predictor. queue_size (int): number of samples to keep in the queue. + + .. note:: + NNBYOL is similar to NNSiam but the queue from which the neighbors are retrieved is + updated using the features of the momentum encoder. See NNCLR's paper for more detals: + https://arxiv.org/abs/2104.14548 + """ super().__init__(**kwargs) @@ -180,7 +186,7 @@ def forward(self, X: torch.Tensor, *args, **kwargs) -> Dict[str, Any]: return {**out, "z": z, "p": p} def training_step(self, batch: Sequence[Any], batch_idx: int) -> torch.Tensor: - """Training step for BYOL reusing BaseMethod training step. + """Training step for NNBYOL reusing BaseMethod training step. Args: batch (Sequence[Any]): a batch of data in the format of [img_indexes, [X], Y], where From 9a058d2ccb5ff1c1deef7c50b884a95391bf17c7 Mon Sep 17 00:00:00 2001 From: DonkeyShot21 Date: Wed, 29 Sep 2021 19:52:57 +0000 Subject: [PATCH 2/2] fixed minors --- docs/source/index.rst | 2 ++ docs/source/solo/methods/nnsiam.rst | 2 +- solo/methods/nnbyol.py | 2 +- solo/methods/nnsiam.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 935da86f..900fcca9 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -69,7 +69,9 @@ While the library is self contained, it is possible to use the models outside of solo/methods/deepclusterv2 solo/methods/dino solo/methods/mocov2plus + solo/methods/nnbyol solo/methods/nnclr + solo/methods/nnsiam solo/methods/ressl solo/methods/simclr solo/methods/simsiam diff --git a/docs/source/solo/methods/nnsiam.rst b/docs/source/solo/methods/nnsiam.rst index 8f35a9f4..6e01dad8 100644 --- a/docs/source/solo/methods/nnsiam.rst +++ b/docs/source/solo/methods/nnsiam.rst @@ -1,5 +1,5 @@ NNSiam -===== +====== .. automethod:: solo.methods.nnsiam.NNSiam.__init__ :noindex: diff --git a/solo/methods/nnbyol.py b/solo/methods/nnbyol.py index 802fbd7b..bfe8f9bc 100644 --- a/solo/methods/nnbyol.py +++ b/solo/methods/nnbyol.py @@ -194,7 +194,7 @@ def training_step(self, batch: Sequence[Any], batch_idx: int) -> torch.Tensor: batch_idx (int): index of the batch. Returns: - torch.Tensor: total loss composed of BYOL and classification loss. + torch.Tensor: total loss composed of NNBYOL and classification loss. """ targets = batch[-1] diff --git a/solo/methods/nnsiam.py b/solo/methods/nnsiam.py index 1c477144..a3f76ba5 100644 --- a/solo/methods/nnsiam.py +++ b/solo/methods/nnsiam.py @@ -174,7 +174,7 @@ def training_step(self, batch: Sequence[Any], batch_idx: int) -> torch.Tensor: batch_idx (int): index of the batch Returns: - torch.Tensor: total loss composed of SimSiam loss and classification loss + torch.Tensor: total loss composed of NNSiam loss and classification loss """ targets = batch[-1]