repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
s2anet | s2anet-master/mmdet/core/bbox/coder/delta_xywha_bbox_coder.py | import torch
from .base_bbox_coder import BaseBBoxCoder
from ..builder import BBOX_CODERS
from ..transforms_rotated import delta2bbox_rotated, bbox2delta_rotated
@BBOX_CODERS.register_module
class DeltaXYWHABBoxCoder(BaseBBoxCoder):
"""Delta XYWHA BBox coder.
Following the practice in `R-CNN <https://arxiv.... | 2,720 | 35.28 | 87 | py |
s2anet | s2anet-master/mmdet/core/bbox/coder/delta_xywh_bbox_coder.py | import numpy as np
import torch
from .base_bbox_coder import BaseBBoxCoder
from ..builder import BBOX_CODERS
@BBOX_CODERS.register_module
class DeltaXYWHBBoxCoder(BaseBBoxCoder):
"""Delta XYWH BBox coder used in MMDet V1.x.
Following the practice in R-CNN [1]_, this coder encodes bbox (x1, y1, x2,
y2) i... | 7,763 | 36.507246 | 79 | py |
s2anet | s2anet-master/mmdet/core/bbox/iou_calculators/iou2d_calculator.py | import torch
from .builder import IOU_CALCULATORS
@IOU_CALCULATORS.register_module
class BboxOverlaps2D(object):
"""2D Overlaps (e.g. IoUs, GIoUs) Calculator."""
def __call__(self, bboxes1, bboxes2, mode='iou', is_aligned=False):
"""Calculate IoU between 2D bboxes.
Args:
bboxes1... | 6,267 | 37.453988 | 78 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/instance_balanced_pos_sampler.py | import numpy as np
import torch
from .random_sampler import RandomSampler
class InstanceBalancedPosSampler(RandomSampler):
def _sample_pos(self, assign_result, num_expected, **kwargs):
pos_inds = torch.nonzero(assign_result.gt_inds > 0)
if pos_inds.numel() != 0:
pos_inds = pos_inds.s... | 1,765 | 41.047619 | 77 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/base_sampler.py | from abc import ABCMeta, abstractmethod
import torch
from .sampling_result import SamplingResult
class BaseSampler(metaclass=ABCMeta):
def __init__(self,
num,
pos_fraction,
neg_pos_ub=-1,
add_gt_as_proposals=True,
**kwargs):
... | 2,942 | 33.22093 | 78 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/random_sampler.py | import numpy as np
import torch
from ..builder import BBOX_SAMPLERS
from .base_sampler import BaseSampler
@BBOX_SAMPLERS.register_module
class RandomSampler(BaseSampler):
def __init__(self,
num,
pos_fraction,
neg_pos_ub=-1,
add_gt_as_proposals=T... | 1,924 | 34 | 77 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/ohem_sampler.py | import torch
from ..transforms import bbox2roi
from .base_sampler import BaseSampler
class OHEMSampler(BaseSampler):
"""
Online Hard Example Mining Sampler described in [1]_.
References:
.. [1] https://arxiv.org/pdf/1604.03540.pdf
"""
def __init__(self,
num,
... | 2,912 | 35.4125 | 77 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/iou_balanced_neg_sampler.py | import numpy as np
import torch
from .random_sampler import RandomSampler
class IoUBalancedNegSampler(RandomSampler):
"""IoU Balanced Sampling
arXiv: https://arxiv.org/pdf/1904.02701.pdf (CVPR 2019)
Sampling proposals according to their IoU. `floor_fraction` of needed RoIs
are sampled from proposal... | 5,869 | 42.80597 | 79 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/random_sampler_rotated.py | import torch
from .random_sampler import RandomSampler
from .sampling_result import SamplingResult
from ..builder import BBOX_SAMPLERS
@BBOX_SAMPLERS.register_module
class RandomSamplerRotated(RandomSampler):
def sample(self,
assign_result,
bboxes,
gt_bboxes,
... | 1,997 | 35.327273 | 84 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/sampling_result.py | import torch
class SamplingResult(object):
def __init__(self, pos_inds, neg_inds, bboxes, gt_bboxes, assign_result,
gt_flags):
self.pos_inds = pos_inds
self.neg_inds = neg_inds
self.pos_bboxes = bboxes[pos_inds]
self.neg_bboxes = bboxes[neg_inds]
self.pos_... | 790 | 30.64 | 76 | py |
s2anet | s2anet-master/mmdet/core/bbox/samplers/pseudo_sampler.py | import torch
from .base_sampler import BaseSampler
from .sampling_result import SamplingResult
class PseudoSampler(BaseSampler):
def __init__(self, **kwargs):
pass
def _sample_pos(self, **kwargs):
raise NotImplementedError
def _sample_neg(self, **kwargs):
raise NotImplementedEr... | 829 | 29.740741 | 79 | py |
s2anet | s2anet-master/mmdet/core/utils/dist_utils.py | from collections import OrderedDict
import torch.distributed as dist
from mmcv.runner import OptimizerHook
from torch._utils import (_flatten_dense_tensors, _take_tensors,
_unflatten_dense_tensors)
def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1):
if bucket_size_mb > 0:
... | 1,967 | 32.355932 | 73 | py |
s2anet | s2anet-master/mmdet/core/anchor/anchor_target.py | import torch
from ..bbox import PseudoSampler, assign_and_sample, build_assigner, build_bbox_coder
from ..utils import multi_apply
def anchor_target(anchor_list,
valid_flag_list,
gt_bboxes_list,
img_metas,
target_means,
target_... | 7,680 | 37.989848 | 90 | py |
s2anet | s2anet-master/mmdet/core/anchor/guided_anchor_target.py | import torch
from ..bbox import PseudoSampler, build_assigner, build_sampler
from ..utils import multi_apply, unmap
def calc_region(bbox, ratio, featmap_size=None):
"""Calculate a proportional bbox region.
The bbox center are fixed and the new h' and w' is h * ratio and w * ratio.
Args:
bbox (T... | 11,809 | 40.006944 | 79 | py |
s2anet | s2anet-master/mmdet/core/anchor/point_generator.py | import torch
class PointGenerator(object):
def _meshgrid(self, x, y, row_major=True):
xx = x.repeat(len(y))
yy = y.view(-1, 1).repeat(1, len(x)).view(-1)
if row_major:
return xx, yy
else:
return yy, xx
def grid_points(self, featmap_size, stride=16, dev... | 1,287 | 35.8 | 71 | py |
s2anet | s2anet-master/mmdet/core/anchor/anchor_generator.py | import torch
class AnchorGenerator(object):
"""
Examples:
>>> from mmdet.core import AnchorGenerator
>>> self = AnchorGenerator(9, [1.], [1.])
>>> all_anchors = self.grid_anchors((2, 2), device='cpu')
>>> print(all_anchors)
tensor([[ 0., 0., 8., 8.],
... | 3,603 | 35.40404 | 78 | py |
s2anet | s2anet-master/mmdet/core/anchor/point_target.py | import torch
from ..bbox import PseudoSampler, assign_and_sample, build_assigner
from ..utils import multi_apply
def point_target(proposals_list,
valid_flag_list,
gt_bboxes_list,
img_metas,
cfg,
gt_bboxes_ignore_list=None,
... | 6,441 | 37.807229 | 79 | py |
s2anet | s2anet-master/mmdet/core/anchor/anchor_generator_rotated.py | import torch
class AnchorGeneratorRotated(object):
def __init__(self, base_size, scales, ratios, angles=[0,],scale_major=True, ctr=None):
self.base_size = base_size
self.scales = torch.Tensor(scales)
self.ratios = torch.Tensor(ratios)
self.angles = torch.Tensor(angles)
self... | 3,472 | 38.022472 | 91 | py |
s2anet | s2anet-master/mmdet/models/builder.py | from torch import nn
from mmdet.utils import build_from_cfg
from .registry import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,
ROI_EXTRACTORS, SHARED_HEADS)
def build(cfg, registry, default_args=None):
if isinstance(cfg, list):
modules = [
build_from_cfg(cfg_, registry,... | 959 | 20.818182 | 78 | py |
s2anet | s2anet-master/mmdet/models/detectors/two_stage.py | import torch
import torch.nn as nn
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .base import BaseDetector
from .test_mixins import BBoxTestMixin, MaskTestMixin, RPNTestMixin
@DETECTORS.register_module
class TwoStageDetector(B... | 12,245 | 38.25 | 79 | py |
s2anet | s2anet-master/mmdet/models/detectors/base.py | import logging
from abc import ABCMeta, abstractmethod
import mmcv
import numpy as np
import pycocotools.mask as maskUtils
import torch.nn as nn
from mmdet.core import auto_fp16, get_classes, tensor2imgs
class BaseDetector(nn.Module):
"""Base class for detectors"""
__metaclass__ = ABCMeta
def __init__... | 5,120 | 32.690789 | 77 | py |
s2anet | s2anet-master/mmdet/models/detectors/single_stage.py | import torch.nn as nn
from mmdet.core import bbox2result
from .. import builder
from ..registry import DETECTORS
from .base import BaseDetector
@DETECTORS.register_module
class SingleStageDetector(BaseDetector):
"""Base class for single-stage detectors.
Single-stage detectors directly and densely predict bo... | 2,822 | 31.448276 | 78 | py |
s2anet | s2anet-master/mmdet/models/detectors/reppoints_detector.py | import torch
from mmdet.core import bbox2result, bbox_mapping_back, multiclass_nms
from ..registry import DETECTORS
from .single_stage import SingleStageDetector
@DETECTORS.register_module
class RepPointsDetector(SingleStageDetector):
"""RepPoints: Point Set Representation for Object Detection.
This det... | 3,089 | 36.682927 | 79 | py |
s2anet | s2anet-master/mmdet/models/detectors/cascade_rcnn.py | from __future__ import division
import torch
import torch.nn as nn
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multiclass_nms)
from .. import builder
from ..registry import DETECTORS
from... | 23,674 | 41.276786 | 79 | py |
s2anet | s2anet-master/mmdet/models/detectors/faster_rcnn_hbb_obb.py | import torch
from mmdet.core import (bbox2result_rotated, rotated_box_to_roi, build_assigner, build_sampler, bbox_to_rotated_box,
bbox_mapping, multiclass_nms_rotated, merge_aug_bboxes_rotated, rotated_box_to_bbox,
bbox2roi)
from .two_stage import TwoStageDetector
from .... | 13,152 | 40.755556 | 116 | py |
s2anet | s2anet-master/mmdet/models/detectors/grid_rcnn.py | import torch
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class GridRCNN(TwoStageDetector):
"""Grid R-CNN.
This detector is the implementation of:
- G... | 9,225 | 39.113043 | 79 | py |
s2anet | s2anet-master/mmdet/models/detectors/double_head_rcnn.py | import torch
from mmdet.core import bbox2roi, build_assigner, build_sampler
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class DoubleHeadRCNN(TwoStageDetector):
def __init__(self, reg_roi_scale_factor, **kwargs):
super().__init__(**kwargs)
s... | 7,453 | 40.642458 | 77 | py |
s2anet | s2anet-master/mmdet/models/detectors/cascade_s2anet.py | import torch.nn as nn
from mmdet.core import bbox2result
from .base import BaseDetector
from .. import builder
from ..registry import DETECTORS
@DETECTORS.register_module
class CascadeS2ANetDetector(BaseDetector):
"""Base class for single-stage detectors.
Single-stage detectors directly and densely predict ... | 4,822 | 35.263158 | 120 | py |
s2anet | s2anet-master/mmdet/models/detectors/htc.py | import torch
import torch.nn.functional as F
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multiclass_nms)
from .. import builder
from ..registry import DETECTORS
from .cascade_rcnn import C... | 24,580 | 43.210432 | 79 | py |
s2anet | s2anet-master/mmdet/models/detectors/mask_scoring_rcnn.py | import torch
from mmdet.core import bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class MaskScoringRCNN(TwoStageDetector):
"""Mask Scoring RCNN.
https://arxiv.org/abs/1903.00241
"""
... | 8,565 | 41.616915 | 79 | py |
s2anet | s2anet-master/mmdet/models/plugins/non_local.py | import torch
import torch.nn as nn
from mmcv.cnn import constant_init, normal_init
from ..utils import ConvModule
class NonLocal2D(nn.Module):
"""Non-local module.
See https://arxiv.org/abs/1711.07971 for details.
Args:
in_channels (int): Channels of the input feature map.
reduction (in... | 3,708 | 31.252174 | 79 | py |
s2anet | s2anet-master/mmdet/models/plugins/generalized_attention.py | import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import kaiming_init
class GeneralizedAttention(nn.Module):
"""GeneralizedAttention module.
See 'An Empirical Study of Spatial Attention Mechanisms in Deep Networks'
(https://arxiv.org/abs/1711... | 15,139 | 38.324675 | 79 | py |
s2anet | s2anet-master/mmdet/models/necks/fpn.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmdet.core import auto_fp16
from ..registry import NECKS
from ..utils import ConvModule
@NECKS.register_module
class FPN(nn.Module):
def __init__(self,
in_channels,
out_channels,
... | 5,289 | 36.253521 | 79 | py |
s2anet | s2anet-master/mmdet/models/necks/bfp.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from ..plugins import NonLocal2D
from ..registry import NECKS
from ..utils import ConvModule
@NECKS.register_module
class BFP(nn.Module):
"""BFP (Balanced Feature Pyrmamids)
BFP takes multi-level features as inputs and ga... | 3,598 | 33.941748 | 79 | py |
s2anet | s2anet-master/mmdet/models/necks/hrfpn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn.weight_init import caffe2_xavier_init
from torch.utils.checkpoint import checkpoint
from ..registry import NECKS
from ..utils import ConvModule
@NECKS.register_module
class HRFPN(nn.Module):
"""HRFPN (High Resolution Feature Pyrmami... | 3,363 | 32.306931 | 79 | py |
s2anet | s2anet-master/mmdet/models/roi_extractors/single_level.py | from __future__ import division
import torch
import torch.nn as nn
from mmdet import ops
from mmdet.core import force_fp32
from ..registry import ROI_EXTRACTORS
@ROI_EXTRACTORS.register_module
class SingleRoIExtractor(nn.Module):
"""Extract RoI features from a single level feature map.
If there are mulitpl... | 3,794 | 34.138889 | 79 | py |
s2anet | s2anet-master/mmdet/models/roi_extractors/single_level_rotated.py | from __future__ import division
import torch
from .single_level import SingleRoIExtractor
from ..registry import ROI_EXTRACTORS
@ROI_EXTRACTORS.register_module
class SingleRoIExtractorRotated(SingleRoIExtractor):
def map_roi_levels(self, rois, num_levels):
"""Map rois to corresponding feature levels by... | 1,348 | 31.119048 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/reppoints_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (PointGenerator, multi_apply, multiclass_nms,
point_target)
from mmdet.ops import DeformConv
from ..builder import build_loss
from ..registry import HEA... | 27,172 | 44.515913 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/fsaf_head.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import multi_apply, multiclass_nms, distance2bbox
from ..losses import sigmoid_focal_loss
from ..registry import HEADS
from ..utils import bias_init_with_prob, ConvModule
def select_iou_loss(pred, target, weight, a... | 23,125 | 42.226168 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/rpn_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import normal_init
from mmdet.core import delta2bbox
from mmdet.ops import nms
from ..registry import HEADS
from .anchor_head import AnchorHead
@HEADS.register_module
class RPNHead(AnchorHead):
def __init__(self, in_channels, **kwa... | 4,050 | 37.580952 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/anchor_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGenerator, anchor_target, delta2bbox, force_fp32,
multi_apply, multiclass_nms)
from ..builder import build_loss
from ..registry import HEADS
@H... | 13,818 | 41.259939 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/retina_head.py | import numpy as np
import torch.nn as nn
from mmcv.cnn import normal_init
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .anchor_head import AnchorHead
@HEADS.register_module
class RetinaHead(AnchorHead):
"""
An anchor-based head used in [1]_.
The head contains two... | 3,602 | 33.644231 | 76 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/ga_rpn_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import normal_init
from mmdet.core import delta2bbox
from mmdet.ops import nms
from ..registry import HEADS
from .guided_anchor_head import GuidedAnchorHead
@HEADS.register_module
class GARPNHead(GuidedAnchorHead):
"""Guided-Anchor-... | 4,981 | 37.921875 | 78 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/ga_retina_head.py | import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.ops import MaskedConv2d
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .guided_anchor_head import FeatureAdaption, GuidedAnchorHead
@HEADS.register_module
class GARetinaHead(GuidedAnchorHead):
"""Guided-Ancho... | 3,760 | 33.824074 | 78 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/ssd_head.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmdet.core import AnchorGenerator, anchor_target, multi_apply
from ..losses import smooth_l1_loss
from ..registry import HEADS
from .anchor_head import AnchorHead
# TODO: add loss evaluator for... | 7,762 | 38.607143 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/fcos_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import distance2bbox, force_fp32, multi_apply, multiclass_nms
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule, Scale, bias_init_with_prob
INF = 1e8
@HEADS.register_module
class FCOSHead(n... | 16,503 | 39.952854 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/guided_anchor_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGenerator, anchor_inside_flags, anchor_target,
delta2bbox, force_fp32, ga_loc_target, ga_shape_target,
multi_apply, multi... | 25,226 | 39.820388 | 79 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads/fovea_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import multi_apply, multiclass_nms
from mmdet.ops import DeformConv
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
INF = 1e8
class FeatureAlign(nn.Module):
def ... | 16,360 | 41.167526 | 79 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads/bbox_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from mmdet.core import (auto_fp16, bbox_target, delta2bbox, force_fp32,
multiclass_nms)
from ..builder import build_loss
from ..losses import accuracy
from ..registry import HEADS
@HEAD... | 9,111 | 36.966667 | 79 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads/convfc_bbox_head.py | import torch.nn as nn
from ..registry import HEADS
from ..utils import ConvModule
from .bbox_head import BBoxHead
@HEADS.register_module
class ConvFCBBoxHead(BBoxHead):
r"""More general bbox head, with shared conv and fc layers and two optional
separated branches.
/-> cls con... | 6,943 | 36.333333 | 79 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads/double_bbox_head.py | import torch.nn as nn
from mmcv.cnn.weight_init import normal_init, xavier_init
from ..backbones.resnet import Bottleneck
from ..registry import HEADS
from ..utils import ConvModule
from .bbox_head import BBoxHead
class BasicResBlock(nn.Module):
"""Basic residual block.
This block is a little different from... | 5,274 | 29.847953 | 78 | py |
s2anet | s2anet-master/mmdet/models/shared_heads/res_layer.py | import logging
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from mmdet.core import auto_fp16
from ..backbones import ResNet, make_res_layer
from ..registry import SHARED_HEADS
@SHARED_HEADS.register_module
class ResLayer(nn.Module):
def __init__... | 2,236 | 29.643836 | 74 | py |
s2anet | s2anet-master/mmdet/models/utils/weight_init.py | import numpy as np
import torch.nn as nn
def xavier_init(module, gain=1, bias=0, distribution='normal'):
assert distribution in ['uniform', 'normal']
if distribution == 'uniform':
nn.init.xavier_uniform_(module.weight, gain=gain)
else:
nn.init.xavier_normal_(module.weight, gain=gain)
i... | 1,455 | 29.978723 | 71 | py |
s2anet | s2anet-master/mmdet/models/utils/norm.py | import torch.nn as nn
norm_cfg = {
# format: layer_type: (abbreviation, module)
'BN': ('bn', nn.BatchNorm2d),
'SyncBN': ('bn', nn.SyncBatchNorm),
'GN': ('gn', nn.GroupNorm),
# and potentially 'SN'
}
def build_norm_layer(cfg, num_features, postfix=''):
""" Build normalization layer
Args:
... | 1,684 | 29.089286 | 74 | py |
s2anet | s2anet-master/mmdet/models/utils/scale.py | import torch
import torch.nn as nn
class Scale(nn.Module):
"""
A learnable scale parameter
"""
def __init__(self, scale=1.0):
super(Scale, self).__init__()
self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float))
def forward(self, x):
return x * self.scale
| 314 | 18.6875 | 73 | py |
s2anet | s2anet-master/mmdet/models/utils/conv_ws.py | import torch.nn as nn
import torch.nn.functional as F
def conv_ws_2d(input,
weight,
bias=None,
stride=1,
padding=0,
dilation=1,
groups=1,
eps=1e-5):
c_in = weight.size(0)
weight_flat = weight.view(c_in, -1... | 1,335 | 27.425532 | 79 | py |
s2anet | s2anet-master/mmdet/models/utils/conv_module.py | import warnings
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from .conv_ws import ConvWS2d
from .norm import build_norm_layer
conv_cfg = {
'Conv': nn.Conv2d,
'ConvWS': ConvWS2d,
# TODO: octave conv
}
def build_conv_layer(cfg, *args, **kwargs):
""" Build convolution layer
... | 5,745 | 33.824242 | 78 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads_rotated/cascade_s2anet_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGeneratorRotated, anchor_target,
build_bbox_coder, delta2bbox_rotated, force_fp32,
images_to_levels, multi_apply, multicla... | 19,133 | 37.811359 | 93 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads_rotated/s2anet_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGeneratorRotated, anchor_target,
build_bbox_coder, delta2bbox_rotated, force_fp32,
images_to_levels, multi_apply, multicla... | 27,099 | 38.911635 | 88 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads_rotated/anchor_head_rotated.py | from __future__ import division
import torch
import torch.nn as nn
from mmdet.core import (AnchorGeneratorRotated, anchor_target,
delta2bbox_rotated, force_fp32, multi_apply,
multiclass_nms_rotated, images_to_levels, build_bbox_coder)
from ..anchor_heads import AnchorHe... | 7,452 | 40.636872 | 95 | py |
s2anet | s2anet-master/mmdet/models/anchor_heads_rotated/retina_head_rotated.py | import numpy as np
import torch.nn as nn
from mmcv.cnn import normal_init
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .anchor_head_rotated import AnchorHeadRotated
@HEADS.register_module
class RetinaHeadRotated(AnchorHeadRotated):
def __init__(self,
num... | 3,012 | 34.034884 | 105 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads_rotated/bbox_head_rotated.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from mmdet.core import (auto_fp16, bbox_target_rotated, delta2bbox_rotated, force_fp32,
multiclass_nms_rotated, bbox_to_rotated_box, rotated_box_to_poly, poly_to_rotated_box)
from ..build... | 9,476 | 38 | 110 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads_rotated/convfc_bbox_head_rotated.py | import torch.nn as nn
from .bbox_head_rotated import BBoxHeadRotated
from ..registry import HEADS
from ..utils import ConvModule
@HEADS.register_module
class ConvFCBBoxHeadRotated(BBoxHeadRotated):
r"""More general bbox head, with shared conv and fc layers and two optional
separated branches.
... | 7,037 | 36.83871 | 79 | py |
s2anet | s2anet-master/mmdet/models/bbox_heads_rotated/double_bbox_head_rotated.py | import torch.nn as nn
from mmcv.cnn.weight_init import normal_init, xavier_init
from .bbox_head_rotated import BBoxHeadRotated
from ..backbones.resnet import Bottleneck
from ..registry import HEADS
from ..utils import ConvModule
class BasicResBlock(nn.Module):
"""Basic residual block.
This block is a little... | 5,310 | 30.05848 | 78 | py |
s2anet | s2anet-master/mmdet/models/losses/ghm_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
def _expand_binary_labels(labels, label_weights, label_channels):
bin_labels = labels.new_full((labels.size(0), label_channels), 0)
inds = torch.nonzero(labels >= 1).squeeze()
if inds.numel() > 0:
bin... | 6,304 | 35.656977 | 79 | py |
s2anet | s2anet-master/mmdet/models/losses/mse_loss.py | import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
from .utils import weighted_loss
mse_loss = weighted_loss(F.mse_loss)
@LOSSES.register_module
class MSELoss(nn.Module):
def __init__(self, reduction='mean', loss_weight=1.0):
super().__init__()
self.reduction = ... | 632 | 23.346154 | 66 | py |
s2anet | s2anet-master/mmdet/models/losses/balanced_l1_loss.py | import numpy as np
import torch
import torch.nn as nn
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def balanced_l1_loss(pred,
target,
beta=1.0,
alpha=0.5,
gamma=1.5,
reduction='me... | 1,884 | 25.928571 | 73 | py |
s2anet | s2anet-master/mmdet/models/losses/iou_loss.py | import torch
import torch.nn as nn
from mmdet.core import bbox_overlaps
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def iou_loss(pred, target, eps=1e-6):
"""IoU loss.
Computing the IoU loss between a set of predicted bboxes and target bboxes.
The loss is calculated as n... | 6,650 | 30.671429 | 89 | py |
s2anet | s2anet-master/mmdet/models/losses/smooth_l1_loss.py | import torch
import torch.nn as nn
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def smooth_l1_loss(pred, target, beta=1.0):
assert beta > 0
assert pred.size() == target.size() and target.numel() > 0
diff = torch.abs(pred - target)
loss = torch.where(diff < beta, 0.5 *... | 1,288 | 27.021739 | 73 | py |
s2anet | s2anet-master/mmdet/models/losses/utils.py | import functools
import torch.nn.functional as F
def reduce_loss(loss, reduction):
"""Reduce loss as specified.
Args:
loss (Tensor): Elementwise loss tensor.
reduction (str): Options are "none", "mean" and "sum".
Return:
Tensor: Reduced loss tensor.
"""
reduction_enum = ... | 3,003 | 29.343434 | 79 | py |
s2anet | s2anet-master/mmdet/models/losses/accuracy.py | import torch.nn as nn
def accuracy(pred, target, topk=1):
assert isinstance(topk, (int, tuple))
if isinstance(topk, int):
topk = (topk, )
return_single = True
else:
return_single = False
maxk = max(topk)
_, pred_label = pred.topk(maxk, dim=1)
pred_label = pred_label.t(... | 801 | 24.0625 | 69 | py |
s2anet | s2anet-master/mmdet/models/losses/focal_loss.py | import torch.nn as nn
import torch.nn.functional as F
from mmdet.ops import sigmoid_focal_loss as _sigmoid_focal_loss
from ..registry import LOSSES
from .utils import weight_reduce_loss
# This method is only for debugging
def py_sigmoid_focal_loss(pred,
target,
wei... | 2,783 | 32.95122 | 76 | py |
s2anet | s2anet-master/mmdet/models/losses/rotated_iou_loss.py | import torch
import torch.nn as nn
from mmdet.ops import box_iou_rotated_differentiable
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def iou_loss(pred, target, linear=False, eps=1e-6):
"""IoU loss.
Computing the IoU loss between a set of predicted bboxes and target bboxes.
... | 2,397 | 30.552632 | 82 | py |
s2anet | s2anet-master/mmdet/models/losses/cross_entropy_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
from .utils import weight_reduce_loss
def cross_entropy(pred, label, weight=None, reduction='mean', avg_factor=None):
# element-wise losses
loss = F.cross_entropy(pred, label, reduction='none')
# apply weigh... | 3,386 | 31.567308 | 79 | py |
s2anet | s2anet-master/mmdet/models/backbones/hrnet.py | import logging
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import BasicBlock, Bottleneck
class HRM... | 19,868 | 36.773764 | 79 | py |
s2anet | s2anet-master/mmdet/models/backbones/resnet.py | import logging
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.plugins import GeneralizedAttention
from mmdet.ops import ContextBlock, DeformConv, Modu... | 18,098 | 32.331492 | 79 | py |
s2anet | s2anet-master/mmdet/models/backbones/ssd_vgg.py | import logging
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import VGG, constant_init, kaiming_init, normal_init, xavier_init
from mmcv.runner import load_checkpoint
from ..registry import BACKBONES
@BACKBONES.register_module
class SSDVGG(VGG):
"""VGG Backbone network for sin... | 5,408 | 33.673077 | 79 | py |
s2anet | s2anet-master/mmdet/models/backbones/resnext.py | import math
import torch.nn as nn
from mmdet.ops import DeformConv, ModulatedDeformConv
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet
class Bottleneck(_Bottleneck):
def __init__(self, inplanes, pl... | 8,336 | 33.882845 | 79 | py |
s2anet | s2anet-master/mmdet/models/mask_heads/grid_head.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import kaiming_init, normal_init
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule
@HEADS.register_module
class GridHead(nn.Module):
def __init__(self,
... | 15,429 | 41.624309 | 79 | py |
s2anet | s2anet-master/mmdet/models/mask_heads/maskiou_head.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import kaiming_init, normal_init
from torch.nn.modules.utils import _pair
from mmdet.core import force_fp32
from ..builder import build_loss
from ..registry import HEADS
@HEADS.register_module
class MaskIoUHead(nn.Module):
"""Mask IoU Head.
... | 7,418 | 37.842932 | 79 | py |
s2anet | s2anet-master/mmdet/models/mask_heads/fcn_mask_head.py | import mmcv
import numpy as np
import pycocotools.mask as mask_util
import torch
import torch.nn as nn
from torch.nn.modules.utils import _pair
from mmdet.core import auto_fp16, force_fp32, mask_target
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule
@HEADS.register_module... | 7,043 | 37.703297 | 79 | py |
s2anet | s2anet-master/mmdet/models/mask_heads/fused_semantic_head.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import kaiming_init
from mmdet.core import auto_fp16, force_fp32
from ..registry import HEADS
from ..utils import ConvModule
@HEADS.register_module
class FusedSemanticHead(nn.Module):
r"""Multi-level fused semantic segmentation head.
in_1 -... | 3,554 | 32.224299 | 79 | py |
s2anet | s2anet-master/mmdet/datasets/custom.py | import os.path as osp
import mmcv
import numpy as np
from torch.utils.data import Dataset
from .pipelines import Compose
from .registry import DATASETS
@DATASETS.register_module
class CustomDataset(Dataset):
"""Custom dataset for detection.
Annotation format:
[
{
'filename': 'a.jpg'... | 5,161 | 32.738562 | 76 | py |
s2anet | s2anet-master/mmdet/datasets/dataset_wrappers.py | import bisect
import math
from collections import defaultdict
import numpy as np
from torch.utils.data.dataset import ConcatDataset as _ConcatDataset
from .registry import DATASETS
@DATASETS.register_module
class ConcatDataset(_ConcatDataset):
"""A wrapper of concatenated dataset.
Same as :obj:`torch.utils... | 2,315 | 29.88 | 79 | py |
s2anet | s2anet-master/mmdet/datasets/loader/sampler.py | from __future__ import division
import math
import numpy as np
import torch
from mmcv.runner.utils import get_dist_info
from torch.utils.data import DistributedSampler as _DistributedSampler
from torch.utils.data import Sampler
class DistributedSampler(_DistributedSampler):
def __init__(self, dataset, num_repli... | 5,832 | 34.567073 | 78 | py |
s2anet | s2anet-master/mmdet/datasets/loader/build_loader.py | import platform
from functools import partial
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from torch.utils.data import DataLoader
from .sampler import DistributedGroupSampler, DistributedSampler, GroupSampler
if platform.system() != 'Windows':
# https://github.com/pytorch/pytorch/issu... | 1,559 | 30.836735 | 78 | py |
s2anet | s2anet-master/mmdet/datasets/pipelines/formating.py | from collections.abc import Sequence
import mmcv
import numpy as np
import torch
from mmcv.parallel import DataContainer as DC
from ..registry import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported types are: :class:`numpy.ndarray`, :class:`torch.... | 6,008 | 31.13369 | 93 | py |
s2anet | s2anet-master/mmdet/utils/flops_counter.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... | 14,351 | 32.069124 | 79 | py |
s2anet | s2anet-master/mmdet/ops/context_block.py | import torch
from mmcv.cnn import constant_init, kaiming_init
from torch import nn
def last_zero_init(m):
if isinstance(m, nn.Sequential):
constant_init(m[-1], val=0)
else:
constant_init(m, val=0)
class ContextBlock(nn.Module):
def __init__(self,
inplanes,
... | 3,766 | 34.87619 | 76 | py |
s2anet | s2anet-master/mmdet/ops/dcn/deform_pool.py | import torch
import torch.nn as nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from . import deform_pool_cuda
class DeformRoIPoolingFunction(Function):
@staticmethod
def forward(ctx,
data,
... | 10,212 | 39.367589 | 79 | py |
s2anet | s2anet-master/mmdet/ops/dcn/deform_conv.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from . import deform_conv_cuda
class DeformConvFunction(Function):
@staticmethod
def forward(ct... | 13,344 | 36.591549 | 80 | py |
s2anet | s2anet-master/mmdet/ops/orn/functions/active_rotating_filter.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
from torch import nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from .. import orn_cuda
#import _C
class _ActiveRotatingFilter(Function):
@s... | 2,736 | 27.510417 | 96 | py |
s2anet | s2anet-master/mmdet/ops/orn/functions/rotation_invariant_pooling.py | import torch
from torch import nn
from torch.nn import functional as F
class RotationInvariantPooling(nn.Module):
def __init__(self, nInputPlane, nOrientation=8):
super(RotationInvariantPooling, self).__init__()
self.nInputPlane = nInputPlane
self.nOrientation = nOrientation
hiddent_dim = int(n... | 940 | 26.676471 | 76 | py |
s2anet | s2anet-master/mmdet/ops/orn/functions/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
from .active_rotating_filter import active_rotating_filter
from .active_rotating_filter import ActiveRotatingFilter
from .rotation_invariant_encoding import rotation_invariant_encoding
from .rotation_invariant_encoding import RotationI... | 551 | 60.333333 | 148 | py |
s2anet | s2anet-master/mmdet/ops/orn/functions/rotation_invariant_encoding.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
from torch import nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from .. import orn_cuda
class _RotationInvariantEncoding(Function):
@staticme... | 1,900 | 31.775862 | 106 | py |
s2anet | s2anet-master/mmdet/ops/orn/modules/ORConv.py | from __future__ import absolute_import
import math
import torch
from torch.nn.parameter import Parameter
import torch.nn.functional as F
from torch.nn.modules import Conv2d
from torch.nn.modules.utils import _pair
from ..functions import active_rotating_filter
class ORConv2d(Conv2d):
def __init__(self, in_channels,... | 3,732 | 35.960396 | 121 | py |
s2anet | s2anet-master/mmdet/ops/masked_conv/masked_conv.py | 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
from . import masked_conv2d_cuda
class MaskedConv2dFunction(Function):
@staticmethod
def forward(ctx, features, mask, weight, b... | 3,375 | 36.511111 | 79 | py |
s2anet | s2anet-master/mmdet/ops/sigmoid_focal_loss/sigmoid_focal_loss.py | import torch.nn as nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from . import sigmoid_focal_loss_cuda
class SigmoidFocalLossFunction(Function):
@staticmethod
def forward(ctx, input, target, gamma=2.0, alpha=0.25):
ctx.save_for_backward(input, target)... | 1,637 | 28.781818 | 77 | py |
s2anet | s2anet-master/mmdet/ops/roi_align/roi_align.py | import torch.nn as nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from . import roi_align_cuda
class RoIAlignFunction(Function):
@staticmethod
def forward(ctx, features, rois, out_size, spatial_scale, sample_num=0):
... | 3,068 | 33.875 | 79 | py |
s2anet | s2anet-master/mmdet/ops/roi_align/gradcheck.py | import os.path as osp
import sys
import numpy as np
import torch
from torch.autograd import gradcheck
sys.path.append(osp.abspath(osp.join(__file__, '../../')))
from roi_align import RoIAlign # noqa: E402, isort:skip
feat_size = 15
spatial_scale = 1.0 / 8
img_size = feat_size / spatial_scale
num_imgs = 2
num_rois =... | 879 | 27.387097 | 76 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.