mmpretrain/configs/simclr
Yixiao Fang 08dc8c75d3
[Refactor] Add selfsup algorithms. (#1389)
* remove basehead

* add moco series

* add byol simclr simsiam

* add ut

* update configs

* add simsiam hook

* add and refactor beit

* update ut

* add cae

* update extract_feat

* refactor cae

* add mae

* refactor data preprocessor

* update heads

* add maskfeat

* add milan

* add simmim

* add mixmim

* fix lint

* fix ut

* fix lint

* add eva

* add densecl

* add barlowtwins

* add swav

* fix lint

* update readtherdocs rst

* update docs

* update

* Decrease UT memory usage

* Fix docstring

* update DALLEEncoder

* Update model docs

* refactor dalle encoder

* update docstring

* fix ut

* fix config error

* add val_cfg and test_cfg

* refactor clip generator

* fix lint

* pass check

* fix ut

* add lars

* update type of BEiT in configs

* Use MMEngine style momentum in EMA.

* apply mmpretrain solarize

---------

Co-authored-by: mzr1996 <mzr1996@163.com>
2023-03-06 16:53:15 +08:00
..
benchmarks [Refactor] Move transforms in mmselfsup to mmpretrain. (#1396) 2023-03-03 15:01:11 +08:00
README.md [Docs] Update generate_readme.py and readme files. (#1388) 2023-03-02 13:29:07 +08:00
metafile.yml [Refactor] Refactor configs and metafile (#1369) 2023-02-23 11:17:16 +08:00
simclr_resnet50_8xb32-coslr-200e_in1k.py [Refactor] Add selfsup algorithms. (#1389) 2023-03-06 16:53:15 +08:00
simclr_resnet50_16xb256-coslr-200e_in1k.py [Refactor] Add selfsup algorithms. (#1389) 2023-03-06 16:53:15 +08:00
simclr_resnet50_16xb256-coslr-800e_in1k.py [Refactor] Add selfsup algorithms. (#1389) 2023-03-06 16:53:15 +08:00

README.md

SimCLR

A simple framework for contrastive learning of visual representations

Abstract

This paper presents SimCLR: a simple framework for contrastive learning of visual representations. We simplify recently proposed contrastive self-supervised learning algorithms without requiring specialized architectures or a memory bank. In order to understand what enables the contrastive prediction tasks to learn useful representations, we systematically study the major components of our framework. We show that (1) composition of data augmentations plays a critical role in defining effective predictive tasks, (2) introducing a learnable nonlinear transformation between the representation and the contrastive loss substantially improves the quality of the learned representations, and (3) contrastive learning benefits from larger batch sizes and more training steps compared to supervised learning. By combining these findings, we are able to considerably outperform previous methods for self-supervised and semi-supervised learning on ImageNet. A linear classifier trained on self-supervised representations learned by SimCLR achieves 76.5% top-1 accuracy, which is a 7% relative improvement over previous state-of-the-art, matching the performance of a supervised ResNet-50.

How to use it?

Predict image

from mmpretrain import inference_model

predict = inference_model('resnet50_simclr-200e-pre_8xb512-linear-coslr-90e_in1k', 'demo/bird.JPEG')
print(predict['pred_class'])
print(predict['pred_score'])

Use the model

import torch
from mmpretrain import get_model

model = get_model('simclr_resnet50_16xb256-coslr-200e_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))

Train/Test Command

Prepare your dataset according to the docs.

Train:

python tools/train.py configs/simclr/simclr_resnet50_16xb256-coslr-200e_in1k.py

Test:

python tools/test.py configs/simclr/benchmarks/resnet50_8xb512-linear-coslr-90e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/simclr/simclr_resnet50_16xb256-coslr-200e_in1k/resnet50_linear-8xb512-coslr-90e_in1k/resnet50_linear-8xb512-coslr-90e_in1k_20220825-f12c0457.pth

Models and results

Pretrained models

Model Params (M) Flops (G) Config Download
simclr_resnet50_16xb256-coslr-200e_in1k N/A N/A config model | log
simclr_resnet50_16xb256-coslr-800e_in1k N/A N/A config model | log

Image Classification on ImageNet-1k

Model Pretrain Params (M) Flops (G) Top-1 (%) Config Download
resnet50_simclr-200e-pre_8xb512-linear-coslr-90e_in1k SIMCLR 200-Epochs N/A N/A 66.90 config model | log
resnet50_simclr-800e-pre_8xb512-linear-coslr-90e_in1k SIMCLR 800-Epochs N/A N/A 69.20 config model | log

Citation

@inproceedings{chen2020simple,
  title={A simple framework for contrastive learning of visual representations},
  author={Chen, Ting and Kornblith, Simon and Norouzi, Mohammad and Hinton, Geoffrey},
  booktitle={ICML},
  year={2020},
}