python_code
stringlengths
0
679k
repo_name
stringlengths
9
41
file_path
stringlengths
6
149
# Copyright (c) OpenMMLab. All rights reserved. import copy import logging import os.path as osp import warnings from abc import ABCMeta, abstractmethod import torch from torch.optim import Optimizer import annotator.uniformer.mmcv as mmcv from ..parallel import is_module_wrapper from .checkpoint import load_checkpoi...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/base_runner.py
# Copyright (c) OpenMMLab. All rights reserved. import io import os import os.path as osp import pkgutil import re import time import warnings from collections import OrderedDict from importlib import import_module from tempfile import TemporaryDirectory import torch import torchvision from torch.optim import Optimize...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/checkpoint.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import platform import shutil import time import warnings import torch import annotator.uniformer.mmcv as mmcv from .base_runner import BaseRunner from .builder import RUNNERS from .checkpoint import save_checkpoint from .utils import get_host_info...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/epoch_based_runner.py
# Copyright (c) OpenMMLab. All rights reserved. from .base_module import BaseModule, ModuleList, Sequential from .base_runner import BaseRunner from .builder import RUNNERS, build_runner from .checkpoint import (CheckpointLoader, _load_checkpoint, _load_checkpoint_with_prefix, load_checkpoint, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/__init__.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import platform import shutil import time import warnings import torch from torch.optim import Optimizer import annotator.uniformer.mmcv as mmcv from .base_runner import BaseRunner from .builder import RUNNERS from .checkpoint import save_checkpoin...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/iter_based_runner.py
# Copyright (c) OpenMMLab. All rights reserved. from enum import Enum class Priority(Enum): """Hook priority levels. +--------------+------------+ | Level | Value | +==============+============+ | HIGHEST | 0 | +--------------+------------+ | VERY_HIGH | 10 ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/priority.py
# Copyright (c) OpenMMLab. All rights reserved. import copy from ..utils import Registry RUNNERS = Registry('runner') RUNNER_BUILDERS = Registry('runner builder') def build_runner_constructor(cfg): return RUNNER_BUILDERS.build(cfg) def build_runner(cfg, default_args=None): runner_cfg = copy.deepcopy(cfg) ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/builder.py
# Copyright (c) OpenMMLab. All rights reserved. import os import random import sys import time import warnings from getpass import getuser from socket import gethostname import numpy as np import torch import annotator.uniformer.mmcv as mmcv def get_host_info(): """Get hostname and username. Return empty s...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/utils.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import warnings from abc import ABCMeta from collections import defaultdict from logging import FileHandler import torch.nn as nn from annotator.uniformer.mmcv.runner.dist_utils import master_only from annotator.uniformer.mmcv.utils.logging import get_logger...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/base_module.py
# Copyright (c) OpenMMLab. All rights reserved. from collections import OrderedDict import numpy as np class LogBuffer: def __init__(self): self.val_history = OrderedDict() self.n_history = OrderedDict() self.output = OrderedDict() self.ready = False def clear(self): ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/log_buffer.py
# Copyright (c) OpenMMLab. All rights reserved. import functools import warnings from collections import abc from inspect import getfullargspec import numpy as np import torch import torch.nn as nn from annotator.uniformer.mmcv.utils import TORCH_VERSION, digit_version from .dist_utils import allreduce_grads as _allr...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/fp16_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import functools import os import subprocess from collections import OrderedDict import torch import torch.multiprocessing as mp from torch import distributed as dist from torch._utils import (_flatten_dense_tensors, _take_tensors, _unflatten_de...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/dist_utils.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/optimizer/default_constructor.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', '...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/optimizer/__init__.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/optimizer/builder.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, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/momentum_updater.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. ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/checkpoint.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/memory.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):...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/sync_buffer.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/ema.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/evaluation.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', ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/hook.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/__init__.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` ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/sampler_seed.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/optimizer.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/lr_updater.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/profiler.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)
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/closure.py
# Copyright (c) OpenMMLab. All rights reserved. import time from .hook import HOOKS, Hook @HOOKS.register_module() class IterTimerHook(Hook): def before_epoch(self, runner): self.t = time.time() def before_iter(self, runner): runner.log_buffer.update({'data_time': time.time() - self.t}) ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/iter_timer.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, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/mlflow.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=...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/wandb.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/__init__.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)...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/dvclive.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/text.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/pavi.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/base.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__...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/tensorboard.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/runner/hooks/logger/neptune.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 ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/version_utils.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/logging.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/misc.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/trace.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/config.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/env.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"....
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/registry.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 ((...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/parrots_wrapper.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/timer.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/__init__.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/ext_loader.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, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/parrots_jit.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/progressbar.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/testing.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/utils/path.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import annotator.uniformer.mmcv as mmcv try: import torch except ImportError: torch = None def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True): """Convert tensor to 3-channel images. Args: tensor (torch.Tenso...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/misc.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers import cv2 import numpy as np from ..utils import to_2tuple from .io import imread_backend try: from PIL import Image except ImportError: Image = None def _scale_size(size, scale): """Rescale a size by a ratio. Args: size (tupl...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/geometric.py
# Copyright (c) OpenMMLab. All rights reserved. import cv2 import numpy as np def imconvert(img, src, dst): """Convert an image from the src colorspace to dst colorspace. Args: img (ndarray): The input image. src (str): The source colorspace, e.g., 'rgb', 'hsv'. dst (str): The destina...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/colorspace.py
# Copyright (c) OpenMMLab. All rights reserved. import io import os.path as osp from pathlib import Path import cv2 import numpy as np from cv2 import (IMREAD_COLOR, IMREAD_GRAYSCALE, IMREAD_IGNORE_ORIENTATION, IMREAD_UNCHANGED) from annotator.uniformer.mmcv.utils import check_file_exist, is_str, mkd...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/io.py
# Copyright (c) OpenMMLab. All rights reserved. from .colorspace import (bgr2gray, bgr2hls, bgr2hsv, bgr2rgb, bgr2ycbcr, gray2bgr, gray2rgb, hls2bgr, hsv2bgr, imconvert, rgb2bgr, rgb2gray, rgb2ycbcr, ycbcr2bgr, ycbcr2rgb) from .geometric import (cutout, imcrop, imflip, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/__init__.py
# Copyright (c) OpenMMLab. All rights reserved. import cv2 import numpy as np from ..utils import is_tuple_of from .colorspace import bgr2gray, gray2bgr def imnormalize(img, mean, std, to_rgb=True): """Normalize an image with mean and std. Args: img (ndarray): Image to be normalized. mean (n...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/image/photometric.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,...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/vgg.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, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/__init__.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/builder.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/resnet.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/alexnet.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/context_block.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/depthwise_separable_conv_module.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/registry.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/generalized_attention.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/norm.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: ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/hswish.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/__init__.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....
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/upsample.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 ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/non_local.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/conv_ws.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/hsigmoid.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/activation.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/wrappers.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/transformer.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: ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/swish.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 ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/plugin.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/conv.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/conv_module.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/padding.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): ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/scale.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/drop.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/bricks/conv2d_adaptive_padding.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/utils/__init__.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/utils/fuse_conv_bn.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/utils/flops_counter.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/utils/sync_bn.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/cnn/utils/weight_init.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/deform_conv.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....
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/points_in_boxes.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', ['dynamic_point_to_voxel_forward', 'dynamic_point_to_voxel_backward']) class _DynamicScatter(Function): @staticm...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/scatter_points.py
# Copyright (c) OpenMMLab. All rights reserved. # Code reference from "Temporal Interlacing Network" # https://github.com/deepcs233/TIN/blob/master/cuda_shift/rtc_wrap.py # Hao Shao, Shengju Qian, Yu Liu # shaoh19@mails.tsinghua.edu.cn, sjqian@cse.cuhk.edu.hk, yuliu@ee.cuhk.edu.hk import torch import torch.nn as nn fr...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/tin_shift.py
import torch from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext( '_ext', ['gather_points_forward', 'gather_points_backward']) class GatherPoints(Function): """Gather points with given index.""" @staticmethod def forward(ctx, features: torch.Tensor, ...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/gather_points.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.autograd import Function from ..utils import ext_loader ext_module = ext_loader.load_ext('_ext', ['ball_query_forward']) class BallQuery(Function): """Find nearby points in spherical space.""" @staticmethod def forward(ctx, min_rad...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/ball_query.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/modulated_deform_conv.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/merge_cells.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...
trt-samples-for-hackathon-cn-master
Hackathon2023/controlnet/annotator/uniformer/mmcv/ops/group_points.py