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/mmseg/models/decode_heads/cc_head.py
.py
import torch from ..builder import HEADS from .fcn_head import FCNHead try: from annotator.uniformer.mmcv.ops import CrissCrossAttention except ModuleNotFoundError: CrissCrossAttention = None @HEADS.register_module() class CCHead(FCNHead): """CCNet: Criss-Cross Attention for Semantic Segmentation. ...
43
1,303
ControlNet
annotator/uniformer/mmseg/models/decode_heads/ema_head.py
.py
import math import torch import torch.distributed as dist import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule from ..builder import HEADS from .decode_head import BaseDecodeHead def reduce_mean(tensor): """Reduce mean when distributed training.""" if not...
169
5,796
ControlNet
annotator/uniformer/mmseg/models/decode_heads/sep_fcn_head.py
.py
from annotator.uniformer.mmcv.cnn import DepthwiseSeparableConvModule from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class DepthwiseSeparableFCNHead(FCNHead): """Depthwise-Separable Fully Convolutional Network for Semantic Segmentation. This head is implemented accord...
52
2,024
ControlNet
annotator/uniformer/mmseg/models/decode_heads/ann_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .decode_head import BaseDecodeHead class PPMConcat(nn.ModuleList): """Pyramid Pooling Module that only concat the features of each ...
246
9,194
ControlNet
annotator/uniformer/mmseg/models/decode_heads/decode_head.py
.py
from abc import ABCMeta, abstractmethod import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import normal_init from annotator.uniformer.mmcv.runner import auto_fp16, force_fp32 from annotator.uniformer.mmseg.core import build_pixel_sampler from annotator.uniformer.mmseg.ops import resize from ..build...
235
9,240
ControlNet
annotator/uniformer/mmseg/models/decode_heads/uper_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead from .psp_head import PPM @HEADS.register_module() class UPerHead(BaseDecodeHead): """Unified Perceptual Pars...
127
4,012
ControlNet
annotator/uniformer/mmseg/models/decode_heads/point_head.py
.py
# Modified from https://github.com/facebookresearch/detectron2/tree/master/projects/PointRend/point_head/point_head.py # noqa import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule, normal_init from annotator.uniformer.mmcv.ops import point_sample from annotator.uniformer.mmseg.models...
350
14,754
ControlNet
annotator/uniformer/mmseg/models/decode_heads/nl_head.py
.py
import torch from annotator.uniformer.mmcv.cnn import NonLocal2d from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class NLHead(FCNHead): """Non-local Neural Networks. This head is the implementation of `NLNet <https://arxiv.org/abs/1711.07971>`_. Args: redu...
50
1,577
ControlNet
annotator/uniformer/mmseg/models/decode_heads/dm_head.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule, build_activation_layer, build_norm_layer from ..builder import HEADS from .decode_head import BaseDecodeHead class DCM(nn.Module): """Dynamic Convolutional Module used in DMNet. Args: ...
141
5,004
ControlNet
annotator/uniformer/mmseg/models/decode_heads/da_head.py
.py
import torch import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule, Scale from torch import nn from annotator.uniformer.mmseg.core import add_prefix from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .decode_head import BaseDecodeHead class PA...
179
5,585
ControlNet
annotator/uniformer/mmseg/models/decode_heads/lraspp_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv import is_tuple_of from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class LRASPPHead(BaseDecodeHead): "...
91
3,098
ControlNet
annotator/uniformer/mmseg/models/decode_heads/sep_aspp_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule, DepthwiseSeparableConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .aspp_head import ASPPHead, ASPPModule class DepthwiseSeparableASPPModule(ASPPModule): """Atrous Spatial Pyramid P...
102
3,527
ControlNet
annotator/uniformer/mmseg/models/decode_heads/cascade_decode_head.py
.py
from abc import ABCMeta, abstractmethod from .decode_head import BaseDecodeHead class BaseCascadeDecodeHead(BaseDecodeHead, metaclass=ABCMeta): """Base class for cascade decode head used in :class:`CascadeEncoderDecoder.""" def __init__(self, *args, **kwargs): super(BaseCascadeDecodeHead, self)....
58
2,351
ControlNet
annotator/uniformer/mmseg/models/decode_heads/fpn_head.py
.py
import numpy as np import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class FPNHead(BaseDecodeHead): """Panoptic Feature Pyramid Networks. This...
69
2,422
ControlNet
annotator/uniformer/mmseg/models/decode_heads/ocr_head.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .cascade_decode_head import BaseCascadeDecodeHead clas...
128
4,319
ControlNet
annotator/uniformer/mmseg/models/decode_heads/psa_head.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead try: from annotator.uniformer.mmcv.ops import PSAMask except ModuleNotFoundErr...
197
7,544
ControlNet
annotator/uniformer/mmseg/models/decode_heads/gc_head.py
.py
import torch from annotator.uniformer.mmcv.cnn import ContextBlock from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class GCHead(FCNHead): """GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond. This head is the implementation of `GCNet <https://arxiv....
48
1,611
ControlNet
annotator/uniformer/mmseg/models/decode_heads/dnl_head.py
.py
import torch from annotator.uniformer.mmcv.cnn import NonLocal2d from torch import nn from ..builder import HEADS from .fcn_head import FCNHead class DisentangledNonLocal2d(NonLocal2d): """Disentangled Non-Local Blocks. Args: temperature (float): Temperature to adjust attention. Default: 0.05 ""...
132
4,591
ControlNet
annotator/uniformer/mmseg/models/decode_heads/aspp_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class ASPPModule(nn.ModuleList): """Atrous Spatial Pyramid Pooling (ASPP) Module. Args: dilation...
108
3,459
ControlNet
annotator/uniformer/mmseg/models/decode_heads/psp_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class PPM(nn.ModuleList): """Pooling Pyramid Module used in PSPNet. Args: pool_scales (tuple[int...
102
3,352
ControlNet
annotator/uniformer/mmseg/models/decode_heads/fcn_head.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class FCNHead(BaseDecodeHead): """Fully Convolution Networks for Semantic Segmentation. This head is implemented of `FCNNet <htt...
82
2,817
ControlNet
annotator/uniformer/mmseg/models/decode_heads/apc_head.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule from annotator.uniformer.mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class ACM(nn.Module): """Adaptive Context Module used in APCNet. Args: ...
159
5,572
ControlNet
annotator/uniformer/mmseg/models/backbones/unet.py
.py
import torch.nn as nn import torch.utils.checkpoint as cp from annotator.uniformer.mmcv.cnn import (UPSAMPLE_LAYERS, ConvModule, build_activation_layer, build_norm_layer, constant_init, kaiming_init) from annotator.uniformer.mmcv.runner import load_checkpoint from annotator.uniformer.mmcv.utils.pa...
430
18,269
ControlNet
annotator/uniformer/mmseg/models/backbones/resnext.py
.py
import math from annotator.uniformer.mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from ..utils import ResLayer from .resnet import Bottleneck as _Bottleneck from .resnet import ResNet class Bottleneck(_Bottleneck): """Bottleneck block for ResNeXt. If style is "pytorch"...
146
5,161
ControlNet
annotator/uniformer/mmseg/models/backbones/fast_scnn.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import (ConvModule, DepthwiseSeparableConvModule, constant_init, kaiming_init) from torch.nn.modules.batchnorm import _BatchNorm from annotator.uniformer.mmseg.models.decode_heads.psp_head import PPM from annotator.uniformer.mms...
376
14,436
ControlNet
annotator/uniformer/mmseg/models/backbones/mobilenet_v3.py
.py
import logging import annotator.uniformer.mmcv as mmcv import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule, constant_init, kaiming_init from annotator.uniformer.mmcv.cnn.bricks import Conv2dAdaptivePadding from annotator.uniformer.mmcv.runner import load_checkpoint from torch.nn.modules.batchnorm...
256
10,390
ControlNet
annotator/uniformer/mmseg/models/backbones/resnet.py
.py
import torch.nn as nn import torch.utils.checkpoint as cp from annotator.uniformer.mmcv.cnn import (build_conv_layer, build_norm_layer, build_plugin_layer, constant_init, kaiming_init) from annotator.uniformer.mmcv.runner import load_checkpoint from annotator.uniformer.mmcv.utils.parrots_wrapper i...
689
24,310
ControlNet
annotator/uniformer/mmseg/models/backbones/__init__.py
.py
from .cgnet import CGNet # from .fast_scnn import FastSCNN from .hrnet import HRNet from .mobilenet_v2 import MobileNetV2 from .mobilenet_v3 import MobileNetV3 from .resnest import ResNeSt from .resnet import ResNet, ResNetV1c, ResNetV1d from .resnext import ResNeXt from .unet import UNet from .vit import VisionTransfo...
18
532
ControlNet
annotator/uniformer/mmseg/models/backbones/cgnet.py
.py
import torch import torch.nn as nn import torch.utils.checkpoint as cp from annotator.uniformer.mmcv.cnn import (ConvModule, build_conv_layer, build_norm_layer, constant_init, kaiming_init) from annotator.uniformer.mmcv.runner import load_checkpoint from annotator.uniformer.mmcv.utils.parrots_wrap...
368
13,183
ControlNet
annotator/uniformer/mmseg/models/backbones/mobilenet_v2.py
.py
import logging import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule, constant_init, kaiming_init from annotator.uniformer.mmcv.runner import load_checkpoint from torch.nn.modules.batchnorm import _BatchNorm from ..builder import BACKBONES from ..utils import InvertedResidual, make_divisible @BA...
181
6,981
ControlNet
annotator/uniformer/mmseg/models/backbones/hrnet.py
.py
import torch.nn as nn from annotator.uniformer.mmcv.cnn import (build_conv_layer, build_norm_layer, constant_init, kaiming_init) from annotator.uniformer.mmcv.runner import load_checkpoint from annotator.uniformer.mmcv.utils.parrots_wrapper import _BatchNorm from annotator.uniformer.mmseg.ops imp...
556
21,226
ControlNet
annotator/uniformer/mmseg/models/backbones/resnest.py
.py
import math import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from annotator.uniformer.mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from ..utils import ResLayer from .resnet import Bottleneck as _Bottleneck from .resnet import ...
315
10,110
ControlNet
annotator/uniformer/mmseg/models/backbones/vit.py
.py
"""Modified from https://github.com/rwightman/pytorch-image- models/blob/master/timm/models/vision_transformer.py.""" import math import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from annotator.uniformer.mmcv.cnn import (Conv2d, Linear, build_activation_layer, bui...
460
18,085
ControlNet
annotator/uniformer/mmseg/models/backbones/uniformer.py
.py
# -------------------------------------------------------- # UniFormer # Copyright (c) 2022 SenseTime X-Lab # Licensed under The MIT License [see LICENSE for details] # Written by Kunchang Li # -------------------------------------------------------- from collections import OrderedDict import math from functools impo...
423
18,476
ControlNet
annotator/uniformer/mmseg/models/losses/lovasz_loss.py
.py
"""Modified from https://github.com/bermanmaxim/LovaszSoftmax/blob/master/pytor ch/lovasz_losses.py Lovasz-Softmax and Jaccard hinge loss in PyTorch Maxim Berman 2018 ESAT-PSI KU Leuven (MIT License)""" import annotator.uniformer.mmcv as mmcv import torch import torch.nn as nn import torch.nn.functional as F from ..b...
304
11,419
ControlNet
annotator/uniformer/mmseg/models/losses/utils.py
.py
import functools import annotator.uniformer.mmcv as mmcv import numpy as np import torch.nn.functional as F def get_class_weight(class_weight): """Get class weight for loss function. Args: class_weight (list[float] | str | None): If class_weight is a str, take it as a file name and read ...
122
3,718
ControlNet
annotator/uniformer/mmseg/models/losses/cross_entropy_loss.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from ..builder import LOSSES from .utils import get_class_weight, weight_reduce_loss def cross_entropy(pred, label, weight=None, class_weight=None, reduction='mean', ...
199
7,437
ControlNet
annotator/uniformer/mmseg/models/losses/__init__.py
.py
from .accuracy import Accuracy, accuracy from .cross_entropy_loss import (CrossEntropyLoss, binary_cross_entropy, cross_entropy, mask_cross_entropy) from .dice_loss import DiceLoss from .lovasz_loss import LovaszLoss from .utils import reduce_loss, weight_reduce_loss, weighted_loss __a...
13
529
ControlNet
annotator/uniformer/mmseg/models/losses/accuracy.py
.py
import torch.nn as nn def accuracy(pred, target, topk=1, thresh=None): """Calculate accuracy according to the prediction and target. Args: pred (torch.Tensor): The model prediction, shape (N, num_class, ...) target (torch.Tensor): The target of each prediction, shape (N, , ...) topk (...
79
2,970
ControlNet
annotator/uniformer/mmseg/models/losses/dice_loss.py
.py
"""Modified from https://github.com/LikeLy-Journey/SegmenTron/blob/master/ segmentron/solver/loss.py (Apache-2.0 License)""" import torch import torch.nn as nn import torch.nn.functional as F from ..builder import LOSSES from .utils import get_class_weight, weighted_loss @weighted_loss def dice_loss(pred, ...
120
4,239
ControlNet
annotator/uniformer/mmseg/models/utils/se_layer.py
.py
import annotator.uniformer.mmcv as mmcv import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule from .make_divisible import make_divisible class SELayer(nn.Module): """Squeeze-and-Excitation Module. Args: channels (int): The input (and output) channels of the SE layer. rati...
58
2,151
ControlNet
annotator/uniformer/mmseg/models/utils/res_layer.py
.py
from annotator.uniformer.mmcv.cnn import build_conv_layer, build_norm_layer from torch import nn as nn class ResLayer(nn.Sequential): """ResLayer to build ResNet style backbone. Args: block (nn.Module): block used to build ResLayer. inplanes (int): inplanes of block. planes (int): pla...
95
3,335
ControlNet
annotator/uniformer/mmseg/models/utils/__init__.py
.py
from .drop import DropPath from .inverted_residual import InvertedResidual, InvertedResidualV3 from .make_divisible import make_divisible from .res_layer import ResLayer from .se_layer import SELayer from .self_attention_block import SelfAttentionBlock from .up_conv_block import UpConvBlock from .weight_init import tru...
14
502
ControlNet
annotator/uniformer/mmseg/models/utils/inverted_residual.py
.py
from annotator.uniformer.mmcv.cnn import ConvModule from torch import nn from torch.utils import checkpoint as cp from .se_layer import SELayer class InvertedResidual(nn.Module): """InvertedResidual block for MobileNetV2. Args: in_channels (int): The input channels of the InvertedResidual block. ...
209
7,025
ControlNet
annotator/uniformer/mmseg/models/utils/self_attention_block.py
.py
import torch from annotator.uniformer.mmcv.cnn import ConvModule, constant_init from torch import nn as nn from torch.nn import functional as F class SelfAttentionBlock(nn.Module): """General self-attention block/non-local block. Please refer to https://arxiv.org/abs/1706.03762 for details about key, que...
160
6,145
ControlNet
annotator/uniformer/mmseg/models/utils/drop.py
.py
"""Modified from https://github.com/rwightman/pytorch-image- models/blob/master/timm/models/layers/drop.py.""" import torch from torch import nn class DropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks). Args: drop_prob (float): Drop r...
32
1,015
ControlNet
annotator/uniformer/mmseg/models/utils/make_divisible.py
.py
def make_divisible(value, divisor, min_value=None, min_ratio=0.9): """Make divisible function. This function rounds the channel number to the nearest value that can be divisible by the divisor. It is taken from the original tf repo. It ensures that all layers have a channel number that is divisible by ...
28
1,231
ControlNet
annotator/uniformer/mmseg/models/utils/weight_init.py
.py
"""Modified from https://github.com/rwightman/pytorch-image- models/blob/master/timm/models/layers/drop.py.""" import math import warnings import torch def _no_grad_trunc_normal_(tensor, mean, std, a, b): """Reference: https://people.sc.fsu.edu/~jburkardt/presentations /truncated_normal.pdf""" def norm...
63
2,327
ControlNet
annotator/uniformer/mmseg/models/utils/up_conv_block.py
.py
import torch import torch.nn as nn from annotator.uniformer.mmcv.cnn import ConvModule, build_upsample_layer class UpConvBlock(nn.Module): """Upsample convolution block in decoder for UNet. This upsample convolution block consists of one upsample module followed by one convolution block. The upsample mod...
102
3,988
ControlNet
annotator/uniformer/mmseg/models/segmentors/encoder_decoder.py
.py
import torch import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmseg.core import add_prefix from annotator.uniformer.mmseg.ops import resize from .. import builder from ..builder import SEGMENTORS from .base import BaseSegmentor @SEGMENTORS.register_module() class EncoderDecoder(BaseSegm...
299
11,344
ControlNet
annotator/uniformer/mmseg/models/segmentors/cascade_encoder_decoder.py
.py
from torch import nn from annotator.uniformer.mmseg.core import add_prefix from annotator.uniformer.mmseg.ops import resize from .. import builder from ..builder import SEGMENTORS from .encoder_decoder import EncoderDecoder @SEGMENTORS.register_module() class CascadeEncoderDecoder(EncoderDecoder): """Cascade Enc...
99
3,708
ControlNet
annotator/uniformer/mmseg/models/segmentors/base.py
.py
import logging import warnings from abc import ABCMeta, abstractmethod from collections import OrderedDict import annotator.uniformer.mmcv as mmcv import numpy as np import torch import torch.distributed as dist import torch.nn as nn from annotator.uniformer.mmcv.runner import auto_fp16 class BaseSegmentor(nn.Module...
274
10,398
ControlNet
annotator/uniformer/mmseg/models/necks/__init__.py
.py
from .fpn import FPN from .multilevel_neck import MultiLevelNeck __all__ = ['FPN', 'MultiLevelNeck']
5
102
ControlNet
annotator/uniformer/mmseg/models/necks/multilevel_neck.py
.py
import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule from ..builder import NECKS @NECKS.register_module() class MultiLevelNeck(nn.Module): """MultiLevelNeck. A neck structure connect vit backbone and decoder_heads. Args: in_channels (List[int]...
71
2,454
ControlNet
annotator/uniformer/mmseg/models/necks/fpn.py
.py
import torch.nn as nn import torch.nn.functional as F from annotator.uniformer.mmcv.cnn import ConvModule, xavier_init from ..builder import NECKS @NECKS.register_module() class FPN(nn.Module): """Feature Pyramid Network. This is an implementation of - Feature Pyramid Networks for Object Detection (http...
213
9,159
ControlNet
annotator/uniformer/mmcv/version.py
.py
# Copyright (c) OpenMMLab. All rights reserved. __version__ = '1.3.17' def parse_version_info(version_str: str, length: int = 4) -> tuple: """Parse a version string into a tuple. Args: version_str (str): The version string. length (int): The maximum number of version levels. Default: 4. ...
36
1,177
ControlNet
annotator/uniformer/mmcv/fileio/parse.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from io import StringIO from .file_client import FileClient def list_from_file(filename, prefix='', offset=0, max_num=0, encoding='utf-8', file_client_args=None): """Loa...
98
3,458
ControlNet
annotator/uniformer/mmcv/fileio/io.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from io import BytesIO, StringIO from pathlib import Path from ..utils import is_list_of, is_str from .file_client import FileClient from .handlers import BaseFileHandler, JsonHandler, PickleHandler, YamlHandler file_handlers = { 'json': JsonHandler(), 'yaml': Y...
152
5,520
ControlNet
annotator/uniformer/mmcv/fileio/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .file_client import BaseStorageBackend, FileClient from .handlers import BaseFileHandler, JsonHandler, PickleHandler, YamlHandler from .io import dump, load, register_handler from .parse import dict_from_file, list_from_file __all__ = [ 'BaseStorageBackend', 'Fi...
12
478
ControlNet
annotator/uniformer/mmcv/fileio/file_client.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import inspect import os import os.path as osp import re import tempfile import warnings from abc import ABCMeta, abstractmethod from contextlib import contextmanager from pathlib import Path from typing import Iterable, Iterator, Optional, Tuple, Union from urllib.reques...
1,149
41,933
ControlNet
annotator/uniformer/mmcv/fileio/handlers/json_handler.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import json import numpy as np from .base import BaseFileHandler def set_default(obj): """Set default json values for non-serializable values. It helps convert ``set``, ``range`` and ``np.ndarray`` data types to list. It also converts ``np.generic`` (incl...
37
1,068
ControlNet
annotator/uniformer/mmcv/fileio/handlers/pickle_handler.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import pickle from .base import BaseFileHandler class PickleHandler(BaseFileHandler): str_like = False def load_from_fileobj(self, file, **kwargs): return pickle.load(file, **kwargs) def load_from_path(self, filepath, **kwargs): return su...
29
817
ControlNet
annotator/uniformer/mmcv/fileio/handlers/base.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import ABCMeta, abstractmethod class BaseFileHandler(metaclass=ABCMeta): # `str_like` is a flag to indicate whether the type of file object is # str-like object or bytes-like object. Pickle only processes bytes-like # objects but json only processes...
31
993
ControlNet
annotator/uniformer/mmcv/fileio/handlers/yaml_handler.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import yaml try: from yaml import CLoader as Loader, CDumper as Dumper except ImportError: from yaml import Loader, Dumper from .base import BaseFileHandler # isort:skip class YamlHandler(BaseFileHandler): def load_from_fileobj(self, file, **kwargs): ...
25
665
ControlNet
annotator/uniformer/mmcv/image/misc.py
.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...
45
1,410
ControlNet
annotator/uniformer/mmcv/image/io.py
.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...
259
9,572
ControlNet
annotator/uniformer/mmcv/image/colorspace.py
.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...
307
9,907
ControlNet
annotator/uniformer/mmcv/image/__init__.py
.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, ...
29
1,725
ControlNet
annotator/uniformer/mmcv/image/geometric.py
.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...
729
25,196
ControlNet
annotator/uniformer/mmcv/image/photometric.py
.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...
429
14,999
ControlNet
annotator/uniformer/mmcv/parallel/distributed_deprecated.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.distributed as dist import torch.nn as nn from torch._utils import (_flatten_dense_tensors, _take_tensors, _unflatten_dense_tensors) from annotator.uniformer.mmcv.utils import TORCH_VERSION, digit_version from .registry...
71
2,837
ControlNet
annotator/uniformer/mmcv/parallel/utils.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .registry import MODULE_WRAPPERS def is_module_wrapper(module): """Check if a module is a module wrapper. The following 3 modules in MMCV (and their subclasses) are regarded as module wrappers: DataParallel, DistributedDataParallel, MMDistributedDa...
21
708
ControlNet
annotator/uniformer/mmcv/parallel/distributed.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.nn.parallel.distributed import (DistributedDataParallel, _find_tensors) from annotator.uniformer.mmcv import print_log from annotator.uniformer.mmcv.utils import TORCH_VERSION, digit_version from .scatter...
113
4,857
ControlNet
annotator/uniformer/mmcv/parallel/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .collate import collate from .data_container import DataContainer from .data_parallel import MMDataParallel from .distributed import MMDistributedDataParallel from .registry import MODULE_WRAPPERS from .scatter_gather import scatter, scatter_kwargs from .utils import...
14
505
ControlNet
annotator/uniformer/mmcv/parallel/registry.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from torch.nn.parallel import DataParallel, DistributedDataParallel from annotator.uniformer.mmcv.utils import Registry MODULE_WRAPPERS = Registry('module wrapper') MODULE_WRAPPERS.register_module(module=DataParallel) MODULE_WRAPPERS.register_module(module=DistributedDa...
9
332
ControlNet
annotator/uniformer/mmcv/parallel/collate.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from collections.abc import Mapping, Sequence import torch import torch.nn.functional as F from torch.utils.data.dataloader import default_collate from .data_container import DataContainer def collate(batch, samples_per_gpu=1): """Puts each data field into a tenso...
85
3,665
ControlNet
annotator/uniformer/mmcv/parallel/_functions.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.nn.parallel._functions import _get_stream def scatter(input, devices, streams=None): """Scatters tensor across multiple GPUs.""" if streams is None: streams = [None] * len(devices) if isinstance(input, list): chunk_si...
80
2,830
ControlNet
annotator/uniformer/mmcv/parallel/data_container.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import functools import torch def assert_tensor_type(func): @functools.wraps(func) def wrapper(*args, **kwargs): if not isinstance(args[0].data, torch.Tensor): raise AttributeError( f'{args[0].__class__.__name__} has no attr...
90
2,365
ControlNet
annotator/uniformer/mmcv/parallel/data_parallel.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from itertools import chain from torch.nn.parallel import DataParallel from .scatter_gather import scatter_kwargs class MMDataParallel(DataParallel): """The DataParallel module that supports DataContainer. MMDataParallel has two main differences with PyTorch ...
90
3,912
ControlNet
annotator/uniformer/mmcv/parallel/scatter_gather.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.nn.parallel._functions import Scatter as OrigScatter from ._functions import Scatter from .data_container import DataContainer def scatter(inputs, target_gpus, dim=0): """Scatter inputs to target gpus. The only difference from original ...
60
2,307
ControlNet
annotator/uniformer/mmcv/engine/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .test import (collect_results_cpu, collect_results_gpu, multi_gpu_test, single_gpu_test) __all__ = [ 'collect_results_cpu', 'collect_results_gpu', 'multi_gpu_test', 'single_gpu_test' ]
9
266
ControlNet
annotator/uniformer/mmcv/engine/test.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import pickle import shutil import tempfile import time import torch import torch.distributed as dist import annotator.uniformer.mmcv as mmcv from annotator.uniformer.mmcv.runner import get_dist_info def single_gpu_test(model, data_loader): "...
203
7,196
ControlNet
annotator/uniformer/mmcv/visualization/color.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from enum import Enum import numpy as np from annotator.uniformer.mmcv.utils import is_str class Color(Enum): """An enum that defines common colors. Contains red, green, blue, cyan, yellow, magenta, white and black. """ red = (0, 0, 255) green = (...
52
1,381
ControlNet
annotator/uniformer/mmcv/visualization/optflow.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from __future__ import division import numpy as np from annotator.uniformer.mmcv.image import rgb2bgr from annotator.uniformer.mmcv.video import flowread from .image import imshow def flowshow(flow, win_name='', wait_time=0): """Show optical flow. Args: ...
113
3,389
ControlNet
annotator/uniformer/mmcv/visualization/__init__.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from .color import Color, color_val from .image import imshow, imshow_bboxes, imshow_det_bboxes from .optflow import flow2rgb, flowshow, make_color_wheel __all__ = [ 'Color', 'color_val', 'imshow', 'imshow_bboxes', 'imshow_det_bboxes', 'flowshow', 'flow2rgb', 'ma...
10
338
ControlNet
annotator/uniformer/mmcv/visualization/image.py
.py
# Copyright (c) OpenMMLab. All rights reserved. import cv2 import numpy as np from annotator.uniformer.mmcv.image import imread, imwrite from .color import color_val def imshow(img, win_name='', wait_time=0): """Show an image. Args: img (str or ndarray): The image to be displayed. win_name (...
153
5,145
ControlNet
annotator/uniformer/mmcv/runner/checkpoint.py
.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...
708
25,136
ControlNet
annotator/uniformer/mmcv/runner/default_constructor.py
.py
from .builder import RUNNER_BUILDERS, RUNNERS @RUNNER_BUILDERS.register_module() class DefaultRunnerConstructor: """Default constructor for runners. Custom existing `Runner` like `EpocBasedRunner` though `RunnerConstructor`. For example, We can inject some new properties and functions for `Runner`. ...
45
1,928
ControlNet
annotator/uniformer/mmcv/runner/utils.py
.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...
94
2,936
ControlNet
annotator/uniformer/mmcv/runner/builder.py
.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) ...
25
666
ControlNet
annotator/uniformer/mmcv/runner/epoch_based_runner.py
.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...
188
7,565
ControlNet
annotator/uniformer/mmcv/runner/base_module.py
.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...
196
7,502
ControlNet
annotator/uniformer/mmcv/runner/__init__.py
.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, ...
48
2,859
ControlNet
annotator/uniformer/mmcv/runner/priority.py
.py
# Copyright (c) OpenMMLab. All rights reserved. from enum import Enum class Priority(Enum): """Hook priority levels. +--------------+------------+ | Level | Value | +==============+============+ | HIGHEST | 0 | +--------------+------------+ | VERY_HIGH | 10 ...
61
1,598
ControlNet
annotator/uniformer/mmcv/runner/base_runner.py
.py
# 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...
543
20,846
ControlNet
annotator/uniformer/mmcv/runner/fp16_utils.py
.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...
411
15,784
ControlNet
annotator/uniformer/mmcv/runner/iter_based_runner.py
.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...
274
11,062
ControlNet
annotator/uniformer/mmcv/runner/log_buffer.py
.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): ...
42
1,192
ControlNet
annotator/uniformer/mmcv/runner/dist_utils.py
.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...
165
5,395
ControlNet
annotator/uniformer/mmcv/runner/hooks/iter_timer.py
.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}) ...
19
446