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 |
|---|---|---|---|---|---|---|
D2Det | D2Det-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... | 22,843 | 43.271318 | 79 | py |
D2Det | D2Det-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,580 | 41.691542 | 79 | py |
D2Det | D2Det-master/mmdet/models/detectors/test_mixins.py | import logging
import sys
import torch
from mmdet.core import (bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, merge_aug_proposals, multiclass_nms)
logger = logging.getLogger(__name__)
if sys.version_info >= (3, 7):
from mmdet.utils.contextmanagers import completed
class RPN... | 11,312 | 41.370787 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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,004 | 38.075521 | 79 | py |
D2Det | D2Det-master/mmdet/models/necks/fpn_carafe.py | import torch.nn as nn
from mmcv.cnn import xavier_init
from mmdet.ops.carafe import CARAFEPack
from ..registry import NECKS
from ..utils import ConvModule, build_upsample_layer
@NECKS.register_module
class FPN_CARAFE(nn.Module):
"""FPN_CARAFE is a more flexible implementation of FPN.
It allows more choice fo... | 10,293 | 39.368627 | 79 | py |
D2Det | D2Det-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):
"""
Feature Pyramid Network.
This is an implementation of - Feature Pyramid Net... | 6,625 | 35.811111 | 79 | py |
D2Det | D2Det-master/mmdet/models/necks/nas_fpn.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import caffe2_xavier_init
from ..registry import NECKS
from ..utils import ConvModule
class MergingCell(nn.Module):
def __init__(self, channels=256, with_conv=True, norm_cfg=None):
super(MergingCell, self).__init__()
self.with_c... | 6,608 | 34.342246 | 78 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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,173 | 44.517588 | 79 | py |
D2Det | D2Det-master/mmdet/models/anchor_heads/atss_head.py | import numpy as np
import torch
import torch.distributed as dist
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (PseudoSampler, anchor_inside_flags, bbox2delta,
build_assigner, delta2bbox, force_fp32,
images_to_levels, multi_apply, multicla... | 19,669 | 39.307377 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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,895 | 40.981873 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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... | 8,031 | 38.762376 | 79 | py |
D2Det | D2Det-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,509 | 39.366748 | 79 | py |
D2Det | D2Det-master/mmdet/models/anchor_heads/retina_sepbn_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 RetinaSepBNHead(AnchorHead):
""""RetinaHead with separate BN.
In RetinaHead, conv/norm l... | 3,902 | 35.820755 | 76 | py |
D2Det | D2Det-master/mmdet/models/anchor_heads/free_anchor_retina_head.py | import torch
import torch.nn.functional as F
from mmdet.core import bbox2delta, bbox_overlaps, delta2bbox
from ..registry import HEADS
from .retina_head import RetinaHead
@HEADS.register_module
class FreeAnchorRetinaHead(RetinaHead):
def __init__(self,
num_classes,
in_channels,... | 7,396 | 38.137566 | 79 | py |
D2Det | D2Det-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,251 | 39.598071 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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... | 11,326 | 39.024735 | 79 | py |
D2Det | D2Det-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,910 | 35.760638 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-master/mmdet/models/shared_heads/res_layer.py | 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 mmdet.utils import get_root_logger
from ..backbones import ResNet, make_res_layer
from ..registry import SHARED_HEADS
@SHARED_HEADS.register_module
class ResLayer(nn.Mo... | 2,258 | 30.375 | 74 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-master/mmdet/models/utils/conv_module.py | import warnings
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmdet.ops import DeformConvPack, ModulatedDeformConvPack
from .conv_ws import ConvWS2d
from .norm import build_norm_layer
conv_cfg = {
'Conv': nn.Conv2d,
'ConvWS': ConvWS2d,
'DCN': DeformConvPack,
'DCNv2': Mod... | 5,866 | 33.922619 | 78 | py |
D2Det | D2Det-master/mmdet/models/utils/upsample.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmdet.ops.carafe import CARAFEPack
class PixelShufflePack(nn.Module):
""" Pixel Shuffle upsample layer
Args:
in_channels (int): Number of input channels
out_channels (int): Number of output channels
... | 2,250 | 27.493671 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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,700 | 30.313084 | 89 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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,784 | 32.554217 | 76 | py |
D2Det | D2Det-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 |
D2Det | D2Det-master/mmdet/models/backbones/hrnet.py | 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 mmdet.utils import get_root_logger
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import BasicBlock... | 19,890 | 36.887619 | 79 | py |
D2Det | D2Det-master/mmdet/models/backbones/resnet.py | 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
from mmdet.utils import get_root_... | 16,921 | 31.731141 | 79 | py |
D2Det | D2Det-master/mmdet/models/backbones/ssd_vgg.py | 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 mmdet.utils import get_root_logger
from ..registry import BACKBONES
@BACKBONES.register_module
class SSDVGG(VGG):
"""VGG ... | 5,357 | 33.792208 | 79 | py |
D2Det | D2Det-master/mmdet/models/backbones/resnext.py | import math
import torch.nn as nn
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, planes, groups=1, base_width=4, **kwargs):
"""Bo... | 7,588 | 33.03139 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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,453 | 38.026178 | 79 | py |
D2Det | D2Det-master/mmdet/models/mask_heads/D2Det_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
from mmdet.core import mask_target
@HEADS.register_module
class D2DetHead(nn.Module):
d... | 13,433 | 40.591331 | 146 | py |
D2Det | D2Det-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 mmdet.ops.carafe import CARAFEPack
from ..builder import build_loss
from ..registry import HEADS
from ..utils im... | 8,239 | 38.425837 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-master/mmdet/datasets/custom.py | import os.path as osp
import mmcv
import numpy as np
from torch.utils.data import Dataset
from mmdet.core import eval_map, eval_recalls
from .pipelines import Compose
from .registry import DATASETS
@DATASETS.register_module
class CustomDataset(Dataset):
"""Custom dataset for detection.
Annotation format:
... | 7,767 | 35.299065 | 79 | py |
D2Det | D2Det-master/mmdet/datasets/dataset_wrappers.py | 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.data.dataset.ConcatDataset`, but
concat the group flag for... | 1,639 | 28.285714 | 78 | py |
D2Det | D2Det-master/mmdet/datasets/loader/sampler.py | from __future__ import division
import math
import numpy as np
import torch
from mmcv.runner 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_replicas=No... | 5,860 | 34.521212 | 78 | py |
D2Det | D2Det-master/mmdet/datasets/loader/build_loader.py | import platform
import random
from functools import partial
import numpy as np
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:... | 3,063 | 33.426966 | 78 | py |
D2Det | D2Det-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,200 | 31.129534 | 79 | py |
D2Det | D2Det-master/mmdet/utils/contextmanagers.py | 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 completed(trace_name='',
name='',
... | 4,099 | 31.539683 | 79 | py |
D2Det | D2Det-master/mmdet/utils/profiling.py | 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_stream=None):
"""Print time spent by CP... | 1,364 | 31.5 | 74 | py |
D2Det | D2Det-master/mmdet/utils/collect_env.py | import os.path as osp
import subprocess
import sys
from collections import defaultdict
import cv2
import mmcv
import torch
import torchvision
import mmdet
def collect_env():
env_info = {}
env_info['sys.platform'] = sys.platform
env_info['Python'] = sys.version.replace('\n', '')
cuda_available = tor... | 1,971 | 29.8125 | 74 | py |
D2Det | D2Det-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,304 | 31.146067 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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
import torch.nn as nn
from collections import OrderedDict
import torch.nn.functional as F
import math
COEFF = 12.0
cl... | 11,726 | 38.220736 | 112 | py |
D2Det | D2Det-master/mmdet/ops/dcn/deform_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, _single
from mmdet.utils import print_log
from . import deform_conv_cuda
class DeformConvFunction(Function):
@staticmethod
def... | 16,838 | 37.979167 | 80 | py |
D2Det | D2Det-master/mmdet/ops/dcn/src/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
import torch.nn as nn
from collections import OrderedDict
import torch.nn.functional as F
import math
COEFF = 12.0
de... | 11,924 | 37.717532 | 104 | py |
D2Det | D2Det-master/mmdet/ops/affine_grid/affine_grid.py | import torch
import torch.nn.functional as F
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from . import affine_grid_cuda
class _AffineGridGenerator(Function):
@staticmethod
def forward(ctx, theta, size, align_corners):
ctx.save_for_backward(theta)
... | 2,375 | 33.434783 | 79 | py |
D2Det | D2Det-master/mmdet/ops/grid_sampler/grid_sampler.py | import torch
import torch.nn.functional as F
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from . import grid_sampler_cuda
class _GridSampler(Function):
@staticmethod
def forward(ctx, input, grid, mode_enum, padding_mode_enum, align_corners):
ctx.save_f... | 4,453 | 36.116667 | 79 | py |
D2Det | D2Det-master/mmdet/ops/carafe/grad_check.py | import os.path as osp
import sys
import mmcv
import torch
from torch.autograd import gradcheck
sys.path.append(osp.abspath(osp.join(__file__, '../../')))
from mmdet.ops.carafe import CARAFENAIVE # noqa: E402, isort:skip
from mmdet.ops.carafe import carafe_naive # noqa: E402, isort:skip
from mmdet.ops.carafe import ... | 2,118 | 33.177419 | 77 | py |
D2Det | D2Det-master/mmdet/ops/carafe/setup.py | from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
NVCC_ARGS = [
'-D__CUDA_NO_HALF_OPERATORS__',
'-D__CUDA_NO_HALF_CONVERSIONS__',
'-D__CUDA_NO_HALF2_OPERATORS__',
]
setup(
name='carafe',
ext_modules=[
CUDAExtension(
'carafe_cuda',... | 791 | 25.4 | 77 | py |
D2Det | D2Det-master/mmdet/ops/carafe/carafe.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import normal_init, xavier_init
from torch.autograd import Function
from torch.nn.modules.module import Module
from . import carafe_cuda, carafe_naive_cuda
class CARAFENaiveFunction(Function):
@staticmethod
def forward(ctx, fea... | 8,809 | 36.016807 | 79 | py |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-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 |
D2Det | D2Det-master/mmdet/ops/roi_pool/roi_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 roi_pool_cuda
class RoIPoolFunction(Function):
@staticmethod
def forward(ctx, features, rois, out_size, spatial_scale):
... | 2,544 | 32.486842 | 78 | py |
D2Det | D2Det-master/mmdet/ops/roi_pool/gradcheck.py | import os.path as osp
import sys
import torch
from torch.autograd import gradcheck
sys.path.append(osp.abspath(osp.join(__file__, '../../')))
from roi_pool import RoIPool # noqa: E402, isort:skip
feat = torch.randn(4, 16, 15, 15, requires_grad=True).cuda()
rois = torch.Tensor([[0, 0, 0, 50, 50], [0, 10, 30, 43, 55]... | 513 | 29.235294 | 66 | py |
D2Det | D2Det-master/mmdet/ops/nms/nms_wrapper.py | import numpy as np
import torch
from . import nms_cpu, nms_cuda
def nms(dets, iou_thr, device_id=None):
"""Dispatch to either CPU or GPU NMS implementations.
The input can be either a torch tensor or numpy array. GPU NMS will be used
if the input is a gpu tensor or device_id is specified, otherwise CPU ... | 4,349 | 35.554622 | 79 | py |
delay_stability | delay_stability-master/main.py | # Version ICLR 11/09/2019
import warnings
import argparse
import os
import socket
import logging
import torch
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim
import torch.utils.data
import utils.tensorboard as tb
import models
import torch.distributed as dist
from data import DataRegime... | 16,457 | 48.423423 | 120 | py |
delay_stability | delay_stability-master/data.py | import os
import torch
import torchvision.datasets as datasets
from torch.utils.data.distributed import DistributedSampler
from torch.utils.data.sampler import RandomSampler
from utils.regime import Regime
from preprocess import get_transform
def get_dataset(name, split='train', transform=None,
target... | 4,733 | 42.431193 | 95 | py |
delay_stability | delay_stability-master/power_iteration.py | import torch
def hess_largest_eigenvalue(criterion, inputs, target, net, device, tolerance=1e-6, max_iters=100):
# Create gradients vector
# Create v
dim = 0
for w in net.parameters():
dim += w.numel()
v = torch.normal(torch.zeros(dim), 1).to(device)
iter_num = 0
lmbda = 9999
... | 1,967 | 32.931034 | 110 | py |
delay_stability | delay_stability-master/parameter_server.py | # Version ICLR 11/09/2019
import torch
import torch.nn as nn
from torch.nn.utils import clip_grad_norm_
from utils.optim import OptimRegime
from copy import deepcopy
from math import sqrt, log2, floor
import utils.tensorboard as tb
import logging
class ParameterServer(object):
@staticmethod
def get_server(m... | 16,993 | 42.352041 | 118 | py |
delay_stability | delay_stability-master/preprocess.py | import torch
import numpy as np
import torchvision.transforms as transforms
import random
_IMAGENET_STATS = {'mean': [0.485, 0.456, 0.406],
'std': [0.229, 0.224, 0.225]}
_IMAGENET_PCA = {
'eigval': torch.Tensor([0.2175, 0.0188, 0.0045]),
'eigvec': torch.Tensor([
[-0.5675, 0.7192, ... | 6,972 | 33.519802 | 123 | py |
delay_stability | delay_stability-master/trainer.py | # Version ICLR 11/09/2019
import time
import logging
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import utils.tensorboard as tb
from utils.meters import AverageMeter, accuracy
import numpy as np
from scipy.stats import norm
from collections import defaultdict
class Trainer(object):
... | 7,947 | 41.276596 | 108 | py |
delay_stability | delay_stability-master/models/mobilenet_v2.py | import torch
import torch.nn as nn
from torch.nn.modules.utils import _single, _pair, _triple
import math
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
import torchvision.transforms as transforms
__all__ = ['mobilenet_v2']
def nearby_int(n):
return int(round(n))
def init_model(model):... | 6,028 | 38.149351 | 106 | py |
delay_stability | delay_stability-master/models/resnet_zi.py | import torch
import torch.nn as nn
import torchvision.transforms as transforms
import math
from .modules.se import SEBlock
__all__ = ['resnet_zi', 'resnet_zi_se']
def conv3x3(in_planes, out_planes, stride=1, groups=1, bias=True):
"3x3 convolution with padding"
return nn.Conv2d(in_planes, out_planes, kernel_si... | 12,209 | 36.33945 | 113 | py |
delay_stability | delay_stability-master/models/fully_conn.py | # Version ICLR 11/09/2019
import torch
import torch.nn as nn
from models.modules.fixed_proj import LinearFixed
__all__ = ['fully_conn']
class fully_conn_model(nn.Module):
def __init__(self, depth=3, width=1024, regime='normal', regime_lr=0.1, regime_momentum=0.9, regime_dampening=0,
fixed_linea... | 1,663 | 37.697674 | 116 | py |
delay_stability | delay_stability-master/models/resnet.py | # Version ICLR 11/09/2019
import torch
import torch.nn as nn
import math
from .modules.se import SEBlock
import utils.tensorboard as tb
import logging
batch_norm = nn.BatchNorm2d
nn_linear = nn.Linear
__all__ = ['resnet', 'resnet_se']
def conv3x3(in_planes, out_planes, stride=1, groups=1, bias=False):
"3x3 convo... | 15,733 | 37.18932 | 113 | py |
delay_stability | delay_stability-master/models/vgg.py | # Version ICLR 11/09/2019
import torch.nn as nn
__all__ = ['vgg']
batch_norm = nn.BatchNorm2d
class VGG(nn.Module):
def __init__(self, features, num_classes=1000, init_weights=True, regime='normal_imnet', regime_momentum=0.9,
regime_lr=1e-2, regime_dampening=0, scale_lr=1):
super(VGG, se... | 6,656 | 35.179348 | 117 | py |
delay_stability | delay_stability-master/models/densenet.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from collections import OrderedDict
__all__ = ['densenet']
def init_model(model):
# Official init from torch repo.
for m in model.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight)
elif isins... | 9,762 | 39.679167 | 110 | py |
delay_stability | delay_stability-master/models/googlenet.py | from collections import OrderedDict
import torch
import torch.nn as nn
__all__ = ['googlenet']
class Inception_v1_GoogLeNet(nn.Module):
input_side = 227
rescale = 255.0
rgb_mean = [122.7717, 115.9465, 102.9801]
rgb_std = [1, 1, 1]
def __init__(self, num_classes=1000):
super(Inception_v1_G... | 4,998 | 41.008403 | 120 | py |
delay_stability | delay_stability-master/models/cifar_shallow.py | import torch
import torch.nn as nn
__all__ = ['cifar10_shallow', 'cifar100_shallow']
class AlexNet(nn.Module):
def __init__(self, num_classes=10, regime_momentum=0.9, regime_lr=1e-2, regime_dampening=0, regime='normal'):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
... | 2,404 | 35.439394 | 113 | py |
delay_stability | delay_stability-master/models/resnext.py | import torch
import torch.nn as nn
import math
from .resnet import ResNet_imagenet, ResNet_cifar, BasicBlock, Bottleneck
from .modules.se import SEBlock
__all__ = ['resnext', 'resnext_se']
class ResNeXt_imagenet(ResNet_imagenet):
def __init__(self, width=[128, 256, 512, 1024], groups=[32, 32, 32, 32], expansion... | 1,888 | 32.732143 | 100 | py |
delay_stability | delay_stability-master/models/convnet.py | # Version ICLR 11/09/2019
import torch
import torch.nn as nn
import torch.nn.functional as F
__all__ = ['convnet']
class conv_model(nn.Module):
def __init__(self, regime='normal', regime_lr=0.1, regime_momentum=0.9, regime_dampening=0, **kwargs):
super(conv_model, self).__init__()
self.conv1 = n... | 1,479 | 31.888889 | 106 | py |
delay_stability | delay_stability-master/models/inception_resnet_v2.py | import torch
import torch.nn as nn
from collections import OrderedDict
__all__ = ['inception_resnet_v2']
""" inception_resnet_v2.
References:
Inception-v4, Inception-ResNet and the Impact of Residual Connections
on Learning
Christian Szegedy, Sergey Ioffe, Vincent Vanhoucke, Alex Alemi.
Links:
http://a... | 9,552 | 35.742308 | 81 | py |
delay_stability | delay_stability-master/models/mobilenet.py | import torch
import torch.nn as nn
from torch.nn.modules.utils import _single, _pair, _triple
import math
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
import torchvision.transforms as transforms
__all__ = ['mobilenet']
def nearby_int(n):
return int(round(n))
def init_model(model):
... | 6,691 | 37.45977 | 79 | py |
delay_stability | delay_stability-master/models/inception_v2.py | import torch
import torch.nn as nn
import torchvision.transforms as transforms
import math
__all__ = ['inception_v2']
def conv_bn(in_planes, out_planes, kernel_size, stride=1, padding=0):
"convolution with batchnorm, relu"
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size, stride=stri... | 5,514 | 34.811688 | 89 | py |
delay_stability | delay_stability-master/models/mnist.py | import torch
import torch.nn as nn
__all__ = ['mnist']
class mnist_model(nn.Module):
def __init__(self):
super(mnist_model, self).__init__()
self.feats = nn.Sequential(
nn.Conv2d(1, 32, 5, 1, 1),
nn.MaxPool2d(2, 2),
nn.ReLU(True),
nn.BatchNorm2d(32)... | 1,059 | 22.555556 | 47 | py |
delay_stability | delay_stability-master/models/wideresnet.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from models.modules.gbn import GhostBatchNorm
from numpy import sqrt
batch_norm = nn.BatchNorm2d
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0, bn_momentum=0.1):
super(BasicBlock, ... | 7,232 | 41.547059 | 117 | py |
delay_stability | delay_stability-master/models/alexnet.py | import torch.nn as nn
import torchvision.transforms as transforms
__all__ = ['alexnet']
batch_norm = nn.BatchNorm2d
class AlexNetOWT_BN(nn.Module):
def __init__(self, num_classes=1000, regime_momentum=0.9, regime_lr=1e-2, regime_dampening=0):
super(AlexNetOWT_BN, self).__init__()
self.features = ... | 3,126 | 35.788235 | 98 | py |
delay_stability | delay_stability-master/models/modules/fixed_proj.py | import torch.nn as nn
import math
import torch
from torch.autograd import Variable
from scipy.linalg import hadamard
import utils.tensorboard as tb
class HadamardProj(nn.Module):
def __init__(self, input_size, output_size, bias=True, fixed_weights=True, fixed_scale=None):
super(HadamardProj, self).__init... | 2,862 | 32.682353 | 97 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.