repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
ControlNet
annotator/uniformer/mmcv/runner/hooks/checkpoint.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import warnings from annotator.uniformer.mmcv.fileio import FileClient from ..dist_utils import allreduce_params, master_only from .hook import HOOKS, Hook @HOOKS.register_module() class CheckpointHook(Hook): """Save checkpoints periodically. ...
168
7,317
ControlNet
annotator/uniformer/mmcv/runner/hooks/sync_buffer.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ..dist_utils import allreduce_params from .hook import HOOKS, Hook @HOOKS.register_module() class SyncBuffersHook(Hook): """Synchronize model buffers such as running_mean and running_var in BN at the end of each epoch. Args: distributed (bool):...
23
707
ControlNet
annotator/uniformer/mmcv/runner/hooks/evaluation.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import warnings from math import inf import torch.distributed as dist from torch.nn.modules.batchnorm import _BatchNorm from torch.utils.data import DataLoader from annotator.uniformer.mmcv.fileio import FileClient from annotator.uniformer.mmcv.uti...
510
22,448
ControlNet
annotator/uniformer/mmcv/runner/hooks/profiler.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings from typing import Callable, List, Optional, Union import torch from ..dist_utils import master_only from .hook import HOOKS, Hook @HOOKS.register_module() class ProfilerHook(Hook): """Profiler to analyze performance during training. PyTorch P...
181
8,041
ControlNet
annotator/uniformer/mmcv/runner/hooks/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .checkpoint import CheckpointHook from .closure import ClosureHook from .ema import EMAHook from .evaluation import DistEvalHook, EvalHook from .hook import HOOKS, Hook from .iter_timer import IterTimerHook from .logger import (DvcliveLoggerHook, LoggerHook, MlflowLo...
30
1,396
ControlNet
annotator/uniformer/mmcv/runner/hooks/lr_updater.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers from math import cos, pi import annotator.uniformer.mmcv as mmcv from .hook import HOOKS, Hook class LrUpdaterHook(Hook): """LR Scheduler in MMCV. Args: by_epoch (bool): LR changes epoch by epoch warmup (string): Type of warmup u...
671
26,034
ControlNet
annotator/uniformer/mmcv/runner/hooks/ema.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ...parallel import is_module_wrapper from ..hooks.hook import HOOKS, Hook @HOOKS.register_module() class EMAHook(Hook): r"""Exponential Moving Average Hook. Use Exponential Moving Average on all parameters of model in training process. All parameters h...
90
3,599
ControlNet
annotator/uniformer/mmcv/runner/hooks/closure.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .hook import HOOKS, Hook @HOOKS.register_module() class ClosureHook(Hook): def __init__(self, fn_name, fn): assert hasattr(self, fn_name) assert callable(fn) setattr(self, fn_name, fn)
12
269
ControlNet
annotator/uniformer/mmcv/runner/hooks/momentum_updater.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import annotator.uniformer.mmcv as mmcv from .hook import HOOKS, Hook from .lr_updater import annealing_cos, annealing_linear, format_param class MomentumUpdaterHook(Hook): def __init__(self, by_epoch=True, warmup=None, ...
494
21,296
ControlNet
annotator/uniformer/mmcv/runner/hooks/hook.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from annotator.uniformer.mmcv.utils import Registry, is_method_overridden HOOKS = Registry('hook') class Hook: stages = ('before_run', 'before_train_epoch', 'before_train_iter', 'after_train_iter', 'after_train_epoch', 'before_val_epoch', ...
93
2,761
ControlNet
annotator/uniformer/mmcv/runner/hooks/sampler_seed.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .hook import HOOKS, Hook @HOOKS.register_module() class DistSamplerSeedHook(Hook): """Data-loading sampler for distributed training. When distributed training, it is only useful in conjunction with :obj:`EpochBasedRunner`, while :obj:`IterBasedRunner` ...
21
847
ControlNet
annotator/uniformer/mmcv/runner/hooks/memory.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from .hook import HOOKS, Hook @HOOKS.register_module() class EmptyCacheHook(Hook): def __init__(self, before_epoch=False, after_epoch=True, after_iter=False): self._before_epoch = before_epoch self._after_epoch = after_epoch se...
26
657
ControlNet
annotator/uniformer/mmcv/runner/hooks/optimizer.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import copy from collections import defaultdict from itertools import chain from torch.nn.utils import clip_grad from annotator.uniformer.mmcv.utils import TORCH_VERSION, _BatchNorm, digit_version from ..dist_utils import allreduce_grads from ..fp16_utils import LossSca...
509
21,654
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/pavi.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import json import os import os.path as osp import torch import yaml import annotator.uniformer.mmcv as mmcv from ....parallel.utils import is_module_wrapper from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_mo...
118
4,378
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/mlflow.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_module() class MlflowLoggerHook(LoggerHook): def __init__(self, exp_name=None, tags=None, log_model=True, ...
79
2,838
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .base import LoggerHook from .dvclive import DvcliveLoggerHook from .mlflow import MlflowLoggerHook from .neptune import NeptuneLoggerHook from .pavi import PaviLoggerHook from .tensorboard import TensorboardLoggerHook from .text import TextLoggerHook from .wandb imp...
16
522
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/neptune.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_module() class NeptuneLoggerHook(LoggerHook): """Class to log metrics to NeptuneAI. It requires `neptune-client` to be installed. Args: init...
83
3,077
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/wandb.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_module() class WandbLoggerHook(LoggerHook): def __init__(self, init_kwargs=None, interval=10, ignore_last=...
57
1,694
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/tensorboard.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from annotator.uniformer.mmcv.utils import TORCH_VERSION, digit_version from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_module() class TensorboardLoggerHook(LoggerHook): def __init__...
58
2,077
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/text.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import datetime import os import os.path as osp from collections import OrderedDict import torch import torch.distributed as dist import annotator.uniformer.mmcv as mmcv from annotator.uniformer.mmcv.fileio.file_client import FileClient from annotator.uniformer.mmcv.uti...
257
10,684
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/base.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers from abc import ABCMeta, abstractmethod import numpy as np import torch from ..hook import Hook class LoggerHook(Hook): """Base class for logger hooks. Args: interval (int): Logging interval (every k iterations). ignore_last (bo...
167
5,451
ControlNet
annotator/uniformer/mmcv/runner/hooks/logger/dvclive.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @HOOKS.register_module() class DvcliveLoggerHook(LoggerHook): """Class to log metrics with dvclive. It requires `dvclive`_ to be installed. Args: path (str)...
59
1,761
ControlNet
annotator/uniformer/mmcv/runner/optimizer/default_constructor.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch from torch.nn import GroupNorm, LayerNorm from annotator.uniformer.mmcv.utils import _BatchNorm, _InstanceNorm, build_from_cfg, is_list_of from annotator.uniformer.mmcv.utils.ext_loader import check_ops_exist from .builder import OPTIMIZER_B...
250
11,803
ControlNet
annotator/uniformer/mmcv/runner/optimizer/builder.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import inspect import torch from ...utils import Registry, build_from_cfg OPTIMIZERS = Registry('optimizer') OPTIMIZER_BUILDERS = Registry('optimizer builder') def register_torch_optimizers(): torch_optimizers = [] for module_name in dir(torch.opt...
45
1,346
ControlNet
annotator/uniformer/mmcv/runner/optimizer/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .builder import (OPTIMIZER_BUILDERS, OPTIMIZERS, build_optimizer, build_optimizer_constructor) from .default_constructor import DefaultOptimizerConstructor __all__ = [ 'OPTIMIZER_BUILDERS', 'OPTIMIZERS', 'DefaultOptimizerConstructor', '...
10
370
ControlNet
annotator/uniformer/mmcv/utils/trace.py
.py
import warnings import torch from annotator.uniformer.mmcv.utils import digit_version def is_jit_tracing() -> bool: if (torch.__version__ != 'parrots' and digit_version(torch.__version__) >= digit_version('1.6.0')): on_trace = torch.jit.is_tracing() # In PyTorch 1.6, torch.jit.is_tra...
24
795
ControlNet
annotator/uniformer/mmcv/utils/logging.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import torch.distributed as dist logger_initialized = {} def get_logger(name, log_file=None, log_level=logging.INFO, file_mode='w'): """Initialize and get a logger by name. If the logger has not been initialized, this method will initialize the...
111
3,986
ControlNet
annotator/uniformer/mmcv/utils/misc.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import collections.abc import functools import itertools import subprocess import warnings from collections import abc from importlib import import_module from inspect import getfullargspec from itertools import repeat # From PyTorch internals def _ntuple(n): def p...
378
11,447
ControlNet
annotator/uniformer/mmcv/utils/__init__.py
.py
# flake8: noqa # Copyright (c) OpenMMLab. All rights reserved. from .config import Config, ConfigDict, DictAction from .misc import (check_prerequisites, concat_list, deprecated_api_warning, has_method, import_modules_from_strings, is_list_of, is_method_overridden, is_seq_of, is_st...
70
3,915
ControlNet
annotator/uniformer/mmcv/utils/registry.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import inspect import warnings from functools import partial from .misc import is_seq_of def build_from_cfg(cfg, registry, default_args=None): """Build a module from config dict. Args: cfg (dict): Config dict. It should at least contain the key "type"....
316
11,041
ControlNet
annotator/uniformer/mmcv/utils/testing.py
.py
# Copyright (c) Open-MMLab. import sys from collections.abc import Iterable from runpy import run_path from shlex import split from typing import Any, Dict, List from unittest.mock import patch def check_python_script(cmd): """Run the python cmd script with `__main__`. The difference between `os.system` is th...
141
4,289
ControlNet
annotator/uniformer/mmcv/utils/path.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os import os.path as osp from pathlib import Path from .misc import is_str def is_filepath(x): return is_str(x) or isinstance(x, Path) def fopen(filepath, *args, **kwargs): if is_str(filepath): return open(filepath, *args, **kwargs) elif is...
102
3,414
ControlNet
annotator/uniformer/mmcv/utils/parrots_wrapper.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from functools import partial import torch TORCH_VERSION = torch.__version__ def is_rocm_pytorch() -> bool: is_rocm = False if TORCH_VERSION != 'parrots': try: from torch.utils.cpp_extension import ROCM_HOME is_rocm = True if ((...
108
3,536
ControlNet
annotator/uniformer/mmcv/utils/parrots_jit.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os from .parrots_wrapper import TORCH_VERSION parrots_jit_option = os.getenv('PARROTS_JIT_OPTION') if TORCH_VERSION == 'parrots' and parrots_jit_option == 'ON': from parrots.jit import pat as jit else: def jit(func=None, check_input=None, ...
42
899
ControlNet
annotator/uniformer/mmcv/utils/timer.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from time import time class TimerError(Exception): def __init__(self, message): self.message = message super(TimerError, self).__init__(message) class Timer: """A flexible Timer class. :Example: >>> import time >>> import annotat...
119
2,993
ControlNet
annotator/uniformer/mmcv/utils/progressbar.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import sys from collections.abc import Iterable from multiprocessing import Pool from shutil import get_terminal_size from .timer import Timer class ProgressBar: """A progress bar which can print the progress.""" def __init__(self, task_num=0, bar_width=50, st...
209
7,105
ControlNet
annotator/uniformer/mmcv/utils/version_utils.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os import subprocess import warnings from packaging.version import parse def digit_version(version_str: str, length: int = 4): """Convert a version string into a tuple of integers. This method is usually used for comparing two versions. For pre-release ...
91
2,673
ControlNet
annotator/uniformer/mmcv/utils/config.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import ast import copy import os import os.path as osp import platform import shutil import sys import tempfile import uuid import warnings from argparse import Action, ArgumentParser from collections import abc from importlib import import_module from addict import Dict...
689
26,263
ControlNet
annotator/uniformer/mmcv/utils/env.py
.py
# Copyright (c) OpenMMLab. All rights reserved. """This file holding some environment constant for sharing by other files.""" import os.path as osp import subprocess import sys from collections import defaultdict import cv2 import torch import annotator.uniformer.mmcv as mmcv from .parrots_wrapper import get_build_c...
96
3,367
ControlNet
annotator/uniformer/mmcv/utils/ext_loader.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import importlib import os import pkgutil import warnings from collections import namedtuple import torch if torch.__version__ != 'parrots': def load_ext(name, funcs): ext = importlib.import_module('mmcv.' + name) for fun in funcs: asser...
72
2,021
ControlNet
annotator/uniformer/mmcv/cnn/builder.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ..runner import Sequential from ..utils import Registry, build_from_cfg def build_model_from_cfg(cfg, registry, default_args=None): """Build a PyTorch model from config dict(s). Different from ``build_from_cfg``, if cfg is a list, a ``nn.Sequential`` will b...
31
1,089
ControlNet
annotator/uniformer/mmcv/cnn/alexnet.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import torch.nn as nn class AlexNet(nn.Module): """AlexNet backbone. Args: num_classes (int): number of classes for classification. """ def __init__(self, num_classes=-1): super(AlexNet, self).__init__() self.num...
62
1,990
ControlNet
annotator/uniformer/mmcv/cnn/resnet.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import torch.nn as nn import torch.utils.checkpoint as cp from .utils import constant_init, kaiming_init def conv3x3(in_planes, out_planes, stride=1, dilation=1): """3x3 convolution with padding.""" return nn.Conv2d( in_planes, o...
317
9,955
ControlNet
annotator/uniformer/mmcv/cnn/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .alexnet import AlexNet # yapf: disable from .bricks import (ACTIVATION_LAYERS, CONV_LAYERS, NORM_LAYERS, PADDING_LAYERS, PLUGIN_LAYERS, UPSAMPLE_LAYERS, ContextBlock, Conv2d, Conv3d, ConvAWS2d, ConvModule, ...
42
2,438
ControlNet
annotator/uniformer/mmcv/cnn/vgg.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import torch.nn as nn from .utils import constant_init, kaiming_init, normal_init def conv3x3(in_planes, out_planes, dilation=1): """3x3 convolution with padding.""" return nn.Conv2d( in_planes, out_planes, kernel_size=3,...
176
6,053
ControlNet
annotator/uniformer/mmcv/cnn/utils/flops_counter.py
.py
# Modified from flops-counter.pytorch by Vladislav Sovrasov # original repo: https://github.com/sovrasov/flops-counter.pytorch # MIT License # Copyright (c) 2018 Vladislav Sovrasov # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (th...
600
22,104
ControlNet
annotator/uniformer/mmcv/cnn/utils/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .flops_counter import get_model_complexity_info from .fuse_conv_bn import fuse_conv_bn from .sync_bn import revert_sync_batchnorm from .weight_init import (INITIALIZERS, Caffe2XavierInit, ConstantInit, KaimingInit, NormalInit, PretrainedInit...
20
1,023
ControlNet
annotator/uniformer/mmcv/cnn/utils/sync_bn.py
.py
import torch import annotator.uniformer.mmcv as mmcv class _BatchNormXd(torch.nn.modules.batchnorm._BatchNorm): """A general BatchNorm layer without input dimension check. Reproduced from @kapily's work: (https://github.com/pytorch/pytorch/issues/41081#issuecomment-783961547) The only difference bet...
60
2,327
ControlNet
annotator/uniformer/mmcv/cnn/utils/weight_init.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import math import warnings import numpy as np import torch import torch.nn as nn from torch import Tensor from annotator.uniformer.mmcv.utils import Registry, build_from_cfg, get_logger, print_log INITIALIZERS = Registry('initializer') def update_init_in...
685
26,006
ControlNet
annotator/uniformer/mmcv/cnn/utils/fuse_conv_bn.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn def _fuse_conv_bn(conv, bn): """Fuse conv and bn into one module. Args: conv (nn.Module): Conv to be fused. bn (nn.Module): BN to be fused. Returns: nn.Module: Fused module. """ conv_w = co...
60
1,881
ControlNet
annotator/uniformer/mmcv/cnn/bricks/hswish.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from .registry import ACTIVATION_LAYERS @ACTIVATION_LAYERS.register_module() class HSwish(nn.Module): """Hard Swish Module. This module applies the hard swish function: .. math:: Hswish(x) = x * ReLU6(x + 3) / 6 Args: ...
30
651
ControlNet
annotator/uniformer/mmcv/cnn/bricks/transformer.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import warnings import torch import torch.nn as nn from annotator.uniformer.mmcv import ConfigDict, deprecated_api_warning from annotator.uniformer.mmcv.cnn import Linear, build_activation_layer, build_norm_layer from annotator.uniformer.mmcv.runner.base_mod...
596
24,639
ControlNet
annotator/uniformer/mmcv/cnn/bricks/norm.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import inspect import torch.nn as nn from annotator.uniformer.mmcv.utils import is_tuple_of from annotator.uniformer.mmcv.utils.parrots_wrapper import SyncBatchNorm, _BatchNorm, _InstanceNorm from .registry import NORM_LAYERS NORM_LAYERS.register_module('BN', module=nn...
145
5,154
ControlNet
annotator/uniformer/mmcv/cnn/bricks/swish.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from .registry import ACTIVATION_LAYERS @ACTIVATION_LAYERS.register_module() class Swish(nn.Module): """Swish Module. This module applies the swish function: .. math:: Swish(x) = x * Sigmoid(x) Returns: ...
26
485
ControlNet
annotator/uniformer/mmcv/cnn/bricks/non_local.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import ABCMeta import torch import torch.nn as nn from ..utils import constant_init, normal_init from .conv_module import ConvModule from .registry import PLUGIN_LAYERS class _NonLocalNd(nn.Module, metaclass=ABCMeta): """Basic Non-local module. This ...
307
11,012
ControlNet
annotator/uniformer/mmcv/cnn/bricks/upsample.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from ..utils import xavier_init from .registry import UPSAMPLE_LAYERS UPSAMPLE_LAYERS.register_module('nearest', module=nn.Upsample) UPSAMPLE_LAYERS.register_module('bilinear', module=nn.Upsample) @UPSAMPLE_LAYERS....
85
2,880
ControlNet
annotator/uniformer/mmcv/cnn/bricks/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .activation import build_activation_layer from .context_block import ContextBlock from .conv import build_conv_layer from .conv2d_adaptive_padding import Conv2dAdaptivePadding from .conv_module import ConvModule from .conv_ws import ConvAWS2d, ConvWS2d, conv_ws_2d fr...
36
1,732
ControlNet
annotator/uniformer/mmcv/cnn/bricks/generalized_attention.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import math import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from ..utils import kaiming_init from .registry import PLUGIN_LAYERS @PLUGIN_LAYERS.register_module() class GeneralizedAttention(nn.Module): """GeneralizedAttention m...
413
15,999
ControlNet
annotator/uniformer/mmcv/cnn/bricks/activation.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.utils import TORCH_VERSION, build_from_cfg, digit_version from .registry import ACTIVATION_LAYERS for module in [ nn.ReLU, nn.LeakyReLU, nn.PReLU, nn.RReLU, nn.ReLU6...
93
2,508
ControlNet
annotator/uniformer/mmcv/cnn/bricks/conv2d_adaptive_padding.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import math from torch import nn from torch.nn import functional as F from .registry import CONV_LAYERS @CONV_LAYERS.register_module() class Conv2dAdaptivePadding(nn.Conv2d): """Implementation of 2D convolution in tensorflow with `padding` as "same", which app...
63
2,514
ControlNet
annotator/uniformer/mmcv/cnn/bricks/conv_module.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn from annotator.uniformer.mmcv.utils import _BatchNorm, _InstanceNorm from ..utils import constant_init, kaiming_init from .activation import build_activation_layer from .conv import build_conv_layer from .norm import build_norm_laye...
207
8,760
ControlNet
annotator/uniformer/mmcv/cnn/bricks/registry.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from annotator.uniformer.mmcv.utils import Registry CONV_LAYERS = Registry('conv layer') NORM_LAYERS = Registry('norm layer') ACTIVATION_LAYERS = Registry('activation layer') PADDING_LAYERS = Registry('padding layer') UPSAMPLE_LAYERS = Registry('upsample layer') PLUGIN_L...
17
658
ControlNet
annotator/uniformer/mmcv/cnn/bricks/conv.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from torch import nn from .registry import CONV_LAYERS CONV_LAYERS.register_module('Conv1d', module=nn.Conv1d) CONV_LAYERS.register_module('Conv2d', module=nn.Conv2d) CONV_LAYERS.register_module('Conv3d', module=nn.Conv3d) CONV_LAYERS.register_module('Conv', module=nn.C...
45
1,446
ControlNet
annotator/uniformer/mmcv/cnn/bricks/wrappers.py
.py
# Copyright (c) OpenMMLab. All rights reserved. r"""Modified from https://github.com/facebookresearch/detectron2/blob/master/detectron2/layers/wrappers.py # noqa: E501 Wrap some nn modules to support empty tensor input. Currently, these wrappers are mainly used in mask heads like fcn_mask_head and maskiou_heads since...
181
6,961
ControlNet
annotator/uniformer/mmcv/cnn/bricks/context_block.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch import nn from ..utils import constant_init, kaiming_init from .registry import PLUGIN_LAYERS def last_zero_init(m): if isinstance(m, nn.Sequential): constant_init(m[-1], val=0) else: constant_init(m, val=0) @PLUGIN_LAY...
126
4,681
ControlNet
annotator/uniformer/mmcv/cnn/bricks/drop.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from annotator.uniformer.mmcv import build_from_cfg from .registry import DROPOUT_LAYERS def drop_path(x, drop_prob=0., training=False): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks...
66
2,172
ControlNet
annotator/uniformer/mmcv/cnn/bricks/padding.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from .registry import PADDING_LAYERS PADDING_LAYERS.register_module('zero', module=nn.ZeroPad2d) PADDING_LAYERS.register_module('reflect', module=nn.ReflectionPad2d) PADDING_LAYERS.register_module('replicate', module=nn.ReplicationPad2d) def buil...
37
1,127
ControlNet
annotator/uniformer/mmcv/cnn/bricks/conv_ws.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from .registry import CONV_LAYERS def conv_ws_2d(input, weight, bias=None, stride=1, padding=0, dilation=1, grou...
149
5,417
ControlNet
annotator/uniformer/mmcv/cnn/bricks/depthwise_separable_conv_module.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from .conv_module import ConvModule class DepthwiseSeparableConvModule(nn.Module): """Depthwise separable convolution module. See https://arxiv.org/pdf/1704.04861.pdf for details. This module can replace a ConvModule with the conv bl...
97
4,142
ControlNet
annotator/uniformer/mmcv/cnn/bricks/hsigmoid.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from .registry import ACTIVATION_LAYERS @ACTIVATION_LAYERS.register_module() class HSigmoid(nn.Module): """Hard Sigmoid Module. Apply the hard sigmoid function: Hsigmoid(x) = min(max((x + bias) / divisor, min_value), max_value) Default...
35
1,097
ControlNet
annotator/uniformer/mmcv/cnn/bricks/plugin.py
.py
import inspect import platform from .registry import PLUGIN_LAYERS if platform.system() == 'Windows': import regex as re else: import re def infer_abbr(class_type): """Infer abbreviation from the class name. This method will infer the abbreviation to map class types to abbreviations. Rule ...
89
2,487
ControlNet
annotator/uniformer/mmcv/cnn/bricks/scale.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn class Scale(nn.Module): """A learnable scale parameter. This layer scales the input by a learnable factor. It multiplies a learnable scale parameter of shape (1,) with input of any shape. Args: scale (float): ...
22
577
ControlNet
annotator/uniformer/mmcv/arraymisc/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .quantization import dequantize, quantize __all__ = ['quantize', 'dequantize']
5
133
ControlNet
annotator/uniformer/mmcv/arraymisc/quantization.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np def quantize(arr, min_val, max_val, levels, dtype=np.int64): """Quantize an array of (-inf, inf) to [0, levels-1]. Args: arr (ndarray): Input array. min_val (scalar): Minimum value to be clipped. max_val (scalar): Maxi...
56
1,824
ControlNet
annotator/uniformer/mmcv/ops/modulated_deform_conv.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.nn as nn from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.modules.utils import _pair, _single from annotator.uniformer.mmcv.utils import deprecated_api_warning from ..cnn impo...
283
10,574
ControlNet
annotator/uniformer/mmcv/ops/bbox.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps']) def bbox_overlaps(bboxes1, bboxes2, mode='iou', aligned=False, offset=0): """Calculate overlap between two set of bboxes. If ``aligned`` is ``False``, then calculate the...
73
2,508
ControlNet
annotator/uniformer/mmcv/ops/deform_roi_pool.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from torch import nn from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.modules.utils import _pair from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['deform_roi_pool_forward', 'deform_roi...
205
7,410
ControlNet
annotator/uniformer/mmcv/ops/cc_attention.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import PLUGIN_LAYERS, Scale def NEG_INF_DIAG(n, device): """Returns a diagonal matrix of size [n, n]. The diagonal are all "-inf". This is for avoiding calcula...
84
3,041
ControlNet
annotator/uniformer/mmcv/ops/roiaware_pool3d.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch import nn as nn from torch.autograd import Function import annotator.uniformer.mmcv as mmcv from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['roiaware_pool3d_forward', 'roiaware_pool3d_backward']) class RoIAwarePool...
115
4,256
ControlNet
annotator/uniformer/mmcv/ops/border_align.py
.py
# Copyright (c) OpenMMLab. All rights reserved. # modified from # https://github.com/Megvii-BaseDetection/cvpods/blob/master/cvpods/layers/border_align.py import torch import torch.nn as nn from torch.autograd import Function from torch.autograd.function import once_differentiable from ..utils import ext_loader ext_...
110
3,725
ControlNet
annotator/uniformer/mmcv/ops/deform_conv.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Tuple, Union import torch import torch.nn as nn import torch.nn.functional as F from torch import Tensor from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.modules.utils import _pair, _single from...
406
15,603
ControlNet
annotator/uniformer/mmcv/ops/pixel_group.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ['pixel_group']) def pixel_group(score, mask, embedding, kernel_label, kernel_contour, kernel_region_num, distance_threshold): """Group pixels i...
76
3,113
ControlNet
annotator/uniformer/mmcv/ops/roi_align_rotated.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['roi_align_rotated_forward', 'roi_align_rotated_backward']) class RoIAlignRotatedFunction(Function): @staticmethod def symb...
178
6,434
ControlNet
annotator/uniformer/mmcv/ops/group_points.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from typing import Tuple import torch from torch import nn as nn from torch.autograd import Function from ..utils import ext_loader from .ball_query import ball_query from .knn import knn ext_module = ext_loader.load_ext( '_ext', ['group_points_forward', 'group_poi...
225
8,135
ControlNet
annotator/uniformer/mmcv/ops/info.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import glob import os import torch if torch.__version__ == 'parrots': import parrots def get_compiler_version(): return 'GCC ' + parrots.version.compiler def get_compiling_cuda_version(): return parrots.version.cuda else: from ..utils i...
37
887
ControlNet
annotator/uniformer/mmcv/ops/nms.py
.py
import os import numpy as np import torch from annotator.uniformer.mmcv.utils import deprecated_api_warning from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['nms', 'softnms', 'nms_match', 'nms_rotated']) # This function is modified from: https://github.com/pytorch/vision/ class NMSop(t...
418
16,237
ControlNet
annotator/uniformer/mmcv/ops/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .assign_score_withk import assign_score_withk from .ball_query import ball_query from .bbox import bbox_overlaps from .border_align import BorderAlign, border_align from .box_iou_rotated import box_iou_rotated from .carafe import CARAFE, CARAFENaive, CARAFEPack, cara...
82
4,506
ControlNet
annotator/uniformer/mmcv/ops/iou3d.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', [ 'iou3d_boxes_iou_bev_forward', 'iou3d_nms_forward', 'iou3d_nms_normal_forward' ]) def boxes_iou_bev(boxes_a, boxes_b): """Calculate boxes IoU in the Bird's Eye View. ...
86
2,988
ControlNet
annotator/uniformer/mmcv/ops/three_interpolate.py
.py
from typing import Tuple import torch from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['three_interpolate_forward', 'three_interpolate_backward']) class ThreeInterpolate(Function): """Performs weighted linear interpolation on 3 features. Ple...
69
2,147
ControlNet
annotator/uniformer/mmcv/ops/merge_cells.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import abstractmethod import torch import torch.nn as nn import torch.nn.functional as F from ..cnn import ConvModule class BaseMergeCell(nn.Module): """The basic class for cells used in NAS-FPN and NAS-FCOS. BaseMergeCell takes 2 inputs. After apply...
150
5,403
ControlNet
annotator/uniformer/mmcv/ops/points_in_boxes.py
.py
import torch from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', [ 'points_in_boxes_part_forward', 'points_in_boxes_cpu_forward', 'points_in_boxes_all_forward' ]) def points_in_boxes_part(points, boxes): """Find the box in which each point is (CUDA). Args: points (torch....
134
5,241
ControlNet
annotator/uniformer/mmcv/ops/roi_pool.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.modules.utils import _pair from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ...
87
2,517
ControlNet
annotator/uniformer/mmcv/ops/furthest_point_sample.py
.py
import torch from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', [ 'furthest_point_sampling_forward', 'furthest_point_sampling_with_dist_forward' ]) class FurthestPointSampling(Function): """Uses iterative furthest point sampling to select a set of...
84
2,550
ControlNet
annotator/uniformer/mmcv/ops/sync_bn.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.distributed as dist import torch.nn.functional as F from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.modules.module import Module from torch.nn.parameter import Parameter from annotator.un...
280
11,267
ControlNet
annotator/uniformer/mmcv/ops/box_iou_rotated.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ['box_iou_rotated']) def box_iou_rotated(bboxes1, bboxes2, mode='iou', aligned=False): """Return intersection-over-union (Jaccard index) of boxes. Both sets of boxes are expected to be in ...
46
1,609
ControlNet
annotator/uniformer/mmcv/ops/corner_pool.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch import nn from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', [ 'top_pool_forward', 'top_pool_backward', 'bottom_pool_forward', 'bottom_pool_backward', 'left_pool_forward', 'left_poo...
162
4,697
ControlNet
annotator/uniformer/mmcv/ops/assign_score_withk.py
.py
from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['assign_score_withk_forward', 'assign_score_withk_backward']) class AssignScoreWithK(Function): r"""Perform weighted sum to generate output features according to scores. Modified from `PAConv <h...
124
4,344
ControlNet
annotator/uniformer/mmcv/ops/multi_scale_deform_attn.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import math import warnings import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd.function import Function, once_differentiable from annotator.uniformer.mmcv import deprecated_api_warning from annotator.uniformer.mmcv.cnn import constant...
359
15,175
ControlNet
annotator/uniformer/mmcv/ops/contour_expand.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ['contour_expand']) def contour_expand(kernel_mask, internal_kernel_label, min_kernel_area, kernel_num): """Expand kernel contours so that fo...
50
1,795
ControlNet
annotator/uniformer/mmcv/ops/deprecated_wrappers.py
.py
# Copyright (c) OpenMMLab. All rights reserved. # This file is for backward compatibility. # Module wrappers for empty tensor have been moved to mmcv.cnn.bricks. import warnings from ..cnn.bricks.wrappers import Conv2d, ConvTranspose2d, Linear, MaxPool2d class Conv2d_deprecated(Conv2d): def __init__(self, *args...
44
1,467