Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ and PyTorch Lightning distributed examples for all models to kickstart your proj
| Model | Year | Paper | Docs | Colab (PyTorch) | Colab (PyTorch Lightning) |
|----------------|------|-------|------|-----------------|----------------------------|
| MoCo | 2019 | [paper](https://arxiv.org/abs/1911.05722) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/moco.html) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/moco.ipynb) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch_Lightning-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/moco.ipynb) | <!-- 13/11/2019 -->
| SimCLR | 2020 | [paper](https://arxiv.org/abs/2002.05709) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/simclr.html) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/simclr.ipynb) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch_Lightning-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/simclr.ipynb) | <!-- 13/02/2020 -->
| SimCLR | 2020 | [paper](https://arxiv.org/abs/2002.05709) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/simclr.html) | [example](https://github.com/lightly-ai/lightly/blob/master/examples/simclr.py) | [benchmark](https://github.com/lightly-ai/lightly/blob/master/benchmarks/simclr) | <!-- 13/02/2020 -->
| BYOL | 2020 | [paper](https://arxiv.org/abs/2006.07733) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/byol.html) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/byol.ipynb) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch_Lightning-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/byol.ipynb) | <!-- 13/06/2020 -->
| SwaV | 2020 | [paper](https://arxiv.org/abs/2006.09882) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/swav.html) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/swav.ipynb) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch_Lightning-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/swav.ipynb) | <!-- 17/06/2020 -->
| DenseCL | 2020 | [paper](https://arxiv.org/abs/2011.09157) | [docs](https://docs.lightly.ai/self-supervised-learning/examples/densecl.html) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/densecl.ipynb) | [![Open In Colab](https://img.shields.io/badge/Colab-PyTorch_Lightning-blue?logo=googlecolab)](https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/densecl.ipynb) | <!-- 18/11/2020 -->
Expand Down Expand Up @@ -313,7 +313,7 @@ See the [benchmarking scripts](./benchmarks/imagenet/) for details.
| LeJEPA\*\* | ViT-S/16 | 512 | 100 | 64.0 | 78.7 | 47.1 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_vits16_lejepa_2026-05-20_17-59-16/pretrain/version_0/metrics_plot.png) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_vits16_lejepa_2026-05-20_17-59-16/pretrain/version_0/checkpoints/epoch%3D099-val_online_cls_top1%3D0.5623.ckpt) |
| MAE | ViT-B/16 | 256 | 100 | 46.0 | 81.3 | 11.2 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_vitb16_mae_2024-02-25_19-57-30/pretrain/version_0/events.out.tfevents.1708887459.Machine2.1092409.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_vitb16_mae_2024-02-25_19-57-30/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| MoCoV2 | Res50 | 256 | 100 | 61.5 | 74.3 | 41.8 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_mocov2_2024-02-18_10-29-14/pretrain/version_0/events.out.tfevents.1708248562.Machine2.439033.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_mocov2_2024-02-18_10-29-14/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| SimCLR\* | Res50 | 256 | 100 | 63.2 | 73.9 | 44.8 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_simclr_2023-06-22_09-11-13/pretrain/version_0/events.out.tfevents.1687417883.Machine2.33270.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_simclr_2023-06-22_09-11-13/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| SimCLR\*\*\* | Res50 | 256 | 100 | 63.2 | 73.9 | 44.8 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_simclr_2023-06-22_09-11-13/pretrain/version_0/events.out.tfevents.1687417883.Machine2.33270.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_simclr_2023-06-22_09-11-13/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| SimCLR\* + DCL | Res50 | 256 | 100 | 65.1 | 73.5 | 49.6 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_dcl_2023-07-04_16-51-40/pretrain/version_0/events.out.tfevents.1688482310.Machine2.247807.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_dcl_2023-07-04_16-51-40/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| SimCLR\* + DCLW | Res50 | 256 | 100 | 64.5 | 73.2 | 48.5 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_dclw_2023-07-07_14-57-13/pretrain/version_0/events.out.tfevents.1688734645.Machine2.3176.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_dclw_2023-07-07_14-57-13/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
| SwAV | Res50 | 256 | 100 | 67.2 | 75.4 | 49.5 | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_swav_2023-05-25_08-29-14/pretrain/version_0/events.out.tfevents.1684996168.Machine2.1445108.0) | [link](https://lightly-ssl-checkpoints.s3.amazonaws.com/imagenet_resnet50_swav_2023-05-25_08-29-14/pretrain/version_0/checkpoints/epoch%3D99-step%3D500400.ckpt) |
Expand All @@ -323,6 +323,10 @@ See the [benchmarking scripts](./benchmarks/imagenet/) for details.
_\*We use square root learning rate scaling instead of linear scaling as it yields
better results for smaller batch sizes. See Appendix B.1 in the [SimCLR paper](https://arxiv.org/abs/2002.05709)._

_\*\*\*This number was produced by `benchmarks/imagenet/resnet50/simclr.py`, which
has been replaced by `benchmarks/simclr/`. The new benchmark has not reproduced it
yet; see [benchmarks/simclr/README.md](benchmarks/simclr/README.md) for what differs._

_\*\*The LeJEPA numbers were published in [#1935](https://github.com/lightly-ai/lightly/pull/1935) (`a08c5c35`) and predate the loss fix in [#2023](https://github.com/lightly-ai/lightly/pull/2023), which adds the global views to SIGReg and the invariance term. They will be updated after a re-run._

### ImageNet100
Expand Down
9 changes: 7 additions & 2 deletions benchmarks/imagenet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ to read, run, and adapt.
**Goals**
* Provide easy to use/adapt reference implementations of SSL methods.
* Keep methods self-contained while using Lightly building blocks. See
[resnet50/simclr.py](resnet50/simclr.py) for a compact example.
[resnet50/byol.py](resnet50/byol.py) for a compact example.

**Note**
> SimCLR has moved to [benchmarks/simclr/](../simclr), which carries one row per
> dataset and is gated against `examples/simclr.py`. The rest of this tree follows
> as each method is ported.
Comment on lines +17 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove SimCLR from the old benchmark inventory

After moving SimCLR out of this tree, the Available Benchmarks table still advertises it under resnet50/. Users following that inventory and passing --methods simclr to this README's resnet50/main.py command will get a KeyError, because the SimCLR file was deleted and METHODS no longer contains that key. Update the inventory alongside this move.

Useful? React with 👍 / 👎.

* Remain as framework agnostic as possible. The benchmarks mainly rely on PyTorch and PyTorch Lightning; some ViT methods require `timm` (install via `pip install lightly[timm]`).

**Non-Goals**
Expand Down Expand Up @@ -64,7 +69,7 @@ python main.py \
To run only specific methods, use `--methods`:

```bash
python main.py --epochs 100 --batch-size-per-device 128 --methods simclr byol
python main.py --epochs 100 --batch-size-per-device 128 --methods dcl byol
```

## Run ViT Benchmarks
Expand Down
146 changes: 0 additions & 146 deletions benchmarks/imagenet/resnet50/simclr.py

This file was deleted.

58 changes: 18 additions & 40 deletions docs/source/examples/simclr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,29 @@ Reference:
Tutorials:
:ref:`lightly-simclr-tutorial-3`

The example
-----------

.. tabs::
.. tab:: PyTorch
One file, plain PyTorch, with the training loop in view. Run it with::

.. image:: https://img.shields.io/badge/Open%20in%20Colab-blue?logo=googlecolab&label=%20&labelColor=5c5c5c
:target: https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch/simclr.ipynb
python examples/simclr.py

This example can be run from the command line with::
.. literalinclude:: ../../../examples/simclr.py

python lightly/examples/pytorch/simclr.py
Reproducing a published number
------------------------------

.. literalinclude:: ../../../examples/pytorch/simclr.py
``benchmarks/simclr/`` runs the same method on Lightning, with the paper's
settings, the probes and DDP. It carries one row per dataset, and the example
above is the small row written out::

.. tab:: Lightning
torchrun --nproc_per_node=8 -m benchmarks.simclr.benchmark \
--train-dir /datasets/imagenet/train --val-dir /datasets/imagenet/val

.. image:: https://img.shields.io/badge/Open%20in%20Colab-blue?logo=googlecolab&label=%20&labelColor=5c5c5c
:target: https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning/simclr.ipynb
The two files restate each other rather than one importing the other, and
``tests/test_simclr_agrees.py`` is what holds them to the same method. They do
not share numbers: the example is small enough to run on one GPU, the benchmark
is the paper.

This example can be run from the command line with::

python lightly/examples/pytorch_lightning/simclr.py

.. literalinclude:: ../../../examples/pytorch_lightning/simclr.py

.. tab:: Lightning Distributed

.. image:: https://img.shields.io/badge/Open%20in%20Colab-blue?logo=googlecolab&label=%20&labelColor=5c5c5c
:target: https://colab.research.google.com/github/lightly-ai/lightly/blob/master/examples/notebooks/pytorch_lightning_distributed/simclr.ipynb

This example runs on multiple gpus using Distributed Data Parallel (DDP)
training with Pytorch Lightning. At least one GPU must be available on
the system. The example can be run from the command line with::

python lightly/examples/pytorch_lightning_distributed/simclr.py

The model differs in the following ways from the non-distributed
implementation:

- Distributed Data Parallel is enabled
- Synchronized Batch Norm is used in place of standard Batch Norm
- Features are gathered from all GPUs before the loss is calculated

Note that Synchronized Batch Norm and feature gathering are optional and
the model can also be trained without them. Without Synchronized Batch
Norm and feature gathering the batch norm and loss for each GPU are
only calculated based on the features on that specific GPU.

.. literalinclude:: ../../../examples/pytorch_lightning_distributed/simclr.py
For configured training on your own data with any backbone, use
`LightlyTrain <https://docs.lightly.ai/train/stable/>`_.
Loading
Loading