repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_extractor.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner from torch.utils.data import Dataset from mmselfsup.core.optimizer import build_optimizer ...
1,805
27.21875
76
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_extract_process.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import MagicMock import pytest import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from torch.utils.data import DataLoader, Dataset from mmselfsup.models.utils import ExtractProcess, MultiExtractProcess class ExampleDataset(D...
2,293
29.184211
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_byol_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner, obj_from_dict from torch.utils.data import DataLoader, Dataset from mmselfsup.core.hooks ...
2,565
31.075
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_deepcluster_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner from torch.utils.data import Dataset from mmselfsup.core.hooks import DeepClusterHook from mmselfsup.core.optimi...
2,405
29.075
76
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_optimizer_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import pytest import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner, obj_from_dict from torch.utils.data import DataLoader, Dataset from mmselfs...
4,247
32.448819
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_densecl_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner, obj_from_dict from torch.utils.data import DataLoader, Dataset from mmselfsup.core.hooks ...
2,135
29.084507
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_swav_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner, obj_from_dict from torch.utils.data import DataLoader, Dataset from mmselfsup.core.hooks ...
2,383
29.961039
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_runtime/test_hooks/test_simsiam_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import torch import torch.nn as nn from mmcv.parallel import MMDataParallel from mmcv.runner import build_runner from torch.utils.data import DataLoader, Dataset from mmselfsup.core.hooks import SimSiamH...
2,364
29.320513
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_heads.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn.functional as F from mmselfsup.models.heads import (ClsHead, ContrastiveHead, LatentClsHead, LatentCrossCorrelationHead, LatentPredictHead, MAEFinetuneHead, ...
4,331
27.88
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_backbones/test_resnet.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmselfsup.models.backbones import ResNet from mmselfsup.models.backbones.resnet import BasicBlock, Bottleneck def is_block(modules): """Check if is ResNet building block.""" if isinstance(modul...
4,443
30.742857
68
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_backbones/test_mae_pretrain_vit.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.backbones import MAEViT backbone = dict(arch='b', patch_size=16, mask_ratio=0.75) @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_mae_pretrain_vit(): mae_pre...
555
26.8
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_backbones/test_mim_cls_vit.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.backbones import MIMVisionTransformer finetune_backbone = dict( arch='b', patch_size=16, drop_path_rate=0.1, final_norm=False) finetune_backbone_norm = dict( arch='b', patch_size=16, drop_path_ra...
1,600
38.04878
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_backbones/test_maskfeat_pretrain_vit.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.backbones import MaskFeatViT backbone = dict(arch='b', patch_size=16) @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_maskfeat_pretrain_vit(): maskfeat_pretr...
618
28.47619
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_backbones/test_resnext.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmselfsup.models.backbones import ResNeXt from mmselfsup.models.backbones.resnext import Bottleneck as BottleneckX def test_resnext(): with pytest.raises(KeyError): # ResNeXt depth should be in [50, 101, 152] ResNeXt(...
1,462
32.25
78
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_byol.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import BYOL backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type='NonLinearNeck...
1,546
27.648148
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_mocov3.py
# Copyright (c) OpenMMLab. All rights reserved. import platform 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...
1,544
25.637931
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_odc.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import ODC num_classes = 5 backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type...
1,424
24.909091
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_swav.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import SwAV nmb_crops = [2, 6] backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN'), zero_init_res...
1,565
26.964286
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_maskfeat.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import MaskFeat backbone = dict( type='MaskFeatViT', arch='b', patch_size=16, drop_path_rate=0, ) head = dict(type='MaskFeatPretrainHead', hog_dim=108) hog_para = dict(nbins=9, ...
1,074
30.617647
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_simmim.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import SimMIM @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_simmim(): # model config model_config = dict( backbone=dict( ...
868
28.965517
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_relative_loc.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import RelativeLoc backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type='Relati...
1,831
32.309091
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_rotation_pred.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import RotationPred backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) head = dict(type='ClsHead', ...
1,485
31.304348
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_classification.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import Classification @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_classification(): # test ResNet with_sobel = True, backbone = dict( ...
1,659
27.62069
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_barlowtwins.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import BarlowTwins backbone = dict( type='ResNet', depth=50, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type='NonLin...
1,393
29.977778
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_simsiam.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import SimSiam backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN'), zero_init_residual=True) neck...
1,704
26.95082
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_deepcluster.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import DeepCluster num_classes = 5 with_sobel = True, backbone = dict( type='ResNet', depth=18, in_channels=2, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='...
1,373
28.869565
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_densecl.py
# Copyright (c) OpenMMLab. All rights reserved. import platform from unittest.mock import MagicMock import pytest import torch import mmselfsup from mmselfsup.models.algorithms import DenseCL queue_len = 32 feat_dim = 2 momentum = 0.999 loss_lambda = 0.5 backbone = dict( type='ResNet', depth=18, in_chann...
2,689
28.56044
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_npid.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import NPID backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type='LinearNeck', ...
1,185
31.944444
77
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_simclr.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import SimCLR backbone = dict( type='ResNet', depth=18, in_channels=3, out_indices=[4], # 0: conv-1, x: stage-x norm_cfg=dict(type='BN')) neck = dict( type='NonLinearNe...
1,171
28.3
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_cae.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import CAE # model settings backbone = dict( type='CAEViT', arch='b', patch_size=16, init_values=0.1, qkv_bias=False) neck = dict( type='CAENeck', patch_size=16, embed_dims=768,...
1,421
28.020408
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_moco.py
# Copyright (c) OpenMMLab. All rights reserved. import platform from unittest.mock import MagicMock import pytest import torch import mmselfsup from mmselfsup.models.algorithms import MoCo queue_len = 32 feat_dim = 2 momentum = 0.999 backbone = dict( type='ResNet', depth=18, in_channels=3, out_indice...
1,991
26.666667
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_mmcls_classifier_wrapper.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import mmcls.models # noqa: F401 import pytest import torch from mmselfsup.models import ALGORITHMS @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_mmcls_classifier_wrapper(): model_config = dict( t...
1,948
32.033898
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_algorithms/test_mae.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.algorithms import MAE backbone = dict(type='MAEViT', arch='b', patch_size=16, mask_ratio=0.75) neck = dict( type='MAEPretrainDecoder', patch_size=16, in_chans=3, embed_dim=768, decoder...
1,310
30.97561
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_utils/test_knn_classifier.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.utils import knn_classifier def test_knn_classifier(): train_feats = torch.ones(200, 3) train_labels = torch.ones(200).long() test_feats = torch.ones(200, 3) test_labels = torch.ones(200).long() num_knn = [10, 20, ...
541
29.111111
74
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_utils/test_dalle.py
# Copyright (c) OpenMMLab. All rights reserved. import platform import pytest import torch from mmselfsup.models.utils import Encoder @pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit') def test_dalle(): model = Encoder() fake_inputs = torch.rand((2, 3, 112, 112)) fake_output...
401
22.647059
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_utils/test_multi_pooling.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmselfsup.models.utils import MultiPooling def test_multi_pooling(): # adaptive layer = MultiPooling(pool_type='adaptive', in_indices=(0, 1, 2)) fake_in = [ torch.rand((1, 32, 112, 112)), torch.rand((1, 64, 56...
1,094
27.815789
69
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_utils/test_multi_prototypes.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch import torch.nn as nn from mmselfsup.models.utils import MultiPrototypes def test_multi_prototypes(): with pytest.raises(AssertionError): layer = MultiPrototypes(output_dim=16, num_prototypes=2) layer = MultiPrototypes(output...
746
30.125
68
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_utils/test_sobel.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.utils import Sobel def test_sobel(): sobel_layer = Sobel() fake_input = torch.rand((1, 3, 224, 224)) fake_res = sobel_layer(fake_input) assert fake_res.shape == (1, 2, 224, 224) for p in sobel_layer.sobel.paramete...
366
23.466667
47
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_linear_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmselfsup.models.necks import LinearNeck def test_linear_neck(): neck = LinearNeck(16, 32, with_avg_pool=True) assert isinstance(neck.avgpool, nn.Module) assert neck.fc.in_features == 16 assert neck.fc.out_feature...
702
28.291667
52
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_relative_loc_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.necks import RelativeLocNeck def test_relative_loc_neck(): neck = RelativeLocNeck(16, 32) assert neck.fc.in_features == 32 assert neck.fc.out_features == 32 assert neck.bn.num_features == 32 # test neck with avgpo...
672
28.26087
55
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_odc_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.necks import ODCNeck def test_odc_neck(): neck = ODCNeck(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 assert neck.f...
783
30.36
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_densecl_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmselfsup.models.necks import DenseCLNeck def test_densecl_neck(): neck = DenseCLNeck(16, 32, 16) assert isinstance(neck.mlp, nn.Sequential) assert isinstance(neck.mlp2, nn.Sequential) assert neck.mlp[0].in_featur...
1,153
33.969697
56
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_swav_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmselfsup.models.necks import SwAVNeck def test_swav_neck(): neck = SwAVNeck(16, 32, 16, norm_cfg=dict(type='BN1d')) assert isinstance(neck.projection_neck, (nn.Module, nn.Sequential)) # test neck with avgpool fa...
539
30.764706
74
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_mae_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.necks import MAEPretrainDecoder def test_linear_neck(): decoder = MAEPretrainDecoder() decoder.init_weights() decoder.eval() inputs = torch.rand(1, 50, 1024) ids_restore = torch.arange(0, 196).unsqueeze(0) leve...
424
27.333333
56
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_nonlinear_neck.py
# 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.b...
1,297
30.658537
68
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_avgpool_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.necks import AvgPool2dNeck def test_avgpool2d_neck(): fake_in = [torch.randn((2, 3, 8, 8))] # test default neck = AvgPool2dNeck() fake_out = neck(fake_in) assert fake_out[0].shape == (2, 3, 1, 1) # test custo...
550
21.958333
48
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_models/test_necks/test_mocov2_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmselfsup.models.necks import MoCoV2Neck def test_mocov2_neck(): neck = MoCoV2Neck(16, 32, 16) assert isinstance(neck.mlp, nn.Sequential) assert neck.mlp[0].in_features == 16 assert neck.mlp[2].in_features == 32 ...
739
28.6
54
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_apis/test_train.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import platform import tempfile import time import mmcv import pytest import torch import torch.nn as nn from mmcv import Config from torch.utils.data import Dataset from mmselfsup.apis import init_random_seed, set_random_seed, train_model class ...
2,928
25.387387
103
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_apis/test_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import platform import pytest import torch import torch.nn as nn from mmcv import Config from PIL import Image from mmselfsup.apis import inference_model from mmselfsup.models import BaseModel class ExampleModel(BaseModel): def __init__(self...
1,548
24.816667
99
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_data/test_pipeline.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch from mmcv.utils import build_from_cfg from PIL import Image from mmselfsup.datasets.builder import PIPELINES def test_random_applied_trans(): img = Image.fromarray(np.ones((224, 224, 3), dtype=np.uint8)) # p=0.5 ...
5,715
27.58
77
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_utils/test_misc.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import tempfile import pytest import torch from mmselfsup.utils.misc import find_latest_checkpoint, tensor2imgs def test_tensor2imgs(): with pytest.raises(AssertionError): tensor2imgs(torch.rand((3, 16, 16))) fake_tensor = torch.r...
1,842
31.910714
68
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_utils/test_alias_multinomial.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmselfsup.utils import AliasMethod def test_alias_multinomial(): example_in = torch.Tensor([1, 2, 3, 4]) example_alias_method = AliasMethod(example_in) assert (example_alias_method.prob.numpy() <= 1).all() assert len(exam...
644
28.318182
61
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_utils/test_test_helper.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import MagicMock import numpy as np import torch import torch.nn as nn from torch.utils.data import DataLoader, Dataset from mmselfsup.utils.test_helper import single_gpu_test class ExampleDataset(Dataset): def __getitem__(self, idx): r...
1,174
24.543478
79
py
mmselfsup-0.x
mmselfsup-0.x/tests/test_metrics/test_accuracy.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmselfsup.models.utils import Accuracy def test_accuracy(): pred = torch.Tensor([[0.2, 0.3, 0.5], [0.25, 0.15, 0.6], [0.9, 0.05, 0.05], [0.8, 0.1, 0.1], [0.55, 0.15, 0.3]]) target = torch.zeros(5) acc = Accuracy((...
427
25.75
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/apis/inference.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Optional, Tuple, Union import mmcv import torch from mmcv.parallel import collate, scatter from mmcv.runner import load_checkpoint from mmcv.utils import build_from_cfg from PIL import Image from torch import nn from torchvision.transforms import Compo...
3,036
34.313953
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/apis/train.py
# Copyright (c) OpenMMLab. All rights reserved. import random import numpy as np import torch import torch.distributed as dist from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import (HOOKS, DistEvalHook, DistSamplerSeedHook, EvalHook, build_runner, get_dist...
8,228
36.747706
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/hooks/optimizer_hook.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.runner import (HOOKS, Fp16OptimizerHook, OptimizerHook, allreduce_grads) from mmcv.utils import TORCH_VERSION, _BatchNorm, digit_version @HOOKS.register_module() class DistOptimizerHook(OptimizerHook): """Optimizer hook for distrib...
10,923
40.694656
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/hooks/interclr_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.distributed as dist from mmcv.runner import HOOKS, Hook from mmcv.utils import print_log from mmselfsup.utils import Extractor from mmselfsup.utils import clustering as _clustering @HOOKS.register_module() class InterCLRHook...
7,998
42.005376
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/hooks/swav_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import torch import torch.distributed as dist from mmcv.runner import HOOKS, Hook @HOOKS.register_module() class SwAVHook(Hook): """Hook for SwAV. This hook builds the queue in SwAV according to ``epoch_queue_starts``. The queue will ...
3,060
36.329268
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/hooks/deepcluster_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.distributed as dist from mmcv.runner import HOOKS, Hook from mmcv.utils import print_log from mmselfsup.utils import Extractor from mmselfsup.utils import clustering as _clustering from mmselfsup.utils import get_root_logger ...
5,575
37.993007
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/optimizer/optimizers.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.runner.optimizer.builder import OPTIMIZERS from torch.optim import * # noqa: F401,F403 from torch.optim.optimizer import Optimizer, required @OPTIMIZERS.register_module() class LARS(Optimizer): """Implements layer-wise adaptive rate scaling f...
4,827
35.575758
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/optimizer/constructor.py
# Copyright (c) OpenMMLab. All rights reserved. import re import torch.distributed as dist from mmcv.runner.optimizer.builder import OPTIMIZER_BUILDERS, OPTIMIZERS from mmcv.utils import build_from_cfg, print_log @OPTIMIZER_BUILDERS.register_module(force=True) class DefaultOptimizerConstructor: """Rewrote defaul...
3,606
43.530864
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/optimizer/transformer_finetune_constructor.py
# Copyright (c) OpenMMLab. All rights reserved. import re import torch.distributed as dist from mmcv.runner.optimizer.builder import OPTIMIZER_BUILDERS, OPTIMIZERS from mmcv.utils import build_from_cfg, print_log @OPTIMIZER_BUILDERS.register_module() class TransformerFinetuneConstructor: """Rewrote default const...
6,889
42.607595
77
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/core/optimizer/builder.py
# Copyright (c) OpenMMLab. All rights reserved. import copy from mmcv.runner.optimizer.builder import build_optimizer_constructor def build_optimizer(model, optimizer_cfg): """Build optimizer from configs. Args: model (:obj:`nn.Module`): The model with parameters to be optimized. optimizer_c...
2,002
40.729167
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/base.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import ABCMeta, abstractmethod from collections import OrderedDict import torch import torch.distributed as dist from mmcv.runner import BaseModule, auto_fp16 class BaseModel(BaseModule, metaclass=ABCMeta): """Base model class for self-supervised learning....
5,902
35.89375
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/densecl.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.utils.logging import logger_initialized, print_log from mmselfsup.utils import (batch_shuffle_ddp, batch_unshuffle_ddp, concat_all_gather) from ..builder import ALGORITHMS, build_backbone, build_he...
9,241
36.266129
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/simclr.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from ..utils import GatherLayer from .base import BaseModel @ALGORITHMS.register_module() class SimCLR(BaseModel): """SimCLR. Implementation of `A Simple Framework for Contra...
3,191
34.466667
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/mae.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Dict, Optional, Tuple import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class MAE(BaseModel): """MAE. Implementation of `Masked Autoencoders Are S...
3,194
33.354839
73
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/rotation_pred.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.runner import auto_fp16 from ..builder import ALGORITHMS, build_backbone, build_head from .base import BaseModel @ALGORITHMS.register_module() class RotationPred(BaseModel): """Rotation prediction. Implementation of `Unsupervised Represe...
3,354
33.587629
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/mocov3.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class MoCoV3(BaseModel): """MoCo v3. Implementation of `An Empirical Study of Training Self-Su...
3,769
34.233645
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/barlowtwins.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import List, Optional import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class BarlowTwins(BaseModel): """BarlowTwins. Implementation of `Barlow Twins: Se...
2,478
32.053333
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/deepcluster.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.nn as nn from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from ..utils import Sobel from .base import BaseModel @ALGORITHMS.register_module() class DeepCluster(BaseModel): """DeepCluster. Imp...
4,071
33.218487
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/relative_loc.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class RelativeLoc(BaseModel): """Relative patch location. Implementation of `Unsupervised Visual Representation Lear...
3,876
35.233645
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/moco.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmselfsup.utils import (batch_shuffle_ddp, batch_unshuffle_ddp, concat_all_gather) from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.regi...
5,124
33.166667
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/simsiam.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class SimSiam(BaseModel): """SimSiam. Implementation of `Exploring Simple Siamese Representation Learning ...
2,240
30.125
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/simmim.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import List, Optional import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class SimMIM(BaseModel): """SimMIM. Implementation of `SimMIM: A Simple Framework...
1,952
29.046154
75
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/maskfeat.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import List, Optional import torch from ..builder import ALGORITHMS, build_backbone, build_head from ..utils.hog_layer import HOGLayerC from .base import BaseModel @ALGORITHMS.register_module() class MaskFeat(BaseModel): """MaskFeat. Implementatio...
2,324
31.746479
77
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/swav.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class SwAV(BaseModel): """SwAV. Implementation of `Unsupervised Learning of Visual Features by Contrasting Clust...
2,393
30.090909
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/cae.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Sequence import torch from torchvision.transforms import Normalize from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class CAE(BaseModel): """CAE. Implementati...
4,123
36.490909
77
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/mmcls_classifier_wrapper.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcls.models import ImageClassifier from mmcv.runner import auto_fp16 from ..builder import ALGORITHMS @ALGORITHMS.register_module() class MMClsImageClassifierWrapper(ImageClassifier): """Workaround to use models from mmclassificaiton. Since ...
4,003
35.4
78
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/interclr_moco.py
# Copyright (c) OpenMMLab. All rights reserved. import math import numpy as np import torch import torch.nn as nn from mmselfsup.utils import (batch_shuffle_ddp, batch_unshuffle_ddp, concat_all_gather) from ..builder import (ALGORITHMS, build_backbone, build_head, build_memory, ...
19,120
41.303097
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/npid.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from ..builder import (ALGORITHMS, build_backbone, build_head, build_memory, build_neck) from .base import BaseModel @ALGORITHMS.register_module() class NPID(BaseModel): """NPID. Implementation of `Unsu...
3,946
34.558559
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/byol.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from ..builder import ALGORITHMS, build_backbone, build_head, build_neck from .base import BaseModel @ALGORITHMS.register_module() class BYOL(BaseModel): """BYOL. Implementation of `Bootstrap Your Own Latent: A New Approach t...
3,490
33.564356
75
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/algorithms/odc.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.nn as nn from ..builder import (ALGORITHMS, build_backbone, build_head, build_memory, build_neck) from ..utils import Sobel from .base import BaseModel @ALGORITHMS.register_module() class ODC(BaseModel...
5,013
34.814286
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/relative_loc_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class RelativeLocNeck(BaseModule): """The neck of relative patch location: fc-bn-relu-dropout. Args: in_...
1,885
32.678571
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/swav_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class SwAVNeck(BaseModule): """The non-linear neck of SwAV: fc-bn-relu-fc-normalization. Args: ...
2,733
35.453333
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/odc_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class ODCNeck(BaseModule): """The non-linear neck of ODC: fc-bn-relu-dropout-fc-relu. Args: in_channels ...
2,010
32.516667
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/mocov2_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class MoCoV2Neck(BaseModule): """The non-linear neck of MoCo v2: fc-relu-fc. Args: in_channels (int): Number of input channels. hid_ch...
1,354
31.261905
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/simmim_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class SimMIMNeck(BaseModule): """Pre-train Neck For SimMIM. This neck reconstructs the original image from the shrunk feature map. A...
921
25.342857
74
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/linear_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class LinearNeck(BaseModule): """The linear neck: fc only. Args: in_channels (int): Number of input channels. out_channels (int): Numb...
1,146
29.184211
76
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/nonlinear_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class NonLinearNeck(BaseModule): """The non-linear neck. Structure: fc-bn-[relu-fc-bn] where the substructure in...
4,223
37.4
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/avgpool2d_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class AvgPool2dNeck(BaseModule): """The average pooling 2d neck.""" def __init__(self, output_size=1): super(AvgPool2dNeck, self).__init__() ...
498
23.95
56
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/cae_neck.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Tuple import torch import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.cnn.utils.weight_init import trunc_normal_ from mmcv.runner import BaseModule from ..builder import NECKS from ..utils import CAETransformerRegressorLayer, Transf...
6,546
37.739645
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/densecl_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.runner import BaseModule from ..builder import NECKS @NECKS.register_module() class DenseCLNeck(BaseModule): """The non-linear neck of DenseCL. Single and dense neck in parallel: fc-relu-fc, conv-relu-conv. Borrowed from the...
2,202
33.968254
77
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/necks/mae_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcls.models.backbones.vision_transformer import TransformerEncoderLayer from mmcv.cnn import build_norm_layer from mmcv.runner import BaseModule from ..builder import NECKS from ..utils import build_2d_sincos_position_embedding ...
4,735
33.569343
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/memories/simple_memory.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.distributed as dist import torch.nn as nn from mmcv.runner import BaseModule, get_dist_info from mmselfsup.utils import AliasMethod from ..builder import MEMORIES @MEMORIES.register_module() class SimpleMemory(BaseModule): """Simple memory...
2,494
34.642857
77
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/memories/odc_memory.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.distributed as dist from mmcv.runner import BaseModule, get_dist_info from sklearn.cluster import KMeans from ..builder import MEMORIES @MEMORIES.register_module() class ODCMemory(BaseModule): """Memory module for ODC. ...
10,403
44.038961
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/memories/interclr_memory.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.distributed as dist import torch.nn as nn from mmcv.runner import BaseModule, get_dist_info from sklearn.cluster import KMeans from mmselfsup.utils import AliasMethod from ..builder import MEMORIES @MEMORIES.register_module(...
11,583
44.427451
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/utils/dall_e.py
# Copyright (c) # https://github.com/microsoft/unilm/blob/master/beit/dall_e/encoder.py # Copied from BEiT import math from collections import OrderedDict from functools import partial import attr import torch import torch.nn as nn import torch.nn.functional as F @attr.s(eq=False) class Conv2d(nn.Module): n_in: ...
6,647
36.988571
79
py
mmselfsup-0.x
mmselfsup-0.x/mmselfsup/models/utils/position_embedding.py
# Copyright (c) OpenMMLab. All rights reserved. import torch def build_2d_sincos_position_embedding(patches_resolution, embed_dims, temperature=10000., cls_token=False): """The function is to build...
1,430
32.27907
75
py