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
mmpretrain
mmpretrain-master/mmcls/models/backbones/seresnext.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from .resnet import ResLayer from .seresnet import SEBottleneck as _SEBottleneck from .seresnet import SEResNet class SEBottleneck(_SEBottleneck): """SEBottleneck block for SERe...
6,673
41.782051
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/hornet.py
# Copyright (c) OpenMMLab. All rights reserved. # Adapted from official impl at https://github.com/raoyongming/HorNet. try: import torch.fft fft = True except ImportError: fft = None import copy from functools import partial from typing import Sequence import torch import torch.nn as nn import torch.nn.fu...
18,877
36.756
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/conformer.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Sequence import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_activation_layer, build_norm_layer from mmcv.cnn.bricks.drop import DropPath from mmcv.cnn.bricks.transformer import AdaptivePadding from mmcv.cnn.ut...
22,874
35.483254
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/resnext.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from .resnet import Bottleneck as _Bottleneck from .resnet import ResLayer, ResNet class Bottleneck(_Bottleneck): """Bottleneck block for ResNeXt. Args: in_channels...
6,256
40.993289
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/t2t_vit.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from typing import Sequence import numpy as np import torch import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.transformer import FFN from mmcv.cnn.utils.weight_init import trunc_normal_ from mmcv.runner.base_module...
16,420
36.235828
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/vision_transformer.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Sequence import numpy as np import torch import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.transformer import FFN, PatchEmbed from mmcv.cnn.utils.weight_init import trunc_normal_ from mmcv.runner.base_module import BaseMo...
14,734
37.372396
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/mobilenet_v3.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import ConvModule from torch.nn.modules.batchnorm import _BatchNorm from ..builder import BACKBONES from ..utils import InvertedResidual from .base_backbone import BaseBackbone @BACKBONES.register_module() class MobileNetV3(BaseBackbone): """MobileNet...
7,608
37.821429
78
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/efficientformer.py
# Copyright (c) OpenMMLab. All rights reserved. import itertools from typing import Optional, Sequence import torch import torch.nn as nn from mmcv.cnn.bricks import (ConvModule, DropPath, build_activation_layer, build_norm_layer) from mmcv.runner import BaseModule, ModuleList, Sequential ...
22,131
35.461285
97
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/repmlp.py
# Copyright (c) OpenMMLab. All rights reserved. # Adapted from official impl at https://github.com/DingXiaoH/RepMLP. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import (ConvModule, build_activation_layer, build_conv_layer, build_norm_layer) from mmcv.cnn.bricks...
22,843
38.454231
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/twins.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import Conv2d, build_norm_layer from mmcv.cnn.bricks.drop import build_dropout from mmcv.cnn.bricks.transformer import FFN, PatchEmbed from mmcv.cnn.utils.weight_init import (con...
30,204
40.719613
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/resnest.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from .resnet import Bottleneck as _Bottleneck from .resnet import ResLayer, ResN...
12,231
34.976471
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/resnet_cifar.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from .resnet import ResNet @BACKBONES.register_module() class ResNet_CIFAR(ResNet): """ResNet backbone for CIFAR. Compared to standard ResNet, it uses...
3,707
44.219512
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/lenet.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from ..builder import BACKBONES from .base_backbone import BaseBackbone @BACKBONES.register_module() class LeNet5(BaseBackbone): """`LeNet5 <https://en.wikipedia.org/wiki/LeNet>`_ backbone. The input for LeNet-5 is a 32×32 grayscale image...
1,325
29.837209
67
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/shufflenet_v2.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import ConvModule, constant_init, normal_init from mmcv.runner import BaseModule from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.utils import channel_shuffle from ..b...
10,733
34.193443
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/convnext.py
# Copyright (c) OpenMMLab. All rights reserved. from functools import partial from itertools import chain from typing import Sequence import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from mmcv.cnn.bricks import (NORM_LAYERS, DropPath, build_activation_layer, ...
12,948
35.997143
94
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/res2net.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import build_conv_layer, build_norm_layer from mmcv.runner import ModuleList, Sequential from ..builder import BACKBONES from .resnet import Bottleneck as _Bottleneck from ....
10,770
34.084691
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/convmixer.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Sequence import torch import torch.nn as nn from mmcv.cnn.bricks import (Conv2dAdaptivePadding, build_activation_layer, build_norm_layer) from mmcv.utils import digit_version from ..builder import BACKBONES from .base_back...
6,184
33.943503
95
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/van.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import Conv2d, build_activation_layer, build_norm_layer from mmcv.cnn.bricks import DropPath from mmcv.cnn.bricks.transformer import PatchEmbed from mmcv.runner import BaseModule, ModuleList from mmcv.utils.parrots_wrapper ...
16,200
35.325112
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/poolformer.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Sequence import torch import torch.nn as nn from mmcv.cnn.bricks import DropPath, build_activation_layer, build_norm_layer from mmcv.runner import BaseModule from ..builder import BACKBONES from .base_backbone import BaseBackbone class PatchEmbed(nn...
14,699
34.251799
89
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/swin_transformer_v2.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from typing import Sequence import numpy as np import torch import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.transformer import FFN, PatchEmbed from mmcv.cnn.utils.weight_init i...
22,671
39.413547
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/cspnet.py
# Copyright (c) OpenMMLab. All rights reserved. import math from typing import Sequence import torch import torch.nn as nn from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule from mmcv.cnn.bricks import DropPath from mmcv.runner import BaseModule, Sequential from torch.nn.modules.batchnorm import _BatchNorm ...
25,481
36.473529
79
py
mmpretrain
mmpretrain-master/mmcls/models/backbones/alexnet.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from ..builder import BACKBONES from .base_backbone import BaseBackbone @BACKBONES.register_module() class AlexNet(BaseBackbone): """`AlexNet <https://en.wikipedia.org/wiki/AlexNet>`_ backbone. The input for AlexNet is a 224x224 RGB image...
1,884
32.070175
67
py
mmpretrain
mmpretrain-master/mmcls/models/heads/multi_label_csra_head.py
# Copyright (c) OpenMMLab. All rights reserved. # Modified from https://github.com/Kevinz-code/CSRA import torch import torch.nn as nn from mmcv.runner import BaseModule, ModuleList from ..builder import HEADS from .multi_label_head import MultiLabelClsHead @HEADS.register_module() class CSRAClsHead(MultiLabelClsHea...
4,250
33.844262
74
py
mmpretrain
mmpretrain-master/mmcls/models/heads/conformer_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from mmcv.cnn.utils.weight_init import trunc_normal_ from ..builder import HEADS from .cls_head import ClsHead @HEADS.register_module() class ConformerHead(ClsHead): """Linear classifier head. Args: ...
4,776
34.917293
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/multi_label_linear_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from ..builder import HEADS from .multi_label_head import MultiLabelClsHead @HEADS.register_module() class MultiLabelLinearClsHead(MultiLabelClsHead): """Linear classification head for multilabel task. Args: num_class...
2,948
33.290698
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/deit_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from mmcls.utils import get_root_logger from ..builder import HEADS from .vision_transformer_head import VisionTransformerClsHead @HEADS.register_module() class DeiTClsHead(VisionTransformerClsHead): """Distille...
3,951
39.742268
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/cls_head.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch import torch.nn.functional as F from mmcls.models.losses import Accuracy from ..builder import HEADS, build_loss from ..utils import is_tracing from .base_head import BaseHead @HEADS.register_module() class ClsHead(BaseHead): """classi...
3,939
32.675214
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/stacked_head.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Dict, Sequence import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_activation_layer, build_norm_layer from mmcv.runner import BaseModule, ModuleList from ..builder import HEADS from .cls_head import ClsHead class LinearB...
5,456
32.27439
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/multi_label_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..builder import HEADS, build_loss from ..utils import is_tracing from .base_head import BaseHead @HEADS.register_module() class MultiLabelClsHead(BaseHead): """Classification head for multilabel task. Args: loss (dict): Config of cla...
3,252
31.53
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/efficientformer_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from ..builder import HEADS from .cls_head import ClsHead @HEADS.register_module() class EfficientFormerClsHead(ClsHead): """EfficientFormer classifier head. Args: num_classes (int): Number of categ...
3,476
34.845361
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/linear_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from ..builder import HEADS from .cls_head import ClsHead @HEADS.register_module() class LinearClsHead(ClsHead): """Linear classifier head. Args: num_classes (int): Number of categories excluding th...
2,730
32.304878
79
py
mmpretrain
mmpretrain-master/mmcls/models/heads/vision_transformer_head.py
# Copyright (c) OpenMMLab. All rights reserved. import math from collections import OrderedDict import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_activation_layer from mmcv.cnn.utils.weight_init import trunc_normal_ from mmcv.runner import Sequential from ..builder import HEADS from .cl...
4,527
35.516129
79
py
mmpretrain
mmpretrain-master/mmcls/datasets/base_dataset.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import os.path as osp from abc import ABCMeta, abstractmethod from os import PathLike from typing import List import mmcv import numpy as np from torch.utils.data import Dataset from mmcls.core.evaluation import precision_recall_f1, support from mmcls.models...
7,686
33.626126
78
py
mmpretrain
mmpretrain-master/mmcls/datasets/dataset_wrappers.py
# Copyright (c) OpenMMLab. All rights reserved. import bisect import math from collections import defaultdict import numpy as np from mmcv.utils import print_log from torch.utils.data.dataset import ConcatDataset as _ConcatDataset from .builder import DATASETS @DATASETS.register_module() class ConcatDataset(_Concat...
12,464
36.432432
167
py
mmpretrain
mmpretrain-master/mmcls/datasets/builder.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import platform import random from functools import partial import numpy as np import torch from mmcv.parallel import collate from mmcv.runner import get_dist_info from mmcv.utils import Registry, build_from_cfg, digit_version from torch.utils.data import Dat...
6,438
33.994565
79
py
mmpretrain
mmpretrain-master/mmcls/datasets/cifar.py
# Copyright (c) OpenMMLab. All rights reserved. import os import os.path import pickle import numpy as np import torch.distributed as dist from mmcv.runner import get_dist_info from .base_dataset import BaseDataset from .builder import DATASETS from .utils import check_integrity, download_and_extract_archive @DATAS...
5,805
36.217949
79
py
mmpretrain
mmpretrain-master/mmcls/datasets/imagenet.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Optional, Sequence, Union from .builder import DATASETS from .custom import CustomDataset @DATASETS.register_module() class ImageNet(CustomDataset): """`ImageNet <http://www.image-net.org>`_ Dataset. The dataset supports two kinds of annotat...
35,468
32.461321
146
py
mmpretrain
mmpretrain-master/mmcls/datasets/mnist.py
# Copyright (c) OpenMMLab. All rights reserved. import codecs import os import os.path as osp import numpy as np import torch import torch.distributed as dist from mmcv.runner import get_dist_info, master_only from .base_dataset import BaseDataset from .builder import DATASETS from .utils import download_and_extract_...
6,416
33.5
97
py
mmpretrain
mmpretrain-master/mmcls/datasets/samplers/distributed_sampler.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.utils.data import DistributedSampler as _DistributedSampler from mmcls.core.utils import sync_random_seed from mmcls.datasets import SAMPLERS @SAMPLERS.register_module() class DistributedSampler(_DistributedSampler): def __init__(self, ...
2,242
35.770492
77
py
mmpretrain
mmpretrain-master/mmcls/datasets/samplers/repeat_aug.py
import math import torch from mmcv.runner import get_dist_info from torch.utils.data import Sampler from mmcls.core.utils import sync_random_seed from mmcls.datasets import SAMPLERS @SAMPLERS.register_module() class RepeatAugSampler(Sampler): """Sampler that restricts data loading to a subset of the dataset for...
4,228
38.523364
79
py
mmpretrain
mmpretrain-master/mmcls/datasets/pipelines/formatting.py
# Copyright (c) OpenMMLab. All rights reserved. from collections.abc import Sequence import mmcv import numpy as np import torch from mmcv.parallel import DataContainer as DC from PIL import Image from ..builder import PIPELINES def to_tensor(data): """Convert objects of various python types to :obj:`torch.Tens...
5,508
27.107143
78
py
mmpretrain
mmpretrain-master/mmcls/datasets/pipelines/auto_augment.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import inspect import random from math import ceil from numbers import Number from typing import Sequence import mmcv import numpy as np from ..builder import PIPELINES from .compose import Compose # Default hyperparameters for all Ops _HPARAMS_DEFAULT = di...
37,200
39.348156
79
py
mmpretrain
mmpretrain-master/mmcls/utils/setup_env.py
# Copyright (c) OpenMMLab. All rights reserved. import os import platform import warnings import cv2 import torch.multiprocessing as mp def setup_multi_processes(cfg): """Setup multi-processing environment variables.""" # set multi-process start method as `fork` to speed up the training if platform.syste...
2,219
45.25
112
py
mmpretrain
mmpretrain-master/mmcls/utils/distribution.py
# Copyright (c) OpenMMLab. All rights reserved. def wrap_non_distributed_model(model, device='cuda', dim=0, *args, **kwargs): """Wrap module in non-distributed environment by device type. - For CUDA, wrap as :obj:`mmcv.parallel.MMDataParallel`. - For MPS, wrap as :obj:`mmcv.device.mps.MPSDataParallel`. ...
2,889
34.679012
78
py
mmpretrain
mmpretrain-master/mmcls/utils/device.py
# Copyright (c) OpenMMLab. All rights reserved. import mmcv import torch from mmcv.utils import digit_version def auto_select_device() -> str: mmcv_version = digit_version(mmcv.__version__) if mmcv_version >= digit_version('1.6.0'): from mmcv.device import get_device return get_device() el...
403
24.25
50
py
mmpretrain
mmpretrain-master/.dev_scripts/benchmark_regression/1-benchmark_valid.py
import logging import re from argparse import ArgumentParser from pathlib import Path from time import time from typing import OrderedDict import numpy as np import torch from mmcv import Config from mmcv.parallel import collate, scatter from modelindex.load_model_index import load from rich.console import Console fro...
9,547
36.296875
79
py
mmpretrain
mmpretrain-master/tests/test_runtime/test_optimizer.py
# Copyright (c) OpenMMLab. All rights reserved. import functools from collections import OrderedDict from copy import deepcopy from typing import Iterable import torch import torch.nn as nn from mmcv.runner import build_optimizer from mmcv.runner.optimizer.builder import OPTIMIZERS from mmcv.utils.registry import buil...
11,126
34.893548
79
py
mmpretrain
mmpretrain-master/tests/test_runtime/test_eval_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock, patch import mmcv.runner import pytest import torch import torch.nn as nn from mmcv.runner import obj_from_dict from mmcv.runner.hooks import DistEvalHook, EvalHook from torch.utils.data import DataLoade...
7,069
33.487805
79
py
mmpretrain
mmpretrain-master/tests/test_runtime/test_hooks.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import shutil import tempfile import numpy as np import pytest import torch import torch.nn as nn from mmcv.runner import build_runner from mmcv.runner.hooks import Hook, IterTimerHook from torch.utils.data import DataLoader import mmcls.core # noqa: F40...
4,838
29.433962
79
py
mmpretrain
mmpretrain-master/tests/test_runtime/test_num_class_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock import mmcv.runner as mmcv_runner import pytest import torch from mmcv.runner import obj_from_dict from torch.utils.data import DataLoader, Dataset from mmcls.core.hook import ClassNumCheckHook from mmcl...
2,556
29.082353
76
py
mmpretrain
mmpretrain-master/tests/test_runtime/test_preciseBN_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch import torch.nn as nn from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import EpochBasedRunner, IterBasedRunner, build_optimizer from mmcv.utils import get_logger from mmcv.utils.logging imp...
8,349
29.363636
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_classifiers.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import tempfile from copy import deepcopy import numpy as np import torch from mmcv import ConfigDict from mmcls.models import CLASSIFIERS from mmcls.models.classifiers import ImageClassifier def test_image_classifier(): model_cfg = dict( ...
10,685
31.678899
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_heads.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import patch import pytest import torch from mmcls.models.heads import (ClsHead, ConformerHead, CSRAClsHead, DeiTClsHead, EfficientFormerClsHead, LinearClsHead, MultiLabelClsHead, ...
14,769
35.832918
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.necks import (GeneralizedMeanPooling, GlobalAveragePooling, HRFuseScales) def test_gap_neck(): # test 1d gap_neck neck = GlobalAveragePooling(dim=1) # batch_size, num_features, fe...
2,348
25.693182
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_twins.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import pytest import torch import torch.nn as nn from mmcls.models.backbones.twins import (PCPVT, SVT, GlobalSubsampledAttention, LocallyGroupedSelfAttention) def test_LSA_...
8,490
33.79918
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_vgg.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones import VGG def check_norm_state(modules, train_state): """Check if norm layer is in correct train state.""" for mod in modules: if isinstance(mod, _...
4,069
28.071429
74
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_seresnext.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import SEResNeXt from mmcls.models.backbones.seresnext import SEBottleneck as SEBottleneckX def test_bottleneck(): with pytest.raises(AssertionError): # Style must be in ['pytorch', 'caffe'] SEB...
2,587
33.506667
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_mobilenet_v3.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import MobileNetV3 from mmcls.models.utils import InvertedResidual def is_norm(modules): """Check if is one of the norms....
6,437
35.579545
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_res2net.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones import Res2Net def check_norm_state(modules, train_state): """Check if norm layer is in correct train state.""" for mod in modules: if isinstance(mo...
2,320
31.236111
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_t2t_vit.py
# Copyright (c) OpenMMLab. All rights reserved. import math import os import tempfile from copy import deepcopy from unittest import TestCase import numpy as np import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcls.models.backbones import T2T_ViT from mmcls.models.backbones.t2t_vit import g...
6,968
35.873016
109
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_timm_backbone.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch import nn from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import TIMMBackbone def check_norm_state(modules, train_state): """Check if norm layer is in correct train state.""" for mod in modules...
7,317
34.697561
76
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_convnext.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import ConvNeXt def test_assertion(): with pytest.raises(AssertionError): ConvNeXt(arch='unknown') with pytest.raises(AssertionError): # ConvNeXt arch dict should include 'embed_dims', ...
2,895
28.85567
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_hornet.py
# Copyright (c) OpenMMLab. All rights reserved. import math from copy import deepcopy from itertools import chain from unittest import TestCase import pytest import torch from mmcv.utils import digit_version from mmcv.utils.parrots_wrapper import _BatchNorm from torch import nn from mmcls.models.backbones import HorN...
5,944
32.971429
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_swin_transformer.py
# Copyright (c) OpenMMLab. All rights reserved. import math import os import tempfile from copy import deepcopy from itertools import chain from unittest import TestCase import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones ...
9,274
35.230469
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_efficientnet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import EfficientNet def is_norm(modules): """Check if is one of the norms.""" if isinstance(modules, (GroupNorm, _Bat...
5,431
36.462069
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_resnet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones import ResNet, ResNetV1c, ResNetV1d from mmcls.models.backbones.resnet import (BasicBlock, Bottleneck, ResLayer,...
21,285
33.387722
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_shufflenet_v1.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import ShuffleNetV1 from mmcls.models.backbones.shufflenet_v1 import ShuffleUnit def is_block(modules): """Check if is Re...
7,645
29.955466
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_deit.py
# Copyright (c) OpenMMLab. All rights reserved. import math import os import tempfile from copy import deepcopy from unittest import TestCase import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcls.models.backbones import DistilledVisionTransformer from .utils import timm_resize_pos_embed c...
5,003
36.909091
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_vision_transformer.py
# Copyright (c) OpenMMLab. All rights reserved. import math import os import tempfile from copy import deepcopy from unittest import TestCase import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcls.models.backbones import VisionTransformer from .utils import timm_resize_pos_embed class Test...
6,804
35.983696
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/utils.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.nn.functional as F def timm_resize_pos_embed(posemb, posemb_new, num_tokens=1, gs_new=()): """Timm version pos embed resize function. copied from https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vi...
1,258
38.34375
111
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_conformer.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import Conformer def is_norm(modules): """Check if is one of the norms.""" if isinstance(m...
3,413
29.482143
76
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_mobilenet_v2.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import MobileNetV2 from mmcls.models.backbones.mobilenet_v2 import InvertedResidual def is_block(modules): """Check if is...
8,992
33.588462
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_hrnet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import HRNet def is_norm(modules): """Check if is one of the norms.""" if isinstance(modules, (GroupNorm, _BatchNorm)...
2,625
26.93617
71
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_cspnet.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from functools import partial from unittest import TestCase import torch from mmcv.cnn import ConvModule from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones import CSPDarkNet, CSPResNet, CSPResNeXt from mmcls.models.ba...
5,069
33.256757
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_mlp_mixer.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from unittest import TestCase import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import MlpMixer def is_norm(modules): """Check if is one of the norms.""" ...
3,683
29.7
76
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_mvit.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from unittest import TestCase import torch from mmcls.models.backbones import MViT class TestMViT(TestCase): def setUp(self): self.cfg = dict(arch='tiny', img_size=224, drop_path_rate=0.1) def test_arch(self): # Test...
6,654
34.77957
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_resnet_cifar.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones import ResNet_CIFAR def check_norm_state(modules, train_state): """Check if norm layer is in correct train state.""" for mod in modules: if isinstan...
2,157
30.735294
63
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_resnest.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import ResNeSt from mmcls.models.backbones.resnest import Bottleneck as BottleneckS def test_bottleneck(): with pytest.raises(AssertionError): # Style must be in ['pytorch', 'caffe'] BottleneckS...
1,450
31.244444
76
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_regnet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import RegNet regnet_test_data = [ ('regnetx_400mf', dict(w0=24, wa=24.48, wm=2.54, group_w=16, depth=22, bot_mul=1.0), [32, 64, 160, 384]), ('regnetx_800mf', dict(w0=56, wa=35.73, wm=2.2...
3,119
31.842105
73
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_tnt.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import TNT def check_norm_state(modules, train_state): """Check if norm layer is in correct train state.""" for mod in modules: if isinstance(mod, _...
1,285
24.215686
56
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_poolformer.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from unittest import TestCase import torch from mmcls.models.backbones import PoolFormer from mmcls.models.backbones.poolformer import PoolFormerBlock class TestPoolFormer(TestCase): def setUp(self): arch = 's12' self.cfg...
5,208
35.173611
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_van.py
# Copyright (c) OpenMMLab. All rights reserved. import math from copy import deepcopy from itertools import chain from unittest import TestCase import torch from mmcv.utils.parrots_wrapper import _BatchNorm from torch import nn from mmcls.models.backbones import VAN def check_norm_state(modules, train_state): "...
6,637
34.121693
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_repvgg.py
# Copyright (c) OpenMMLab. All rights reserved. import os import tempfile import pytest import torch from mmcv.runner import load_checkpoint, save_checkpoint from torch import nn from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import RepVGG from mmc...
12,162
33.652422
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_shufflenet_v2.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import ShuffleNetV2 from mmcls.models.backbones.shufflenet_v2 import InvertedResidual def is_block(modules): """Check if ...
6,370
29.927184
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_efficientformer.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy from unittest import TestCase import torch from mmcv.cnn import ConvModule from torch import nn from mmcls.models.backbones import EfficientFormer from mmcls.models.backbones.efficientformer import (AttentionWithBias, Flat, ...
7,785
37.93
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_seresnet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import AvgPool2d from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.backbones import SEResNet from mmcls.models.backbones.resnet import ResLayer from mmcls.models.backbones.seresnet import SEBottleneck, SE...
8,411
32.919355
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_resnext.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import ResNeXt from mmcls.models.backbones.resnext import Bottleneck as BottleneckX def test_bottleneck(): with pytest.raises(AssertionError): # Style must be in ['pytorch', 'caffe'] BottleneckX...
2,072
32.435484
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_densenet.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import DenseNet def test_assertion(): with pytest.raises(AssertionError): DenseNet(arch='unknown') with pytest.raises(AssertionError): # DenseNet arch dict should include essential_keys, ...
2,721
27.354167
75
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_convmixer.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import ConvMixer def test_assertion(): with pytest.raises(AssertionError): ConvMixer(arch='unknown') with pytest.raises(AssertionError): # ConvMixer arch dict should include essential_keys,...
2,087
23.564706
60
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_swin_transformer_v2.py
# Copyright (c) OpenMMLab. All rights reserved. import math import os import tempfile from copy import deepcopy from itertools import chain from unittest import TestCase import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcv.utils.parrots_wrapper import _BatchNorm from mmcls.models.backbones ...
8,897
35.467213
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_backbones/test_repmlp.py
# Copyright (c) OpenMMLab. All rights reserved. import os import tempfile from copy import deepcopy from unittest import TestCase import torch from mmcv.runner import load_checkpoint, save_checkpoint from mmcls.models.backbones import RepMLPNet class TestRepMLP(TestCase): def setUp(self): # default mod...
5,915
33.196532
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_layer_scale.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest import TestCase import torch from mmcls.models.utils import LayerScale class TestLayerScale(TestCase): def test_init(self): with self.assertRaisesRegex(AssertionError, "'data_format' could"): cfg = dict( dim=10, ...
1,577
31.204082
75
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_position_encoding.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcls.models.utils import ConditionalPositionEncoding def test_conditional_position_encoding_module(): CPE = ConditionalPositionEncoding(in_channels=32, embed_dims=32, stride=2) outs = CPE(torch.randn(1, 3136, 32), (56, 56)) assert outs.sh...
352
31.090909
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_augment.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.utils import Augments augment_cfgs = [ dict(type='BatchCutMix', alpha=1., prob=1.), dict(type='BatchMixup', alpha=1., prob=1.), dict(type='Identity', prob=1.), dict(type='BatchResizeMix', alpha=1., prob=1.) ] ...
3,262
32.639175
78
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_embed.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcls.models.backbones import VGG from mmcls.models.utils import HybridEmbed, PatchEmbed, PatchMerging def cal_unfold_dim(dim, kernel_size, stride, padding=0, dilation=1): return (dim + 2 * padding - dilation * (kernel_size - 1) - 1)...
3,256
35.595506
79
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_misc.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcv.utils import digit_version from mmcls.models.utils import channel_shuffle, is_tracing, make_divisible def test_make_divisible(): # test min_value is None result = make_divisible(34, 8, None) assert result == 32 # te...
1,705
27.433333
77
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_inverted_residual.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.utils import InvertedResidual, SELayer def is_norm(modules): """Check if is one of the norms.""" if isinstance(modules, (GroupN...
2,787
32.590361
71
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_se.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from torch.nn.modules import GroupNorm from torch.nn.modules.batchnorm import _BatchNorm from mmcls.models.utils import SELayer def is_norm(modules): """Check if is one of the norms.""" if isinstance(modules, (GroupNorm, _BatchNorm)):...
2,963
29.875
62
py
mmpretrain
mmpretrain-master/tests/test_models/test_utils/test_attention.py
# Copyright (c) OpenMMLab. All rights reserved. from functools import partial from unittest import TestCase from unittest.mock import ANY, MagicMock import pytest import torch from mmcv.utils import TORCH_VERSION, digit_version from mmcls.models.utils.attention import ShiftWindowMSA, WindowMSA if digit_version(TORCH...
8,102
37.770335
79
py
mmpretrain
mmpretrain-master/tests/test_data/test_builder.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from copy import deepcopy from unittest.mock import patch import torch from mmcv.utils import digit_version from mmcls.datasets import ImageNet, build_dataloader, build_dataset from mmcls.datasets.dataset_wrappers import (ClassBalancedDataset, ...
9,975
35.542125
79
py