SimCLR/README.md

46 lines
2.9 KiB
Markdown
Raw Normal View History

2020-03-17 07:28:24 +08:00
# PyTorch SimCLR: A Simple Framework for Contrastive Learning of Visual Representations
2020-03-07 23:01:58 +08:00
### Blog post with full documentation: [Exploring SimCLR: A Simple Framework for Contrastive Learning of Visual Representations](https://sthalles.github.io/simple-self-supervised-learning/)
2020-03-07 22:56:34 +08:00
![Image of SimCLR Arch](https://sthalles.github.io/assets/contrastive-self-supervised/cover.png)
2020-06-20 00:04:17 +08:00
### See also [PyTorch Implementation for BYOL - Bootstrap Your Own Latent: A New Approach to Self-Supervised Learning](https://github.com/sthalles/PyTorch-BYOL).
2020-06-18 23:16:09 +08:00
2020-03-14 10:12:08 +08:00
## Installation
2020-03-07 23:01:58 +08:00
2020-03-14 10:11:07 +08:00
```
2020-04-15 22:50:06 +08:00
$ conda env create --name simclr --file env.yml
2020-03-14 10:11:07 +08:00
$ conda activate simclr
$ python run.py
```
2020-02-25 19:49:51 +08:00
## Config file
2021-01-18 18:33:12 +08:00
Before running SimCLR, make sure you choose the correct running configurations. You can change the running configurations by passing keyword arguments to the ```run.py``` file.
```python
$ python run.py -data ./datasets --dataset-name stl10 --log-every-n-steps 100 --epochs 100
2020-02-25 19:49:51 +08:00
```
2020-02-25 19:53:40 +08:00
2021-01-18 18:33:12 +08:00
If you want to run it on CPU (for debugging purposes) use the ```--disable-cuda``` option.
2021-01-18 18:39:39 +08:00
For 16-bit precision GPU training, make sure to install [NVIDIA apex](https://github.com/NVIDIA/apex) and use the ```--fp16_precision``` flag.
2021-01-18 18:38:08 +08:00
2020-02-25 19:53:40 +08:00
## Feature Evaluation
2020-03-14 07:33:50 +08:00
Feature evaluation is done using a linear model protocol.
2021-01-18 18:33:12 +08:00
First, we learned features using SimCLR on the ```STL10 unsupervised``` set. Then, we train a linear classifier on top of the frozen features from SimCLR. The linera model is trained on features extracted from the ```STL10 train``` set and evaluated on the ```STL10 test``` set.
2020-03-07 22:52:02 +08:00
2021-01-18 18:33:12 +08:00
Check the [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://github.com/sthalles/SimCLR/blob/simclr-refactor/feature_eval/mini_batch_logistic_regression_evaluator.ipynb) notebook for reproducibility.
2020-03-14 07:33:50 +08:00
2021-01-18 18:48:52 +08:00
Note that SimCLR benefits from **longer training**.
2020-03-14 22:31:37 +08:00
2021-01-18 18:35:02 +08:00
| Linear Classification | Dataset | Feature Extractor | Architecture | Feature dimensionality | Projection Head dimensionality | Epochs | Top1 % |
2021-01-18 18:33:12 +08:00
|----------------------------|---------|-------------------|---------------------------------------------------------------------------------|------------------------|--------------------------------|--------|--------|
| Logistic Regression (Adam) | STL10 | SimCLR | [ResNet-18](https://drive.google.com/open?id=14_nH2FkyKbt61cieQDiSbBVNP8-gtwgF) | 512 | 128 | 100 | 70.45 |
| Logistic Regression (Adam) | CIFAR10 | SimCLR | [ResNet-18](https://drive.google.com/open?id=1lc2aoVtrAetGn0PnTkOyFzPCIucOJq7C) | 512 | 128 | 100 | 64.82 |
2021-01-18 18:39:39 +08:00
| Logistic Regression (Adam) | STL10 | SimCLR | [ResNet-50](https://drive.google.com/open?id=1ByTKAUsdm_X7tLcii6oAEl5qFRqRMZSu) | 2048 | 128 | 50 | 67.075 |