Jiahao Xie fc69e38009
Bump version to v0.6.0 (#199)
* [Feature] Add MoCo v3 (#194)

* [Feature] add position embedding function

* [Fature] modify nonlinear neck for vit backbone

* [Feature] add mocov3 head

* [Feature] modify cls_head for vit backbone

* [Feature] add ViT backbone

* [Feature] add mocov3 algorithm

* [Docs] revise BYOL hook docstring

* [Feature] add mocov3 vit small config files

* [Feature] add mocov3 vit small linear eval config files

* [Fix] solve conflict

* [Fix] add mmcls

* [Fix] fix docstring format

* [Fix] fix isort

* [Fix] add mmcls to runtime requirements

* [Feature] remove duplicated codes

* [Feature] add mocov3 related unit test

* [Feature] revise position embedding function

* [Feature] add UT codes

* [Docs] add README.md

* [Docs] add model links and results to model zoo

* [Docs] fix model links

* [Docs] add metafile

* [Docs] modify install.md and add mmcls requirements

* [Docs] modify description

* [Fix] using specific arch name `mocov3-small`  rather than general arch name `small`

* [Fix] add mmcls

* [Fix] fix arch name

* [Feature] change name to `MoCoV3`

* [Fix] fix unit test bug

* [Feature] change `BYOLHook` name to `MomentumUpdateHook`

* [Feature] change name to MoCoV3

* [Docs] modify description

Co-authored-by: fangyixiao18 <fangyx18@hotmail.com>
Co-authored-by: Yixiao Fang <36138628+fangyixiao18@users.noreply.github.com>

* [Docs] update model zoo results (#195)

* Bump version to v0.6.0 (#198)

* [Docs] update model zoo results

* Bump version to v0.6.0

Co-authored-by: fangyixiao18 <fangyx18@hotmail.com>
Co-authored-by: Yixiao Fang <36138628+fangyixiao18@users.noreply.github.com>
2022-02-02 11:16:06 +08:00

55 lines
1.4 KiB
Python

# Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmselfsup.models import MoCoV3
backbone = dict(
type='VisionTransformer',
arch='mocov3-small', # embed_dim = 384
img_size=224,
patch_size=16,
stop_grad_conv1=True)
neck = dict(
type='NonLinearNeck',
in_channels=384,
hid_channels=8,
out_channels=8,
num_layers=2,
with_bias=False,
with_last_bn=True,
with_last_bn_affine=False,
with_last_bias=False,
with_avg_pool=False,
vit_backbone=True)
head = dict(
type='MoCoV3Head',
predictor=dict(
type='NonLinearNeck',
in_channels=8,
hid_channels=8,
out_channels=8,
num_layers=2,
with_bias=False,
with_last_bn=True,
with_last_bn_affine=False,
with_last_bias=False,
with_avg_pool=False),
temperature=0.2)
def test_mocov3():
with pytest.raises(AssertionError):
alg = MoCoV3(backbone=backbone, neck=None, head=head)
with pytest.raises(AssertionError):
alg = MoCoV3(backbone=backbone, neck=neck, head=None)
alg = MoCoV3(backbone, neck, head)
alg.init_weights()
alg.momentum_update()
fake_input = torch.randn((16, 3, 224, 224))
fake_backbone_out = alg.extract_feat(fake_input)
assert fake_backbone_out[0][0].size() == torch.Size([16, 384, 14, 14])
assert fake_backbone_out[0][1].size() == torch.Size([16, 384])