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
Pedestron
Pedestron-master/mmdet/core/evaluation/eval_hooks.py
import os import os.path as osp import mmcv import numpy as np import torch import torch.distributed as dist from mmcv.runner import Hook, obj_from_dict from mmcv.parallel import scatter, collate from pycocotools.cocoeval import COCOeval from torch.utils.data import Dataset from .coco_utils import results2json, fast_...
8,060
37.203791
77
py
Pedestron
Pedestron-master/mmdet/core/post_processing/merge_augs.py
import torch import numpy as np from mmdet.ops import nms from ..bbox import bbox_mapping_back def merge_aug_proposals(aug_proposals, img_metas, rpn_test_cfg): """Merge augmented proposals (multiscale, flip, etc.) Args: aug_proposals (list[Tensor]): proposals from different testing sche...
3,317
33.206186
78
py
Pedestron
Pedestron-master/mmdet/core/post_processing/bbox_nms.py
import torch from mmdet.ops.nms import nms_wrapper def multiclass_nms(multi_bboxes, multi_scores, score_thr, nms_cfg, max_num=-1, score_factors=None): """NMS for multi-class bboxes. Args: multi_bboxes (Ten...
2,277
34.046154
75
py
Pedestron
Pedestron-master/mmdet/core/mask/mask_target.py
import torch import numpy as np import mmcv def mask_target(pos_proposals_list, pos_assigned_gt_inds_list, gt_masks_list, cfg): cfg_list = [cfg for _ in range(len(pos_proposals_list))] mask_targets = map(mask_target_single, pos_proposals_list, pos_assigned_gt_inds_list, ...
1,427
37.594595
77
py
Pedestron
Pedestron-master/mmdet/core/my_mmcv/runner/mean_teacher_runner.py
from mmcv.runner import Runner import logging import os.path as osp import time import mmcv import torch from mmcv.runner import hooks from mmcv.runner.log_buffer import LogBuffer from mmdet.core.my_mmcv.runner.hooks.mean_teacher_optimizer import OptimizerHook from mmcv.runner.hooks import (Hook, LrUpdaterHook, Chec...
6,235
35.899408
94
py
Pedestron
Pedestron-master/mmdet/core/my_mmcv/runner/hooks/mean_teacher_optimizer.py
from torch.nn.utils import clip_grad from mmcv.runner.hooks.hook import Hook class OptimizerHook(Hook): def __init__(self, grad_clip=None, mean_teacher=None): self.grad_clip = grad_clip self.mean_teacher = mean_teacher def clip_grads(self, params): clip_grad.clip_grad_norm_( ...
1,009
33.827586
129
py
Pedestron
Pedestron-master/mmdet/core/fp16/hooks.py
import copy import torch import torch.nn as nn from mmcv.runner import OptimizerHook from .utils import cast_tensor_type from ..utils.dist_utils import allreduce_grads class Fp16OptimizerHook(OptimizerHook): """FP16 optimizer hook. The steps of fp16 optimizer is as follows. 1. Scale the loss value. ...
4,481
34.291339
79
py
Pedestron
Pedestron-master/mmdet/core/fp16/utils.py
from collections import abc import numpy as np import torch def cast_tensor_type(inputs, src_type, dst_type): if isinstance(inputs, torch.Tensor): return inputs.to(dst_type) elif isinstance(inputs, str): return inputs elif isinstance(inputs, np.ndarray): return inputs elif isi...
664
26.708333
74
py
Pedestron
Pedestron-master/mmdet/core/fp16/decorators.py
import functools from inspect import getfullargspec import torch from .utils import cast_tensor_type def auto_fp16(apply_to=None, out_fp32=False): """Decorator to enable fp16 training automatically. This decorator is useful when you write custom modules and want to support mixed precision training. If ...
6,211
37.583851
79
py
Pedestron
Pedestron-master/mmdet/core/bbox/bbox_target.py
import torch from .transforms import bbox2delta from ..utils import multi_apply def bbox_target(pos_bboxes_list, neg_bboxes_list, pos_gt_bboxes_list, pos_gt_labels_list, cfg, reg_classes=1, target_means=[.0, .0, .0, .0], ...
2,799
36.837838
78
py
Pedestron
Pedestron-master/mmdet/core/bbox/geometry.py
import torch def bbox_overlaps(bboxes1, bboxes2, mode='iou', is_aligned=False): """Calculate overlap between two set of bboxes. If ``is_aligned`` is ``False``, then calculate the ious between each bbox of bboxes1 and bboxes2, otherwise the ious between each aligned pair of bboxes1 and bboxes2. A...
2,163
32.8125
79
py
Pedestron
Pedestron-master/mmdet/core/bbox/transforms.py
import mmcv import numpy as np import torch def bbox2delta(proposals, gt, means=[0, 0, 0, 0], stds=[1, 1, 1, 1]): assert proposals.size() == gt.size() proposals = proposals.float() gt = gt.float() px = (proposals[..., 0] + proposals[..., 2]) * 0.5 py = (proposals[..., 1] + proposals[..., 3]) * 0....
15,256
34.31713
146
py
Pedestron
Pedestron-master/mmdet/core/bbox/assigners/assign_result.py
import torch class AssignResult(object): def __init__(self, num_gts, gt_inds, max_overlaps, labels=None): self.num_gts = num_gts self.gt_inds = gt_inds self.max_overlaps = max_overlaps self.labels = labels def add_gt_(self, gt_labels): self_inds = torch.arange( ...
664
32.25
77
py
Pedestron
Pedestron-master/mmdet/core/bbox/assigners/approx_max_iou_assigner.py
import torch from .max_iou_assigner import MaxIoUAssigner from ..geometry import bbox_overlaps class ApproxMaxIoUAssigner(MaxIoUAssigner): """Assign a corresponding gt bbox or background to each bbox. Each proposals will be assigned with `-1`, `0`, or a positive integer indicating the ground truth index...
4,950
41.316239
79
py
Pedestron
Pedestron-master/mmdet/core/bbox/assigners/max_iou_assigner.py
import torch from .base_assigner import BaseAssigner from .assign_result import AssignResult from ..geometry import bbox_overlaps class MaxIoUAssigner(BaseAssigner): """Assign a corresponding gt bbox or background to each bbox. Each proposals will be assigned with `-1`, `0`, or a positive integer indica...
6,462
41.24183
79
py
Pedestron
Pedestron-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
Pedestron
Pedestron-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,753
33.860759
78
py
Pedestron
Pedestron-master/mmdet/core/bbox/samplers/random_sampler.py
import numpy as np import torch from .base_sampler import BaseSampler class RandomSampler(BaseSampler): def __init__(self, num, pos_fraction, neg_pos_ub=-1, add_gt_as_proposals=True, **kwargs): super(RandomSampler, self...
1,858
33.425926
77
py
Pedestron
Pedestron-master/mmdet/core/bbox/samplers/ohem_sampler.py
import torch from .base_sampler import BaseSampler from ..transforms import bbox2roi class OHEMSampler(BaseSampler): def __init__(self, num, pos_fraction, context, neg_pos_ub=-1, add_gt_as_proposals=True, **kwa...
2,769
36.432432
77
py
Pedestron
Pedestron-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
Pedestron
Pedestron-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
Pedestron
Pedestron-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
Pedestron
Pedestron-master/mmdet/core/utils/dist_utils.py
from collections import OrderedDict import torch.distributed as dist from torch._utils import (_flatten_dense_tensors, _unflatten_dense_tensors, _take_tensors) from mmcv.runner import OptimizerHook def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1): if bucket_size_mb > 0: ...
2,439
34.362319
97
py
Pedestron
Pedestron-master/mmdet/core/anchor/anchor_target.py
import torch from ..bbox import assign_and_sample, build_assigner, PseudoSampler, bbox2delta from ..utils import multi_apply def anchor_target(anchor_list, valid_flag_list, gt_bboxes_list, img_metas, target_means, target_stds, ...
7,556
37.953608
79
py
Pedestron
Pedestron-master/mmdet/core/anchor/guided_anchor_target.py
import torch from ..bbox import build_assigner, build_sampler, PseudoSampler from ..utils import unmap, multi_apply 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...
12,146
41.472028
79
py
Pedestron
Pedestron-master/mmdet/core/anchor/anchor_generator.py
import torch class AnchorGenerator(object): def __init__(self, base_size, scales, ratios, scale_major=True, ctr=None): self.base_size = base_size self.scales = torch.Tensor(scales) self.ratios = torch.Tensor(ratios) self.scale_major = scale_major self.ctr = ctr sel...
3,117
35.682353
78
py
Pedestron
Pedestron-master/mmdet/models/builder.py
from torch import nn from mmdet.utils import build_from_cfg from .registry import (BACKBONES, NECKS, ROI_EXTRACTORS, SHARED_HEADS, HEADS, LOSSES, DETECTORS) def build(cfg, registry, default_args=None): if isinstance(cfg, list): modules = [ build_from_cfg(cfg_, registry,...
959
20.818182
78
py
Pedestron
Pedestron-master/mmdet/models/detectors/two_stage.py
import torch import torch.nn as nn from .base import BaseDetector from .test_mixins import RPNTestMixin, BBoxTestMixin, MaskTestMixin from .. import builder from ..registry import DETECTORS from mmdet.core import bbox2roi, bbox2result, build_assigner, build_sampler @DETECTORS.register_module class TwoStageDetector(B...
9,289
37.547718
79
py
Pedestron
Pedestron-master/mmdet/models/detectors/base.py
import logging from abc import ABCMeta, abstractmethod import mmcv import numpy as np import torch.nn as nn import pycocotools.mask as maskUtils from mmdet.core import tensor2imgs, get_classes, auto_fp16 class BaseDetector(nn.Module): """Base class for detectors""" __metaclass__ = ABCMeta def __init__...
4,967
31.051613
77
py
Pedestron
Pedestron-master/mmdet/models/detectors/single_stage.py
import torch.nn as nn from .base import BaseDetector from .. import builder from ..registry import DETECTORS from mmdet.core import bbox2result @DETECTORS.register_module class SingleStageDetector(BaseDetector): def __init__(self, backbone, neck=None, bbox_head...
2,475
32.459459
78
py
Pedestron
Pedestron-master/mmdet/models/detectors/cascade_rcnn.py
from __future__ import division import torch import torch.nn as nn from .base import BaseDetector from .test_mixins import RPNTestMixin from .. import builder from ..registry import DETECTORS from mmdet.core import (build_assigner, bbox2roi, bbox2result, build_sampler, merge_aug_masks) @DETE...
15,878
40.786842
79
py
Pedestron
Pedestron-master/mmdet/models/detectors/grid_rcnn.py
from .two_stage import TwoStageDetector from ..registry import DETECTORS import torch from .. import builder from mmdet.core import bbox2roi, bbox2result, build_assigner, build_sampler @DETECTORS.register_module class GridRCNN(TwoStageDetector): """Grid R-CNN. This detector is the implementation of: - ...
8,293
39.262136
79
py
Pedestron
Pedestron-master/mmdet/models/detectors/mgan.py
import torch import torch.nn as nn from .base import BaseDetector from .test_mixins import RPNTestMixin, BBoxTestMixin from .. import builder from ..registry import DETECTORS from mmdet.core import bbox2roi, bbox2result, build_assigner, build_sampler @DETECTORS.register_module class MGAN(BaseDetector, RPNTestMixin, ...
4,332
33.11811
79
py
Pedestron
Pedestron-master/mmdet/models/detectors/htc.py
import torch import torch.nn.functional as F from .cascade_rcnn import CascadeRCNN from .. import builder from ..registry import DETECTORS from mmdet.core import (bbox2roi, bbox2result, build_assigner, build_sampler, merge_aug_masks) @DETECTORS.register_module class HybridTaskCascade(CascadeR...
17,522
43.138539
79
py
Pedestron
Pedestron-master/mmdet/models/detectors/mask_scoring_rcnn.py
import torch from mmdet.core import bbox2roi, build_assigner, build_sampler from .two_stage import TwoStageDetector from .. import builder from ..registry import DETECTORS @DETECTORS.register_module class MaskScoringRCNN(TwoStageDetector): """Mask Scoring RCNN. https://arxiv.org/abs/1903.00241 """ ...
8,496
41.914141
79
py
Pedestron
Pedestron-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,709
31.26087
79
py
Pedestron
Pedestron-master/mmdet/models/plugins/generalized_attention.py
import torch import torch.nn as nn import torch.nn.functional as F import math import numpy as np 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
Pedestron
Pedestron-master/mmdet/models/necks/csp_neck.py
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init from mmcv.cnn import xavier_init from mmdet.core import auto_fp16 from ..registry import NECKS from ..utils import ConvModule import cv2 @NECKS.register_module class CSPNeck(nn.Module): def __init__(self, ...
3,042
29.128713
83
py
Pedestron
Pedestron-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,284
35.958042
79
py
Pedestron
Pedestron-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
Pedestron
Pedestron-master/mmdet/models/necks/hrfpn.py
import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.checkpoint import checkpoint from mmcv.cnn.weight_init import caffe2_xavier_init from ..utils import ConvModule from ..registry import NECKS @NECKS.register_module class HRFPN(nn.Module): """HRFPN (High Resolution Feature Pyrmami...
3,244
32.112245
79
py
Pedestron
Pedestron-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,186
33.641304
79
py
Pedestron
Pedestron-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 .anchor_head import AnchorHead from ..registry import HEADS @HEADS.register_module class RPNHead(AnchorHead): def __init__(self, in_channels, **kwa...
4,050
37.580952
79
py
Pedestron
Pedestron-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, multi_apply, multiclass_nms, force_fp32) from ..builder import build_loss from ..registry import HEADS @H...
11,132
40.081181
79
py
Pedestron
Pedestron-master/mmdet/models/anchor_heads/retina_head.py
import numpy as np import torch.nn as nn from mmcv.cnn import normal_init from .anchor_head import AnchorHead from ..registry import HEADS from ..utils import bias_init_with_prob, ConvModule @HEADS.register_module class RetinaHead(AnchorHead): def __init__(self, num_classes, in...
2,866
33.130952
76
py
Pedestron
Pedestron-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 .guided_anchor_head import GuidedAnchorHead from ..registry import HEADS @HEADS.register_module class GARPNHead(GuidedAnchorHead): """Guided-Anchor-...
5,332
40.664063
79
py
Pedestron
Pedestron-master/mmdet/models/anchor_heads/ga_retina_head.py
import torch.nn as nn from mmcv.cnn import normal_init from .guided_anchor_head import GuidedAnchorHead, FeatureAdaption from ..registry import HEADS from ..utils import bias_init_with_prob, ConvModule from mmdet.ops import MaskedConv2d @HEADS.register_module class GARetinaHead(GuidedAnchorHead): """Guided-Ancho...
4,013
36.166667
78
py
Pedestron
Pedestron-master/mmdet/models/anchor_heads/csp_head.py
import torch import torch.nn as nn from mmcv.cnn import normal_init from mmdet.core import multi_apply, multiclass_nms, csp_height2bbox, csp_heightwidth2bbox, force_fp32 from ..builder import build_loss from ..registry import HEADS from ..utils import bias_init_with_prob, Scale, ConvModule import cv2 import numpy as ...
16,638
39.385922
113
py
Pedestron
Pedestron-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 .anchor_head import AnchorHead from ..losses import smooth_l1_loss from ..registry import HEADS # TODO: add loss evaluator for...
7,708
38.737113
79
py
Pedestron
Pedestron-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 multi_apply, multiclass_nms, distance2bbox, force_fp32 from ..builder import build_loss from ..registry import HEADS from ..utils import bias_init_with_prob, Scale, ConvModule INF = 1e8 @HEADS.register_module class FCOSHead(n...
15,870
39.590793
79
py
Pedestron
Pedestron-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_target, anchor_inside_flags, ga_loc_target, ga_shape_target, delta2bbox, multi_apply, multiclass_nms, f...
24,865
39.763934
79
py
Pedestron
Pedestron-master/mmdet/models/bbox_heads/mgan_head.py
import torch.nn as nn from ..registry import HEADS from ..utils import ConvModule from mmdet.core import auto_fp16 @HEADS.register_module class MGANHead(nn.Module): def __init__(self, num_convs=2, roi_feat_size=7, in_channels=512, conv_out_chan...
1,503
27.377358
71
py
Pedestron
Pedestron-master/mmdet/models/bbox_heads/bbox_head.py
import torch import torch.nn as nn import torch.nn.functional as F from mmdet.core import (delta2bbox, multiclass_nms, bbox_target, force_fp32, auto_fp16) from ..builder import build_loss from ..losses import accuracy from ..registry import HEADS @HEADS.register_module class BBoxHead(nn.Modul...
8,861
36.710638
79
py
Pedestron
Pedestron-master/mmdet/models/bbox_heads/cascade_ped_head.py
import torch.nn as nn from .bbox_head import BBoxHead from ..registry import HEADS from ..utils import ConvModule from ..bbox_heads.convfc_bbox_head import ConvFCBBoxHead import torch import torch.nn as nn import torch.nn.functional as F from mmdet.core import (delta2bbox, multiclass_nms, bbox_target, force_fp32, ...
2,870
34.012195
95
py
Pedestron
Pedestron-master/mmdet/models/bbox_heads/convfc_bbox_head.py
import torch.nn as nn from .bbox_head import BBoxHead from ..registry import HEADS from ..utils import ConvModule @HEADS.register_module class ConvFCBBoxHead(BBoxHead): """More general bbox head, with shared conv and fc layers and two optional separated branches. /-> cls conv...
7,011
36.698925
79
py
Pedestron
Pedestron-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
Pedestron
Pedestron-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
Pedestron
Pedestron-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
Pedestron
Pedestron-master/mmdet/models/utils/scale.py
import torch import torch.nn as nn class Scale(nn.Module): 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
266
19.538462
73
py
Pedestron
Pedestron-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
Pedestron
Pedestron-master/mmdet/models/utils/conv_module.py
import warnings import torch.nn as nn from mmcv.cnn import kaiming_init, constant_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,543
32.804878
79
py
Pedestron
Pedestron-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,156
35.64881
79
py
Pedestron
Pedestron-master/mmdet/models/losses/mse_loss.py
import torch.nn as nn import torch.nn.functional as F from .utils import weighted_loss from ..registry import LOSSES 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
Pedestron
Pedestron-master/mmdet/models/losses/balanced_l1_loss.py
import numpy as np import torch import torch.nn as nn from .utils import weighted_loss from ..registry import LOSSES @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
Pedestron
Pedestron-master/mmdet/models/losses/iou_loss.py
import torch import torch.nn as nn from mmdet.core import bbox_overlaps from .utils import weighted_loss from ..registry import LOSSES @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...
4,339
30.911765
79
py
Pedestron
Pedestron-master/mmdet/models/losses/smooth_l1_loss.py
import torch import torch.nn as nn from .utils import weighted_loss from ..registry import LOSSES @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
Pedestron
Pedestron-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 = ...
2,982
29.438776
79
py
Pedestron
Pedestron-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
Pedestron
Pedestron-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 .utils import weight_reduce_loss from ..registry import LOSSES # This method is only for debugging def py_sigmoid_focal_loss(pred, target, wei...
2,784
32.554217
76
py
Pedestron
Pedestron-master/mmdet/models/losses/cross_entropy_loss.py
import torch import torch.nn as nn import torch.nn.functional as F from .utils import weight_reduce_loss from ..registry import LOSSES 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
Pedestron
Pedestron-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_norm_layer, build_conv_layer from .resnet import BasicBlock, Bottleneck class HRM...
18,403
36.946392
79
py
Pedestron
Pedestron-master/mmdet/models/backbones/resnet.py
import logging import torch.nn as nn import torch.utils.checkpoint as cp from torch.nn.modules.batchnorm import _BatchNorm from mmcv.cnn import constant_init, kaiming_init from mmcv.runner import load_checkpoint from mmdet.ops import DeformConv, ModulatedDeformConv, ContextBlock from mmdet.models.plugins import Gene...
17,451
32.05303
79
py
Pedestron
Pedestron-master/mmdet/models/backbones/vgg.py
import logging import torch.nn as nn from mmcv.cnn import (VGG, constant_init, kaiming_init, normal_init) from mmcv.runner import load_checkpoint from ..registry import BACKBONES @BACKBONES.register_module class VGG(VGG): def __init__(self, depth=16, with_...
1,449
28
74
py
Pedestron
Pedestron-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, xavier_init, constant_init, kaiming_init, normal_init) from mmcv.runner import load_checkpoint from ..registry import BACKBONES @BACKBONES.register_module class SSDVGG(VGG): extra_s...
4,657
33.503704
79
py
Pedestron
Pedestron-master/mmdet/models/backbones/resnext.py
import math import torch.nn as nn from mmdet.ops import DeformConv, ModulatedDeformConv from .resnet import Bottleneck as _Bottleneck from .resnet import ResNet from ..registry import BACKBONES from ..utils import build_conv_layer, build_norm_layer class Bottleneck(_Bottleneck): def __init__(self, inplanes, pl...
7,841
34.008929
79
py
Pedestron
Pedestron-master/mmdet/models/backbones/senet.py
from __future__ import print_function, division, absolute_import from collections import OrderedDict import math from ..registry import BACKBONES import torch.nn as nn from torch.utils import model_zoo from mmcv.runner import load_checkpoint import logging """ https://github.com/Cadene/pretrained-models.pytorch/blob/ma...
13,521
35.349462
112
py
Pedestron
Pedestron-master/mmdet/models/backbones/mobilenet.py
import logging from mmcv.runner import load_checkpoint import torch import torch.nn as nn from mmcv.cnn import (constant_init, kaiming_init, normal_init) from ..registry import BACKBONES model_urls = { 'mobilenet_v2': 'https://download.pytorch.org/models/mobilenet_v2-b0353104.pth', } def _make_divisible(v, div...
6,210
35.110465
107
py
Pedestron
Pedestron-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,299
41.5
79
py
Pedestron
Pedestron-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 mmdet.core import force_fp32 from ..builder import build_loss from ..registry import HEADS @HEADS.register_module class MaskIoUHead(nn.Module): """Mask IoU Head. This head predicts the IoU of predicted ...
7,254
37.796791
79
py
Pedestron
Pedestron-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 ..builder import build_loss from ..registry import HEADS from ..utils import ConvModule from mmdet.core import mask_target, force_fp32, auto_fp16 @HEADS.register_module class FCNMaskHead(nn.Module): def _...
6,971
37.733333
79
py
Pedestron
Pedestron-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): """Multi-level fused semantic segmentation head. in_1 ->...
3,552
32.205607
79
py
Pedestron
Pedestron-master/mmdet/datasets/custom.py
import os.path as osp import mmcv import numpy as np from mmcv.parallel import DataContainer as DC from torch.utils.data import Dataset from .registry import DATASETS from .transforms import (ImageTransform, BboxTransform, MaskTransform, SegMapTransform, Numpy2Tensor) from .utils import to_te...
14,115
37.994475
108
py
Pedestron
Pedestron-master/mmdet/datasets/utils.py
from collections import Sequence import matplotlib.pyplot as plt import mmcv import numpy as np import torch def to_tensor(data): """Convert objects of various python types to :obj:`torch.Tensor`. Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`, :class:`Sequence`, :class:`int` and :cl...
2,178
30.57971
72
py
Pedestron
Pedestron-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
Pedestron
Pedestron-master/mmdet/datasets/transforms.py
import mmcv import numpy as np import torch __all__ = [ 'ImageTransform', 'BboxTransform', 'MaskTransform', 'SegMapTransform', 'Numpy2Tensor' ] class ImageTransform(object): """Preprocess an image. 1. rescale the image to expected size 2. normalize the image 3. flip the image (if needed) ...
4,454
29.101351
79
py
Pedestron
Pedestron-master/mmdet/datasets/loader/sampler.py
from __future__ import division import math import torch import numpy as np from mmcv.runner.utils import get_dist_info from torch.utils.data import Sampler from torch.utils.data import DistributedSampler as _DistributedSampler class DistributedSampler(_DistributedSampler): def __init__(self, dataset, num_repl...
5,668
34.21118
78
py
Pedestron
Pedestron-master/mmdet/datasets/loader/build_loader.py
import platform from functools import partial from mmcv.runner import get_dist_info from mmcv.parallel import collate from torch.utils.data import DataLoader from .sampler import GroupSampler, DistributedGroupSampler, DistributedSampler if platform.system() != 'Windows': # https://github.com/pytorch/pytorch/issu...
1,559
30.836735
78
py
Pedestron
Pedestron-master/mmdet/ops/dcn/functions/deform_pool.py
import torch from torch.autograd import Function from .. import deform_pool_cuda class DeformRoIPoolingFunction(Function): @staticmethod def forward(ctx, data, rois, offset, spatial_scale, out_size, out_channels,...
2,370
32.871429
78
py
Pedestron
Pedestron-master/mmdet/ops/dcn/functions/deform_conv.py
import torch from torch.autograd import Function from torch.nn.modules.utils import _pair from .. import deform_conv_cuda class DeformConvFunction(Function): @staticmethod def forward(ctx, input, offset, weight, stride=1, paddin...
7,291
39.065934
79
py
Pedestron
Pedestron-master/mmdet/ops/dcn/modules/deform_pool.py
from torch import nn from ..functions.deform_pool import deform_roi_pooling class DeformRoIPooling(nn.Module): def __init__(self, spatial_scale, out_size, out_channels, no_trans, group_size=1, part_size=None, ...
7,058
39.803468
79
py
Pedestron
Pedestron-master/mmdet/ops/dcn/modules/deform_conv.py
import math import torch import torch.nn as nn from torch.nn.modules.utils import _pair from ..functions.deform_conv import deform_conv, modulated_deform_conv class DeformConv(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, ...
5,198
31.905063
78
py
Pedestron
Pedestron-master/mmdet/ops/masked_conv/functions/masked_conv.py
import math import torch from torch.autograd import Function from torch.nn.modules.utils import _pair from .. import masked_conv2d_cuda class MaskedConv2dFunction(Function): @staticmethod def forward(ctx, features, mask, weight, bias, padding=0, stride=1): assert mask.dim() == 3 and mask.size(0) == 1...
2,333
39.947368
79
py
Pedestron
Pedestron-master/mmdet/ops/masked_conv/modules/masked_conv.py
import torch.nn as nn from ..functions.masked_conv import masked_conv2d class MaskedConv2d(nn.Conv2d): """A MaskedConv2d which inherits the official Conv2d. The masked forward doesn't implement the backward function and only supports the stride parameter to be 1 currently. """ def __init__(self,...
1,010
31.612903
76
py
Pedestron
Pedestron-master/mmdet/ops/sigmoid_focal_loss/functions/sigmoid_focal_loss.py
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) num_classes ...
1,081
29.914286
77
py
Pedestron
Pedestron-master/mmdet/ops/sigmoid_focal_loss/modules/sigmoid_focal_loss.py
from torch import nn from ..functions.sigmoid_focal_loss import sigmoid_focal_loss # TODO: remove this module class SigmoidFocalLoss(nn.Module): def __init__(self, gamma, alpha): super(SigmoidFocalLoss, self).__init__() self.gamma = gamma self.alpha = alpha def forward(self, logits,...
670
25.84
74
py
Pedestron
Pedestron-master/mmdet/ops/gcb/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
Pedestron
Pedestron-master/mmdet/ops/roi_align/gradcheck.py
import numpy as np import torch from torch.autograd import gradcheck import os.path as osp import sys sys.path.append(osp.abspath(osp.join(__file__, '../../'))) from roi_align import RoIAlign # noqa: E402 feat_size = 15 spatial_scale = 1.0 / 8 img_size = feat_size / spatial_scale num_imgs = 2 num_rois = 20 batch_in...
866
27.9
76
py
Pedestron
Pedestron-master/mmdet/ops/roi_align/functions/roi_align.py
from torch.autograd import Function from .. import roi_align_cuda class RoIAlignFunction(Function): @staticmethod def forward(ctx, features, rois, out_size, spatial_scale, sample_num=0): if isinstance(out_size, int): out_h = out_size out_w = out_size elif isinstance(o...
2,113
33.096774
79
py
Pedestron
Pedestron-master/mmdet/ops/roi_align/modules/roi_align.py
from torch.nn.modules.module import Module from ..functions.roi_align import RoIAlignFunction class RoIAlign(Module): def __init__(self, out_size, spatial_scale, sample_num=0): super(RoIAlign, self).__init__() self.out_size = out_size self.spatial_scale = float(spatial_scale) sel...
535
30.529412
74
py
Pedestron
Pedestron-master/mmdet/ops/roi_pool/gradcheck.py
import torch from torch.autograd import gradcheck import os.path as osp import sys sys.path.append(osp.abspath(osp.join(__file__, '../../'))) from roi_pool import RoIPool # noqa: E402 feat = torch.randn(4, 16, 15, 15, requires_grad=True).cuda() rois = torch.Tensor([[0, 0, 0, 50, 50], [0, 10, 30, 43, 55], ...
500
30.3125
66
py