mmselfsup/tests/test_models/test_necks/test_nonlinear_neck.py

41 lines
1.3 KiB
Python
Raw Normal View History

2021-12-15 19:07:01 +08:00
# Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmselfsup.models.necks import NonLinearNeck
def test_nonlinear_neck():
# test neck arch
neck = NonLinearNeck(16, 32, 16, norm_cfg=dict(type='BN1d'))
assert neck.fc0.in_features == 16
assert neck.fc0.out_features == 32
assert neck.bn0.num_features == 32
fc = getattr(neck, neck.fc_names[-1])
assert fc.out_features == 16
# test neck with avgpool
fake_in = torch.rand((32, 16, 5, 5))
fake_out = neck.forward([fake_in])
assert fake_out[0].shape == torch.Size([32, 16])
# test neck without avgpool
neck = NonLinearNeck(
16, 32, 16, with_avg_pool=False, norm_cfg=dict(type='BN1d'))
fake_in = torch.rand((32, 16))
fake_out = neck.forward([fake_in])
assert fake_out[0].shape == torch.Size([32, 16])
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
# test neck with vit_backbone
neck = NonLinearNeck(
in_channels=16,
hid_channels=32,
out_channels=16,
with_avg_pool=False,
norm_cfg=dict(type='BN1d'),
vit_backbone=True)
fake_cls_token = torch.rand((32, 16))
fake_patch_token = torch.rand((32, 16, 14, 14))
fake_in = [fake_patch_token, fake_cls_token]
fake_out = neck.forward([fake_in])
assert fake_out[0].shape == torch.Size([32, 16])