mmpretrain/configs/mocov2
Yixiao Fang 1ee9bbe050
[Docs] Update links (#1457)
* update links

* update readtherdocs

* update

* update

* fix lint

* update

* update

* update

* update cov branch

* update

* update

* update
2023-04-06 20:58:52 +08:00
..
benchmarks [Refactor] Move transforms in mmselfsup to mmpretrain. (#1396) 2023-03-03 15:01:11 +08:00
README.md [Docs] Update links (#1457) 2023-04-06 20:58:52 +08:00
metafile.yml [Refactor] Update dev scripts to be compatible with selfsup tasks. (#1412) 2023-03-20 14:30:57 +08:00
mocov2_resnet50_8xb32-coslr-200e_in1k.py [Fix] Fix init bug of r50 in contrastive leanrning (#1445) 2023-03-29 15:49:51 +08:00

README.md

MoCoV2

Improved Baselines with Momentum Contrastive Learning

Abstract

Contrastive unsupervised learning has recently shown encouraging progress, e.g., in Momentum Contrast (MoCo) and SimCLR. In this note, we verify the effectiveness of two of SimCLRs design improvements by implementing them in the MoCo framework. With simple modifications to MoCo—namely, using an MLP projection head and more data augmentation—we establish stronger baselines that outperform SimCLR and do not require large training batches. We hope this will make state-of-the-art unsupervised learning research more accessible.

How to use it?

Predict image

from mmpretrain import inference_model

predict = inference_model('resnet50_mocov2-pre_8xb32-linear-steplr-100e_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('mocov2_resnet50_8xb32-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/mocov2/mocov2_resnet50_8xb32-coslr-200e_in1k.py

Test:

python tools/test.py configs/mocov2/benchmarks/resnet50_8xb32-linear-steplr-100e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/mocov2/mocov2_resnet50_8xb32-coslr-200e_in1k/resnet50_linear-8xb32-steplr-100e_in1k/resnet50_linear-8xb32-steplr-100e_in1k_20220825-994c4128.pth

Models and results

Pretrained models

Model Params (M) Flops (G) Config Download
mocov2_resnet50_8xb32-coslr-200e_in1k 55.93 4.11 config model | log

Image Classification on ImageNet-1k

Model Pretrain Params (M) Flops (G) Top-1 (%) Config Download
resnet50_mocov2-pre_8xb32-linear-steplr-100e_in1k MOCOV2 25.56 4.11 67.50 config model | log

Citation

@article{chen2020improved,
  title={Improved baselines with momentum contrastive learning},
  author={Chen, Xinlei and Fan, Haoqi and Girshick, Ross and He, Kaiming},
  journal={arXiv preprint arXiv:2003.04297},
  year={2020}
}