Search is not available for this dataset
repo stringlengths 2 152 ⌀ | file stringlengths 15 239 | code stringlengths 0 58.4M | file_length int64 0 58.4M | avg_line_length float64 0 1.81M | max_line_length int64 0 12.7M | extension_type stringclasses 364
values |
|---|---|---|---|---|---|---|
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/coarse_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import ConvModule, Linear
from mmcv.runner import ModuleList, auto_fp16
from mmdet.models.builder import HEADS
from .fcn_mask_head import FCNMaskHead
@HEADS.register_module()
class CoarseMaskHead(FCNMaskHead):
"""Coarse mask head used in PointRend.
... | 3,551 | 34.168317 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/dynamic_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.runner import auto_fp16, force_fp32
from mmdet.core import mask_target
from mmdet.models.builder import HEADS
from mmdet.models.dense_heads.atss_head import reduce_mean
from mmdet.models.utils import build_transformer
from .fc... | 5,665 | 37.283784 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from warnings import warn
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule, build_conv_layer, build_upsample_layer
from mmcv.ops.carafe import CARAFEPack
from mmcv.runner import BaseModule, ModuleList, ... | 17,449 | 41.251816 | 85 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/feature_relay_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.runner import BaseModule, auto_fp16
from mmdet.models.builder import HEADS
@HEADS.register_module()
class FeatureRelayHead(BaseModule):
"""Feature Relay Head used in `SCNet <https://arxiv.org/abs/2012.10150>`_.
Args:
in_... | 1,930 | 34.759259 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/fused_semantic_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, auto_fp16, force_fp32
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class FusedSemanticHead(BaseModu... | 4,231 | 34.563025 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/global_context_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, auto_fp16, force_fp32
from mmdet.models.builder import HEADS
from mmdet.models.utils import ResLayer, SimplifiedBasicBlock
@HEADS.register_module()
class GlobalContextHead(BaseMod... | 3,774 | 36.009804 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/grid_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class GridHead(BaseModule):
def __i... | 15,579 | 41.802198 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/htc_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import ConvModule
from mmdet.models.builder import HEADS
from .fcn_mask_head import FCNMaskHead
@HEADS.register_module()
class HTCMaskHead(FCNMaskHead):
def __init__(self, with_conv_res=True, *args, **kwargs):
super(HTCMaskHead, self).__init_... | 1,282 | 31.075 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/mask_point_head.py | # Copyright (c) OpenMMLab. All rights reserved.
# 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 mmcv.cnn import ConvModule
from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
from mmcv.r... | 10,785 | 41.464567 | 126 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/maskiou_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import Conv2d, Linear, MaxPool2d
from mmcv.runner import BaseModule, force_fp32
from torch.nn.modules.utils import _pair
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
clas... | 7,382 | 39.125 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/scnet_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmdet.models.builder import HEADS
from mmdet.models.utils import ResLayer, SimplifiedBasicBlock
from .fcn_mask_head import FCNMaskHead
@HEADS.register_module()
class SCNetMaskHead(FCNMaskHead):
"""Mask head for `SCNet <https://arxiv.org/abs/2012.10150>`_.
... | 979 | 32.793103 | 72 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/mask_heads/scnet_semantic_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmdet.models.builder import HEADS
from mmdet.models.utils import ResLayer, SimplifiedBasicBlock
from .fused_semantic_head import FusedSemanticHead
@HEADS.register_module()
class SCNetSemanticHead(FusedSemanticHead):
"""Mask head for `SCNet <https://arxiv.org/ab... | 998 | 33.448276 | 72 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/roi_extractors/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .base_roi_extractor import BaseRoIExtractor
from .generic_roi_extractor import GenericRoIExtractor
from .single_level_roi_extractor import SingleRoIExtractor
__all__ = ['BaseRoIExtractor', 'SingleRoIExtractor', 'GenericRoIExtractor']
| 288 | 40.285714 | 75 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/roi_extractors/base_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
from abc import ABCMeta, abstractmethod
import torch
import torch.nn as nn
from mmcv import ops
from mmcv.runner import BaseModule
class BaseRoIExtractor(BaseModule, metaclass=ABCMeta):
"""Base class for RoI extractor.
Args:
roi_layer (dict): Specify R... | 3,002 | 32.741573 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/roi_extractors/generic_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn.bricks import build_plugin_layer
from mmcv.runner import force_fp32
from mmdet.models.builder import ROI_EXTRACTORS
from .base_roi_extractor import BaseRoIExtractor
@ROI_EXTRACTORS.register_module()
class GenericRoIExtractor(BaseRoIExtractor):
"""Extr... | 3,282 | 37.623529 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.runner import force_fp32
from mmdet.models.builder import ROI_EXTRACTORS
from .base_roi_extractor import BaseRoIExtractor
@ROI_EXTRACTORS.register_module()
class SingleRoIExtractor(BaseRoIExtractor):
"""Extract RoI features from a single leve... | 4,736 | 40.920354 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/shared_heads/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .res_layer import ResLayer
__all__ = ['ResLayer']
| 104 | 20 | 47 | py |
mmdetection | mmdetection-master/mmdet/models/roi_heads/shared_heads/res_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
from mmcv.runner import BaseModule, auto_fp16
from mmdet.models.backbones import ResNet
from mmdet.models.builder import SHARED_HEADS
from mmdet.models.utils import ResLayer as _ResLayer
@SHARED_HEADS.register_module()
class ResLa... | 2,587 | 30.950617 | 76 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .panoptic_fpn_head import PanopticFPNHead # noqa: F401,F403
from .panoptic_fusion_heads import * # noqa: F401,F403
| 170 | 41.75 | 65 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/base_semantic_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from abc import ABCMeta, abstractmethod
import torch.nn.functional as F
from mmcv.runner import BaseModule, force_fp32
from ..builder import build_loss
from ..utils import interpolate_as
class BaseSemanticHead(BaseModule, metaclass=ABCMeta):
"""Base module of Sema... | 2,849 | 31.758621 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/panoptic_fpn_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch
import torch.nn as nn
from mmcv.runner import ModuleList
from ..builder import HEADS
from ..utils import ConvUpsample
from .base_semantic_head import BaseSemanticHead
@HEADS.register_module()
class PanopticFPNHead(BaseSemanticHead):
""... | 6,675 | 41.794872 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/panoptic_fusion_heads/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .base_panoptic_fusion_head import \
BasePanopticFusionHead # noqa: F401,F403
from .heuristic_fusion_head import HeuristicFusionHead # noqa: F401,F403
from .maskformer_fusion_head import MaskFormerFusionHead # noqa: F401,F403
| 285 | 46.666667 | 75 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/panoptic_fusion_heads/base_panoptic_fusion_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from abc import ABCMeta, abstractmethod
from mmcv.runner import BaseModule
from ...builder import build_loss
class BasePanopticFusionHead(BaseModule, metaclass=ABCMeta):
"""Base class for panoptic heads."""
def __init__(self,
num_things_class... | 1,507 | 29.77551 | 75 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/panoptic_fusion_heads/heuristic_fusion_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core.evaluation.panoptic_utils import INSTANCE_OFFSET
from mmdet.models.builder import HEADS
from .base_panoptic_fusion_head import BasePanopticFusionHead
@HEADS.register_module()
class HeuristicFusionHead(BasePanopticFusionHead):
"""Fusion ... | 4,482 | 34.299213 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/seg_heads/panoptic_fusion_heads/maskformer_fusion_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn.functional as F
from mmdet.core.evaluation.panoptic_utils import INSTANCE_OFFSET
from mmdet.core.mask import mask2bbox
from mmdet.models.builder import HEADS
from .base_panoptic_fusion_head import BasePanopticFusionHead
@HEADS.register_modu... | 9,430 | 37.971074 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .brick_wrappers import AdaptiveAvgPool2d, adaptive_avg_pool2d
from .builder import build_linear_layer, build_transformer
from .ckpt_convert import pvt_convert
from .conv_upsample import ConvUpsample
from .csp_layer import CSPLayer
from .gaussian_target import gaussia... | 1,809 | 50.714286 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/utils/brick_wrappers.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn.bricks.wrappers import NewEmptyTensorOp, obsolete_torch_version
if torch.__version__ == 'parrots':
TORCH_VERSION = torch.__version__
else:
# torch.__version__ could be 1.3.1+cu92, we... | 1,856 | 34.711538 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/utils/builder.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.utils import Registry, build_from_cfg
TRANSFORMER = Registry('Transformer')
LINEAR_LAYERS = Registry('linear layers')
def build_transformer(cfg, default_args=None):
"""Builder for Transformer."""
return build_from_cfg(cfg, TRANSF... | 1,535 | 31 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/utils/ckpt_convert.py | # Copyright (c) OpenMMLab. All rights reserved.
# This script consists of several convert functions which
# can modify the weights of model in original repo to be
# pre-trained weights.
from collections import OrderedDict
import torch
def pvt_convert(ckpt):
new_ckpt = OrderedDict()
# Process the concat bet... | 4,964 | 34.978261 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/conv_upsample.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, ModuleList
class ConvUpsample(BaseModule):
"""ConvUpsample performs 2x upsampling after Conv.
There are several `ConvModule` layers. In the first few layers, ups... | 2,653 | 38.029412 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/utils/csp_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
from mmcv.runner import BaseModule
class DarknetBottleneck(BaseModule):
"""The basic bottleneck block used in Darknet.
Each ResBlock consists of two ConvModules and... | 5,079 | 32.642384 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/utils/gaussian_target.py | # Copyright (c) OpenMMLab. All rights reserved.
from math import sqrt
import torch
import torch.nn.functional as F
def gaussian2D(radius, sigma=1, dtype=torch.float32, device='cpu'):
"""Generate 2D gaussian kernel.
Args:
radius (int): Radius of gaussian kernel.
sigma (int): Sigma of gaussian... | 8,399 | 30.226766 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/inverted_residual.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import ConvModule
from mmcv.cnn.bricks import DropPath
from mmcv.runner import BaseModule
from .se_layer import SELayer
class InvertedResidual(BaseModule):
"""Inverted Residual Block.
Args... | 4,380 | 32.442748 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/utils/make_divisible.py | # Copyright (c) OpenMMLab. All rights reserved.
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 la... | 1,279 | 43.137931 | 116 | py |
mmdetection | mmdetection-master/mmdet/models/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
from torch.autograd import Function
from torch.nn import functional as F
class SigmoidGeometricMean(Function):
"""Forward and backward function of geometric mean of two sigmoid
functions.
This implementation with analytical gradient function substitutes
... | 2,606 | 34.712329 | 78 | py |
mmdetection | mmdetection-master/mmdet/models/utils/normed_predictor.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import CONV_LAYERS
from .builder import LINEAR_LAYERS
@LINEAR_LAYERS.register_module(name='NormedLinear')
class NormedLinear(nn.Linear):
"""Normalized Linear Layer.
Args:
... | 2,998 | 32.696629 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/utils/panoptic_gt_processing.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def preprocess_panoptic_gt(gt_labels, gt_masks, gt_semantic_seg, num_things,
num_stuff, img_metas):
"""Preprocess the ground truth for a image.
Args:
gt_labels (Tensor): Ground truth labels of each bbox,
... | 2,536 | 35.768116 | 76 | py |
mmdetection | mmdetection-master/mmdet/models/utils/point_sample.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.ops import point_sample
def get_uncertainty(mask_pred, labels):
"""Estimate uncertainty based on pred logits.
We estimate uncertainty as L1 distance between 0.0 and the logits
prediction in 'mask_pred' for the foreground class in `cla... | 3,878 | 43.079545 | 77 | py |
mmdetection | mmdetection-master/mmdet/models/utils/positional_encoding.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
import torch.nn as nn
from mmcv.cnn.bricks.transformer import POSITIONAL_ENCODING
from mmcv.runner import BaseModule
@POSITIONAL_ENCODING.register_module()
class SinePositionalEncoding(BaseModule):
"""Position encoding with sine and cosine ... | 6,568 | 39.054878 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/res_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import BaseModule, Sequential
from torch import nn as nn
class ResLayer(Sequential):
"""ResLayer to build ResNet style backbone.
Args:
block (nn.Module): block used to build ResLay... | 6,392 | 32.471204 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/se_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
class SELayer(BaseModule):
"""Squeeze-and-Excitation Module.
Args:
channels (int): The input (and output) channels of the SE layer.
... | 5,007 | 38.125 | 79 | py |
mmdetection | mmdetection-master/mmdet/models/utils/transformer.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import warnings
from typing import Sequence
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import (build_activation_layer, build_conv_layer,
build_norm_layer, xavier_init)
from mmcv.cnn.bricks.registry i... | 46,532 | 38.839897 | 132 | py |
mmdetection | mmdetection-master/mmdet/utils/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .ascend_util import (batch_images_to_levels,
get_max_num_gt_division_factor, masked_fill)
from .collect_env import collect_env
from .compat_config import compat_cfg
from .logger import get_caller_name, get_root_logger, log_img_scale
from .me... | 1,035 | 44.043478 | 78 | py |
mmdetection | mmdetection-master/mmdet/utils/ascend_util.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def masked_fill(ori_tensor, mask, new_value, neg=False):
"""The Value of ori_tensor is new_value, depending on mask.
Args:
ori_tensor (Tensor): Input tensor.
mask (Tensor): If select new_value.
new_value(Tensor | scalar): Va... | 2,359 | 32.714286 | 75 | py |
mmdetection | mmdetection-master/mmdet/utils/collect_env.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.utils import collect_env as collect_base_env
from mmcv.utils import get_git_hash
import mmdet
def collect_env():
"""Collect the information of the running environments."""
env_info = collect_base_env()
env_info['MMDetection'] = mmdet.__version__ +... | 471 | 25.222222 | 74 | py |
mmdetection | mmdetection-master/mmdet/utils/compat_config.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import warnings
from mmcv import ConfigDict
def compat_cfg(cfg):
"""This function would modify some filed to keep the compatibility of
config.
For example, it will move some args which will be deprecated to the correct
fields.
"""
c... | 5,966 | 41.621429 | 79 | py |
mmdetection | mmdetection-master/mmdet/utils/contextmanagers.py | # Copyright (c) OpenMMLab. All rights reserved.
import asyncio
import contextlib
import logging
import os
import time
from typing import List
import torch
logger = logging.getLogger(__name__)
DEBUG_COMPLETED_TIME = bool(os.environ.get('DEBUG_COMPLETED_TIME', False))
@contextlib.asynccontextmanager
async def comple... | 4,125 | 32.544715 | 79 | py |
mmdetection | mmdetection-master/mmdet/utils/logger.py | # Copyright (c) OpenMMLab. All rights reserved.
import inspect
import logging
from mmcv.utils import get_logger
def get_root_logger(log_file=None, log_level=logging.INFO):
"""Get root logger.
Args:
log_file (str, optional): File path of log. Defaults to None.
log_level (int, optional): The l... | 1,985 | 29.090909 | 77 | py |
mmdetection | mmdetection-master/mmdet/utils/memory.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
from collections import abc
from contextlib import contextmanager
from functools import wraps
import torch
from mmdet.utils import get_root_logger
def cast_tensor_type(inputs, src_type=None, dst_type=None):
"""Recursively convert Tensor in inputs f... | 8,088 | 36.799065 | 103 | py |
mmdetection | mmdetection-master/mmdet/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import glob
import os
import os.path as osp
import warnings
import mmcv
import torch
from mmcv.utils import TORCH_VERSION, digit_version, print_log
def find_latest_checkpoint(path, suffix='pth'):
"""Find the latest checkpoint from the working directory.
Args:
... | 2,818 | 30.322222 | 74 | py |
mmdetection | mmdetection-master/mmdet/utils/profiling.py | # Copyright (c) OpenMMLab. All rights reserved.
import contextlib
import sys
import time
import torch
if sys.version_info >= (3, 7):
@contextlib.contextmanager
def profile_time(trace_name,
name,
enabled=True,
stream=None,
end... | 1,336 | 31.609756 | 73 | py |
mmdetection | mmdetection-master/mmdet/utils/replace_cfg_vals.py | # Copyright (c) OpenMMLab. All rights reserved.
import re
from mmcv.utils import Config
def replace_cfg_vals(ori_cfg):
"""Replace the string "${key}" with the corresponding value.
Replace the "${key}" with the value of ori_cfg.key in the config. And
support replacing the chained ${key}. Such as, replace... | 2,915 | 40.070423 | 92 | py |
mmdetection | mmdetection-master/mmdet/utils/rfnext.py | # Copyright (c) OpenMMLab. All rights reserved.
try:
from mmcv.cnn import RFSearchHook
except ImportError:
RFSearchHook = None
def rfnext_init_model(detector, cfg):
"""Rcecptive field search via dilation rates.
Please refer to `RF-Next: Efficient Receptive Field
Search for Convolutional Neural Ne... | 1,486 | 32.795455 | 71 | py |
mmdetection | mmdetection-master/mmdet/utils/setup_env.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import platform
import warnings
import cv2
import torch.multiprocessing as mp
def setup_multi_processes(cfg):
"""Setup multi-processing environment variables."""
# set multi-process start method as `fork` to speed up the training
if platform.syste... | 2,428 | 43.981481 | 112 | py |
mmdetection | mmdetection-master/mmdet/utils/split_batch.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def split_batch(img, img_metas, kwargs):
"""Split data_batch by tags.
Code is modified from
<https://github.com/microsoft/SoftTeacher/blob/main/ssod/utils/structure_utils.py> # noqa: E501
Args:
img (Tensor): of shape (N, C, H, W) e... | 1,778 | 37.673913 | 99 | py |
mmdetection | mmdetection-master/mmdet/utils/util_distribution.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
dp_factory = {'cuda': MMDataParallel, 'cpu': MMDataParallel}
ddp_factory = {'cuda': MMDistributedDataParallel}
def build_dp(model, device='cuda', dim=0, *args, **kwargs):
"""build Dat... | 3,189 | 33.301075 | 78 | py |
mmdetection | mmdetection-master/mmdet/utils/util_mixins.py | # Copyright (c) OpenMMLab. All rights reserved.
"""This module defines the :class:`NiceRepr` mixin class, which defines a
``__repr__`` and ``__str__`` method that only depend on a custom ``__nice__``
method, which you must define. This means you only have to overload one
function instead of two. Furthermore, if the ob... | 3,712 | 34.028302 | 78 | py |
mmdetection | mmdetection-master/mmdet/utils/util_random.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Helpers for random number generators."""
import numpy as np
def ensure_rng(rng=None):
"""Coerces input into a random number generator.
If the input is None, then a global random state is returned.
If the input is a numeric value, then that is used as a ... | 1,025 | 28.314286 | 119 | py |
mmdetection | mmdetection-master/tests/data/configs_mmtrack/faster_rcnn_r50_dc5.py | model = dict(
detector=dict(
type='FasterRCNN',
backbone=dict(
type='ResNet',
depth=18,
base_channels=2,
num_stages=4,
out_indices=(3, ),
strides=(1, 2, 2, 1),
dilations=(1, 1, 1, 2),
frozen_stages=1,
... | 4,091 | 34.894737 | 76 | py |
mmdetection | mmdetection-master/tests/data/configs_mmtrack/faster_rcnn_r50_fpn.py | model = dict(
detector=dict(
type='FasterRCNN',
backbone=dict(
type='ResNet',
depth=18,
base_channels=2,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=True),
... | 4,013 | 35.490909 | 76 | py |
mmdetection | mmdetection-master/tests/data/configs_mmtrack/mot_challenge.py | # dataset settings
dataset_type = 'MOTChallengeDataset'
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
train_pipeline = [
dict(type='LoadMultiImagesFromFile', to_float32=True),
dict(type='SeqLoadAnnotations', with_bbox=True, with_track=True),
dict(
... | 2,465 | 31.88 | 77 | py |
mmdetection | mmdetection-master/tests/data/configs_mmtrack/selsa_faster_rcnn_r101_dc5_1x.py | _base_ = [
'./faster_rcnn_r50_dc5.py', './mot_challenge.py',
'../../../configs/_base_/default_runtime.py'
]
model = dict(
type='SELSA',
pretrains=None,
detector=dict(
backbone=dict(depth=18, base_channels=2),
roi_head=dict(
type='SelsaRoIHead',
bbox_head=dict(... | 1,351 | 26.591837 | 72 | py |
mmdetection | mmdetection-master/tests/data/configs_mmtrack/tracktor_faster-rcnn_r50_fpn_4e.py | _base_ = [
'./faster_rcnn_r50_fpn.py', './mot_challenge.py',
'../../../configs/_base_/default_runtime.py'
]
model = dict(
type='Tracktor',
pretrains=dict(
detector= # noqa: E251
'https://download.openmmlab.com/mmtracking/mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-half-64ee2ed4.pth', ... | 2,309 | 31.535211 | 129 | py |
mmdetection | mmdetection-master/tests/test_data/test_utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
from mmdet.datasets import get_loading_pipeline, replace_ImageToTensor
def test_replace_ImageToTensor():
# with MultiScaleFlipAug
pipelines = [
dict(type='LoadImageFromFile'),
dict(
type='MultiScaleFlipAug',
... | 2,721 | 32.604938 | 70 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_coco_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import mmcv
import pytest
from mmdet.datasets import CocoDataset
def _create_ids_error_coco_json(json_name):
image = {
'id': 0,
'width': 640,
'height': 640,
'file_name': 'fake_name.jpg',
}
... | 1,293 | 20.932203 | 76 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_coco_occluded.py | import os.path as osp
from tempfile import TemporaryDirectory
import mmcv
import numpy as np
from mmdet.datasets import OccludedSeparatedCocoDataset
def test_occluded_separated_coco_dataset():
ann = [[
'fake1.jpg', 'person', 8, [219.9, 176.12, 11.14, 34.23], {
'size': [480, 640],
... | 1,160 | 28.769231 | 71 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_common.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import logging
import os.path as osp
import tempfile
from unittest.mock import MagicMock, patch
import mmcv
import numpy as np
import pytest
import torch
import torch.nn as nn
from mmcv.runner import EpochBasedRunner
from torch.utils.data import DataLoader
f... | 12,160 | 31.867568 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_custom_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import unittest
from unittest.mock import MagicMock, patch
import pytest
from mmdet.datasets import DATASETS
@patch('mmdet.datasets.CocoDataset.load_annotations', MagicMock())
@patch('mmdet.datasets.CustomDataset.load_annotations', MagicMock())
@... | 4,777 | 33.374101 | 77 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_dataset_wrapper.py | # Copyright (c) OpenMMLab. All rights reserved.
import bisect
import math
from collections import defaultdict
from unittest.mock import MagicMock
import numpy as np
import pytest
from mmdet.datasets import (ClassBalancedDataset, ConcatDataset, CustomDataset,
MultiImageMixDataset, RepeatDat... | 8,276 | 38.414286 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_objects365.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import mmcv
import pytest
from mmdet.datasets import Objects365V1Dataset, Objects365V2Dataset
def _create_objects365_json(json_name):
images = [{
'file_name': 'fake1.jpg',
'height': 800,
'width': 800,
... | 3,690 | 22.660256 | 73 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_openimages_dataset.py | import csv
import os.path as osp
import tempfile
import mmcv
import numpy as np
import pytest
from mmdet.datasets import OpenImagesChallengeDataset, OpenImagesDataset
def _create_ids_error_oid_csv(
label_file,
fake_csv_file,
):
label_description = ['/m/000002', 'Football']
# `newline=''` is used to ... | 12,808 | 33.807065 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_panoptic_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import mmcv
import numpy as np
from mmdet.core import encode_mask_results
from mmdet.datasets.api_wrappers import pq_compute_single_core
from mmdet.datasets.coco_panoptic import INSTANCE_OFFSET, CocoPanopticDataset
try:
from pa... | 13,935 | 29.49453 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_datasets/test_xml_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
from mmdet.datasets import DATASETS
def test_xml_dataset():
dataconfig = {
'ann_file': 'data/VOCdevkit/VOC2007/ImageSets/Main/test.txt',
'img_prefix': 'data/VOCdevkit/VOC2007/',
'pipeline': [{
'type': 'LoadImageFrom... | 641 | 25.75 | 69 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_formatting.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
from mmcv.utils import build_from_cfg
from mmdet.datasets.builder import PIPELINES
def test_default_format_bundle():
results = dict(
img_prefix=osp.join(osp.dirname(__file__), '../../data'),
img_info=dict(filename='color.jpg')... | 786 | 30.48 | 65 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_loading.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
import mmcv
import numpy as np
import pytest
from mmdet.core.mask import BitmapMasks, PolygonMasks
from mmdet.datasets.pipelines import (FilterAnnotations, LoadImageFromFile,
LoadImageFromWebcam,
... | 5,336 | 39.12782 | 78 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core.bbox.assigners import MaxIoUAssigner
from mmdet.core.bbox.samplers import (OHEMSampler, RandomSampler,
ScoreHLRSampler)
def test_random_sampler():
assigner = MaxIoUAssigner(
pos_iou_thr=0.5,... | 9,735 | 28.50303 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import check_result_same, construct_toy_data, create_random_bboxes
__all__ = ['create_random_bboxes', 'construct_toy_data', 'check_result_same']
| 206 | 40.4 | 78 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_img_augment.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import mmcv
import numpy as np
from mmcv.utils import build_from_cfg
from numpy.testing import assert_array_equal
from mmdet.datasets.builder import PIPELINES
from .utils import construct_toy_data
def test_adjust_color():
results = construct_toy_data()... | 6,904 | 38.232955 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_models_aug_test.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import mmcv
import torch
from mmcv.parallel import collate
from mmcv.utils import build_from_cfg
from mmdet.datasets.builder import PIPELINES
from mmdet.models import build_detector
def model_aug_test_template(cfg_file):
# get config
cfg ... | 4,314 | 31.689394 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_rotate.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import numpy as np
import pytest
from mmcv.utils import build_from_cfg
from mmdet.core.mask import BitmapMasks, PolygonMasks
from mmdet.datasets.builder import PIPELINES
from .utils import check_result_same, construct_toy_data
def test_rotate():
# test... | 6,600 | 37.156069 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_shear.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import numpy as np
import pytest
from mmcv.utils import build_from_cfg
from mmdet.core.mask import BitmapMasks, PolygonMasks
from mmdet.datasets.builder import PIPELINES
from .utils import check_result_same, construct_toy_data
def test_shear():
# test ... | 6,481 | 38.284848 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_transform.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
import mmcv
import numpy as np
import pytest
import torch
from mmcv.utils import build_from_cfg
from mmdet.core.evaluation.bbox_overlaps import bbox_overlaps
from mmdet.datasets.builder import PIPELINES
from .utils import create_full_ma... | 42,738 | 37.193923 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/test_translate.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import numpy as np
import pycocotools.mask as maskUtils
import pytest
from mmcv.utils import build_from_cfg
from mmdet.core.mask import BitmapMasks, PolygonMasks
from mmdet.datasets.builder import PIPELINES
def _check_keys(results, results_translated):
... | 19,985 | 37.65764 | 79 | py |
mmdetection | mmdetection-master/tests/test_data/test_pipelines/test_transform/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
from mmdet.core.mask import BitmapMasks, PolygonMasks
def _check_fields(results, pipeline_results, keys):
"""Check data in fields from two results are same."""
for key in keys:
if isinstance(results[key], (BitmapMasks, PolygonMasks)):... | 3,469 | 37.988764 | 78 | py |
mmdetection | mmdetection-master/tests/test_downstream/test_mmtrack.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
from collections import defaultdict
import numpy as np
import pytest
import torch
from mmcv import Config
@pytest.mark.parametrize(
'cfg_file',
['./tests/data/configs_mmtrack/selsa_faster_rcnn_r101_dc5_1x.py'])
def test_vid_fgfa_style_forward(cfg_fi... | 7,592 | 31.87013 | 77 | py |
mmdetection | mmdetection-master/tests/test_metrics/test_box_overlap.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from mmdet.core import BboxOverlaps2D, bbox_overlaps
from mmdet.core.evaluation.bbox_overlaps import \
bbox_overlaps as recall_overlaps
def test_bbox_overlaps_2d(eps=1e-7):
def _construct_bbox(num_bbox=None):
... | 5,316 | 38.385185 | 79 | py |
mmdetection | mmdetection-master/tests/test_metrics/test_losses.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models import Accuracy, build_loss
def test_ce_loss():
# use_mask and use_sigmoid cannot be true at the same time
with pytest.raises(AssertionError):
loss_cfg = dict(
type='CrossEntropyLoss',
... | 8,694 | 34.929752 | 78 | py |
mmdetection | mmdetection-master/tests/test_metrics/test_mean_ap.py | import numpy as np
from mmdet.core.evaluation.mean_ap import (eval_map, tpfp_default,
tpfp_imagenet, tpfp_openimages)
det_bboxes = np.array([
[0, 0, 10, 10],
[10, 10, 20, 20],
[32, 32, 38, 42],
])
gt_bboxes = np.array([[0, 0, 10, 20], [0, 10, 10, 19], [10, 10, 20... | 5,477 | 28.138298 | 79 | py |
mmdetection | mmdetection-master/tests/test_metrics/test_recall.py | import numpy as np
from mmdet.core.evaluation.recall import eval_recalls
det_bboxes = np.array([
[0, 0, 10, 10],
[10, 10, 20, 20],
[32, 32, 38, 42],
])
gt_bboxes = np.array([[0, 0, 10, 20], [0, 10, 10, 19], [10, 10, 20, 20]])
gt_ignore = np.array([[5, 5, 10, 20], [6, 10, 10, 19]])
def test_eval_recalls(... | 1,377 | 28.319149 | 73 | py |
mmdetection | mmdetection-master/tests/test_models/test_forward.py | # Copyright (c) OpenMMLab. All rights reserved.
"""pytest tests/test_forward.py."""
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _get_config_directory():
"""Find the predefined detector config directory."""
try:
# Assume we are running in the... | 31,150 | 32.280983 | 110 | py |
mmdetection | mmdetection-master/tests/test_models/test_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.utils import digit_version
from mmdet.models.losses import (BalancedL1Loss, CrossEntropyLoss, DiceLoss,
DistributionFocalLoss, FocalLoss,
GaussianFocalLoss,
... | 8,705 | 36.364807 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_loss_compatibility.py | # Copyright (c) OpenMMLab. All rights reserved.
"""pytest tests/test_loss_compatibility.py."""
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _get_config_directory():
"""Find the predefined detector config directory."""
try:
# Assume we are run... | 6,361 | 30.49505 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_necks.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.necks import (FPG, FPN, FPN_CARAFE, NASFCOS_FPN, NASFPN,
YOLOXPAFPN, ChannelMapper, CTResNetNeck,
DilatedEncoder... | 20,961 | 30.10089 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_plugins.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv import ConfigDict
from mmcv.cnn import build_plugin_layer
from mmdet.models.plugins import DropBlock
def test_dropblock():
feat = torch.rand(1, 1, 11, 11)
drop_prob = 1.0
dropblock = DropBlock(drop_prob, block_size=11, w... | 6,057 | 35.059524 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import check_norm_state, is_block, is_norm
__all__ = ['is_block', 'is_norm', 'check_norm_state']
| 158 | 30.8 | 54 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_csp_darknet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.backbones.csp_darknet import CSPDarknet
from .utils import check_norm_state, is_norm
def test_csp_darknet_backbone():
with pytest.raises(ValueError):
# frozen_sta... | 4,117 | 34.196581 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_detectors_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
from mmdet.models.backbones import DetectoRS_ResNet
def test_detectorrs_resnet_backbone():
detectorrs_cfg = dict(
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requi... | 1,611 | 32.583333 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_efficientnet.py | import pytest
import torch
from mmdet.models.backbones import EfficientNet
def test_efficientnet_backbone():
"""Test EfficientNet backbone."""
with pytest.raises(AssertionError):
# EfficientNet arch should be a key in EfficientNet.arch_settings
EfficientNet(arch='c3')
model = EfficientNe... | 859 | 32.076923 | 73 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_hourglass.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones.hourglass import HourglassNet
def test_hourglass_backbone():
with pytest.raises(AssertionError):
# HourglassNet's num_stacks should larger than 0
HourglassNet(num_stacks=0)
with pytest.rais... | 1,464 | 28.3 | 65 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_hrnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones.hrnet import HRModule, HRNet
from mmdet.models.backbones.resnet import BasicBlock, Bottleneck
@pytest.mark.parametrize('block', [BasicBlock, Bottleneck])
def test_hrmodule(block):
# Test multiscale forward
... | 3,089 | 26.589286 | 68 | py |