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 |
|---|---|---|---|---|---|---|
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/ckpt_convert.py | # Copyright (c) OpenMMLab. All rights reserved.
# This script consists of several convert functions which
# can modify the weights of model in original repo to be
# pre-trained weights.
from collections import OrderedDict
import torch
def pvt_convert(ckpt):
new_ckpt = OrderedDict()
# Process the concat bet... | 4,964 | 34.978261 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/conv_upsample.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, ModuleList
class ConvUpsample(BaseModule):
"""ConvUpsample performs 2x upsampling after Conv.
There are several `ConvModule` layers. In the first few layers, ups... | 2,653 | 38.029412 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
from torch.autograd import Function
from torch.nn import functional as F
class SigmoidGeometricMean(Function):
"""Forward and backward function of geometric mean of two sigmoid
functions.
This implementation with analytical gradient function substitutes
... | 2,606 | 34.712329 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/res_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import BaseModule, Sequential
from torch import nn as nn
class ResLayer(Sequential):
"""ResLayer to build ResNet style backbone.
Args:
block (nn.Module): block used to build ResLay... | 6,392 | 32.471204 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/brick_wrappers.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn.bricks.wrappers import NewEmptyTensorOp, obsolete_torch_version
if torch.__version__ == 'parrots':
TORCH_VERSION = torch.__version__
else:
# torch.__version__ could be 1.3.1+cu92, we... | 1,856 | 34.711538 | 77 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/panoptic_gt_processing.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def preprocess_panoptic_gt(gt_labels, gt_masks, gt_semantic_seg, num_things,
num_stuff, img_metas):
"""Preprocess the ground truth for a image.
Args:
gt_labels (Tensor): Ground truth labels of each bbox,
... | 2,536 | 35.768116 | 76 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/transformer.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import warnings
from typing import Sequence
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import (build_activation_layer, build_conv_layer,
build_norm_layer, xavier_init)
from mmcv.cnn.bricks.registry i... | 46,532 | 38.839897 | 132 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/positional_encoding.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
import torch.nn as nn
from mmcv.cnn.bricks.transformer import POSITIONAL_ENCODING
from mmcv.runner import BaseModule
@POSITIONAL_ENCODING.register_module()
class SinePositionalEncoding(BaseModule):
"""Position encoding with sine and cosine ... | 6,568 | 39.054878 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/inverted_residual.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import ConvModule
from mmcv.cnn.bricks import DropPath
from mmcv.runner import BaseModule
from .se_layer import SELayer
class InvertedResidual(BaseModule):
"""Inverted Residual Block.
Args... | 4,380 | 32.442748 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/utils/builder.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.utils import Registry, build_from_cfg
TRANSFORMER = Registry('Transformer')
LINEAR_LAYERS = Registry('linear layers')
def build_transformer(cfg, default_args=None):
"""Builder for Transformer."""
return build_from_cfg(cfg, TRANSF... | 1,535 | 31 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/standard_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
from ..builder import HEADS, build_head, build_roi_extractor
from .base_roi_head import BaseRoIHead
from .test_mixins import BBoxTestMixin, MaskTestMixin
@HEADS.register_module()
c... | 17,132 | 42.047739 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/grid_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmdet.core import bbox2result, bbox2roi
from ..builder import HEADS, build_head, build_roi_extractor
from .standard_roi_head import StandardRoIHead
@HEADS.register_module()
class GridRoIHead(StandardRoIHead):
"""Grid roi head fo... | 6,961 | 39.71345 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/scnet_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn.functional as F
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, multiclass_nms)
from ..builder import HEADS, build_head, build_roi_extractor
from ..uti... | 25,707 | 41.422442 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/sparse_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmdet.core import bbox2result, bbox2roi, bbox_xyxy_to_cxcywh
from mmdet.core.bbox.samplers import PseudoSampler
from ..builder import HEADS
from .cascade_roi_head import CascadeRoIHead
@HEADS.register_module()
class SparseRoIHead(Ca... | 19,280 | 44.367059 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/cascade_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
from mmcv.runner import ModuleList
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multicl... | 27,668 | 42.780063 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/trident_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.ops import batched_nms
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, merge_aug_bboxes,
multiclass_nms)
from mmdet.models.roi_heads.standard_roi_head import StandardRoIHead
from ..builder import HEADS
@HEADS.... | 5,321 | 42.983471 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/dynamic_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmdet.core import bbox2roi
from mmdet.models.losses import SmoothL1Loss
from ..builder import HEADS
from .standard_roi_head import StandardRoIHead
EPS = 1e-15
@HEADS.register_module()
class DynamicRoIHead(StandardRoIHead):
"""R... | 6,654 | 41.660256 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/point_rend_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
# Modified from https://github.com/facebookresearch/detectron2/tree/master/projects/PointRend # noqa
import os
import warnings
import numpy as np
import torch
import torch.nn.functional as F
from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
from mmdet.c... | 18,743 | 46.573604 | 101 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_scoring_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core import bbox2roi
from ..builder import HEADS, build_head
from .standard_roi_head import StandardRoIHead
@HEADS.register_module()
class MaskScoringRoIHead(StandardRoIHead):
"""Mask Scoring RoIHead for Mask Scoring RCNN.
https://arxiv... | 5,230 | 44.885965 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/htc_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn.functional as F
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, multiclass_nms)
from ..builder import HEADS, build_head, build_roi_extractor
from ..uti... | 27,702 | 43.042925 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/test_mixins.py | # Copyright (c) OpenMMLab. All rights reserved.
import sys
import warnings
import numpy as np
import torch
from mmdet.core import (bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, multiclass_nms)
if sys.version_info >= (3, 7):
from mmdet.utils.contextmanagers import completed
... | 13,557 | 42.455128 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/roi_extractors/base_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
from abc import ABCMeta, abstractmethod
import torch
import torch.nn as nn
from mmcv import ops
from mmcv.runner import BaseModule
class BaseRoIExtractor(BaseModule, metaclass=ABCMeta):
"""Base class for RoI extractor.
Args:
roi_layer (dict): Specify R... | 3,002 | 32.741573 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.runner import force_fp32
from mmdet.models.builder import ROI_EXTRACTORS
from .base_roi_extractor import BaseRoIExtractor
@ROI_EXTRACTORS.register_module()
class SingleRoIExtractor(BaseRoIExtractor):
"""Extract RoI features from a single leve... | 4,736 | 40.920354 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/bbox_heads/bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.runner import BaseModule, auto_fp16, force_fp32
from torch.nn.modules.utils import _pair
from mmdet.core import build_bbox_coder, multi_apply, multiclass_nms
from mmdet.models.builder import HEA... | 25,657 | 42.122689 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/bbox_heads/sabl_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, force_fp32
from mmdet.core import build_bbox_coder, multi_apply, multiclass_nms
from mmdet.models.builder import HEAD... | 25,392 | 41.534338 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/bbox_heads/dii_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.cnn import (bias_init_with_prob, build_activation_layer,
build_norm_layer)
from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
from mmcv.runner import auto_fp16, force_fp32
from mmdet.core imp... | 19,199 | 43.964871 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/bbox_heads/convfc_bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmdet.models.builder import HEADS
from mmdet.models.utils import build_linear_layer
from .bbox_head import BBoxHead
@HEADS.register_module()
class ConvFCBBoxHead(BBoxHead):
r"""More general bbox head, with ... | 8,364 | 35.369565 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/bbox_heads/double_bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, ModuleList
from mmdet.models.backbones.resnet import Bottleneck
from mmdet.models.builder import HEADS
from .bbox_head import BBoxHead
class BasicResBlock(BaseModule):
"""Basi... | 5,733 | 31.03352 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/shared_heads/res_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
from mmcv.runner import BaseModule, auto_fp16
from mmdet.models.backbones import ResNet
from mmdet.models.builder import SHARED_HEADS
from mmdet.models.utils import ResLayer as _ResLayer
@SHARED_HEADS.register_module()
class ResLa... | 2,587 | 30.950617 | 76 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/grid_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class GridHead(BaseModule):
def __i... | 15,579 | 41.802198 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/dynamic_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.runner import auto_fp16, force_fp32
from mmdet.core import mask_target
from mmdet.models.builder import HEADS
from mmdet.models.dense_heads.atss_head import reduce_mean
from mmdet.models.utils import build_transformer
from .fc... | 5,665 | 37.283784 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/maskiou_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import Conv2d, Linear, MaxPool2d
from mmcv.runner import BaseModule, force_fp32
from torch.nn.modules.utils import _pair
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
clas... | 7,382 | 39.125 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/feature_relay_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.runner import BaseModule, auto_fp16
from mmdet.models.builder import HEADS
@HEADS.register_module()
class FeatureRelayHead(BaseModule):
"""Feature Relay Head used in `SCNet <https://arxiv.org/abs/2012.10150>`_.
Args:
in_... | 1,930 | 34.759259 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/global_context_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, auto_fp16, force_fp32
from mmdet.models.builder import HEADS
from mmdet.models.utils import ResLayer, SimplifiedBasicBlock
@HEADS.register_module()
class GlobalContextHead(BaseMod... | 3,774 | 36.009804 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from warnings import warn
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule, build_conv_layer, build_upsample_layer
from mmcv.ops.carafe import CARAFEPack
from mmcv.runner import BaseModule, ModuleList, ... | 17,449 | 41.251816 | 85 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/fused_semantic_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule, auto_fp16, force_fp32
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class FusedSemanticHead(BaseModu... | 4,231 | 34.563025 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/roi_heads/mask_heads/mask_point_head.py | # Copyright (c) OpenMMLab. All rights reserved.
# Modified from https://github.com/facebookresearch/detectron2/tree/master/projects/PointRend/point_head/point_head.py # noqa
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
from mmcv.r... | 10,785 | 41.464567 | 126 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/ghm_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weight_reduce_loss
def _expand_onehot_labels(labels, label_weights, label_channels):
bin_labels = labels.new_full((labels.size(0), label_channels), 0)... | 7,923 | 36.028037 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/mse_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weighted_loss
@weighted_loss
def mse_loss(pred, target):
"""Wrapper of mse loss."""
return F.mse_loss(pred, target, reduction='none')
@LOSSES.register_module... | 1,905 | 31.862069 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/dice_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from ..builder import LOSSES
from .utils import weight_reduce_loss
def dice_loss(pred,
target,
weight=None,
eps=1e-3,
reduction='mean',
naive_dice=False,
... | 5,324 | 35.22449 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/pisa_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.core import bbox_overlaps
@mmcv.jit(derivate=True, coderize=True)
def isr_p(cls_score,
bbox_pred,
bbox_targets,
rois,
sampling_results,
loss_cls,
bbox_coder,
k=2,
... | 7,216 | 38.010811 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/balanced_l1_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import torch
import torch.nn as nn
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def balanced_l1_loss(pred,
target,
beta=1.0,... | 4,252 | 33.024 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/iou_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import warnings
import mmcv
import torch
import torch.nn as nn
from mmdet.core import bbox_overlaps
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def iou_loss(pred, target, linear=False... | 15,714 | 32.084211 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/smooth_l1_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
import torch.nn as nn
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def smooth_l1_loss(pred, target, beta=1.0):
"""Smooth L1 loss.
Args:
pred (torch.Tensor)... | 4,635 | 30.537415 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/gfocal_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def quality_focal_loss(pred, target, beta=2.0):
r"""Quality Focal Loss (QFL) is fr... | 9,834 | 38.979675 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/varifocal_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weight_reduce_loss
@mmcv.jit(derivate=True, coderize=True)
def varifocal_loss(pred,
target,
weight=None,
... | 5,365 | 38.748148 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import functools
import mmcv
import torch
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".
R... | 3,310 | 30.235849 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/seesaw_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .accuracy import accuracy
from .cross_entropy_loss import cross_entropy
from .utils import weight_reduce_loss
def seesaw_ce_loss(cls_score,
labels,
... | 10,136 | 37.543726 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/ae_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
@mmcv.jit(derivate=True, coderize=True)
def ae_loss_per_image(tl_preds, br_preds, match):
"""Associative Embedding Loss in one image.
Associative Embedd... | 3,857 | 36.096154 | 143 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/accuracy.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch.nn as nn
@mmcv.jit(coderize=True)
def accuracy(pred, target, topk=1, thresh=None):
"""Calculate accuracy according to the prediction and target.
Args:
pred (torch.Tensor): The model prediction, shape (N, num_class)
targe... | 2,990 | 36.3875 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/focal_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.ops import sigmoid_focal_loss as _sigmoid_focal_loss
from ..builder import LOSSES
from .utils import weight_reduce_loss
# This method is only for debugging
def py_sigmoid_focal_loss(pred,
... | 10,420 | 41.534694 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/cross_entropy_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weight_reduce_loss
def cross_entropy(pred,
label,
weight=None,
reduction='mean',
... | 12,143 | 39.211921 | 132 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/gaussian_focal_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch.nn as nn
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def gaussian_focal_loss(pred, gaussian_target, alpha=2.0, gamma=4.0):
"""`Focal Loss <https://arxiv.org/abs/1708.0... | 3,312 | 34.623656 | 108 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/losses/kd_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weighted_loss
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def knowledge_distillation_kl_div_loss(pred,
so... | 2,912 | 31.730337 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/pvt.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import warnings
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import (Conv2d, build_activation_layer, build_norm_layer,
constant_init, normal_init, trunc_normal_init)
from mmcv.cnn.br... | 23,217 | 38.219595 | 89 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/hrnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import BaseModule, ModuleList, Sequential
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
from .resnet import BasicBlock, Bot... | 23,106 | 38.164407 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/regnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import numpy as np
import torch.nn as nn
from mmcv.cnn import build_conv_layer, build_norm_layer
from ..builder import BACKBONES
from .resnet import ResNet
from .resnext import Bottleneck
@BACKBONES.register_module()
class RegNet(ResNet):
"""RegNet... | 13,605 | 37.112045 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/mobilenet_v2.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
from ..utils import InvertedResidual, make_divisible
@BACKBONES.register_module()... | 7,599 | 37.383838 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/swin.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
from collections import OrderedDict
from copy import deepcopy
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as cp
from mmcv.cnn import build_norm_layer, constant_init, trunc_normal_init
from mmcv.cnn.bric... | 30,579 | 38.560155 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/trident_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as cp
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import BaseModule
from torch.nn.modules.utils import _pair
from mmdet.models.backbones.resnet i... | 11,129 | 36.22408 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/detectors_resnext.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
from mmcv.cnn import build_conv_layer, build_norm_layer
from ..builder import BACKBONES
from .detectors_resnet import Bottleneck as _Bottleneck
from .detectors_resnet import DetectoRS_ResNet
class Bottleneck(_Bottleneck):
expansion = 4
def __init_... | 3,920 | 30.620968 | 77 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/efficientnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import math
from functools import partial
import torch
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn.bricks import ConvModule, DropPath
from mmcv.runner import BaseModule, Sequential
from ..builder import BACKBONES
from ..utils impo... | 16,218 | 37.801435 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import build_conv_layer, build_norm_layer, build_plugin_layer
from mmcv.runner import BaseModule
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
fro... | 23,840 | 34.424963 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/detectors_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import (build_conv_layer, build_norm_layer, constant_init,
kaiming_init)
from mmcv.runner import Sequential, load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
fr... | 12,736 | 34.980226 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/ssd_vgg.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import torch.nn as nn
from mmcv.cnn import VGG
from mmcv.runner import BaseModule
from ..builder import BACKBONES
from ..necks import ssd_neck
@BACKBONES.register_module()
class SSDVGG(VGG, BaseModule):
"""VGG Backbone network for single-shot-detec... | 4,705 | 35.48062 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/resnext.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
from mmcv.cnn import build_conv_layer, build_norm_layer
from ..builder import BACKBONES
from ..utils import ResLayer
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet
class Bottleneck(_Bottleneck):
expansion = 4
def __init__... | 5,712 | 35.858065 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/resnest.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as cp
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import BaseModule
from ..builder import BACKBONES
from ..utils import ResLayer
fro... | 10,579 | 31.755418 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/csp_darknet.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
from mmcv.runner import BaseModule
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
from ..utils import CSPLayer
class Focus(n... | 10,543 | 35.996491 | 77 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/hourglass.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
from ..builder import BACKBONES
from ..utils import ResLayer
from .resnet import BasicBlock
class HourglassModule(BaseModule):
"""Hourglass Modu... | 7,494 | 32.609865 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/res2net.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import build_conv_layer, build_norm_layer
from mmcv.runner import Sequential
from ..builder import BACKBONES
from .resnet import Bottleneck as _Bottleneck
from .resnet impor... | 11,659 | 34.54878 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/models/backbones/darknet.py | # Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) 2019 Western Digital Corporation or its affiliates.
import warnings
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import BaseModule
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
class ResBlo... | 8,233 | 37.476636 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/custom.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import warnings
from collections import OrderedDict
import mmcv
import numpy as np
from mmcv.utils import print_log
from terminaltables import AsciiTable
from torch.utils.data import Dataset
from mmdet.core import eval_map, eval_recalls
from .build... | 15,497 | 36.525424 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/openimages.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import csv
import json
import os.path as osp
import warnings
from collections import OrderedDict, defaultdict
import mmcv
import numpy as np
import torch.distributed as dist
from mmcv.runner import get_dist_info
from mmcv.utils import print_log
from mmdet.co... | 35,084 | 38.33296 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/dataset_wrappers.py | # Copyright (c) OpenMMLab. All rights reserved.
import bisect
import collections
import copy
import math
from collections import defaultdict
import numpy as np
from mmcv.utils import build_from_cfg, print_log
from torch.utils.data.dataset import ConcatDataset as _ConcatDataset
from .builder import DATASETS, PIPELINES... | 17,774 | 37.894967 | 167 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/builder.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import platform
import random
import warnings
from functools import partial
import numpy as np
import torch
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from mmcv.utils import TORCH_VERSION, Registry, build_from_cfg, digit_version
f... | 8,421 | 37.990741 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/samplers/group_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import numpy as np
import torch
from mmcv.runner import get_dist_info
from torch.utils.data import Sampler
class GroupSampler(Sampler):
def __init__(self, dataset, samples_per_gpu=1):
assert hasattr(dataset, 'flag')
self.dataset = datas... | 5,384 | 35.14094 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/samplers/infinite_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import itertools
import numpy as np
import torch
from mmcv.runner import get_dist_info
from torch.utils.data.sampler import Sampler
from mmdet.core.utils import sync_random_seed
class InfiniteGroupBatchSampler(Sampler):
"""Similar to `BatchSampler` warping a `Grou... | 7,064 | 36.780749 | 110 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/samplers/distributed_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
from torch.utils.data import DistributedSampler as _DistributedSampler
from mmdet.core.utils import sync_random_seed
from mmdet.utils import get_device
class DistributedSampler(_DistributedSampler):
def __init__(self,
dat... | 2,037 | 36.054545 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/samplers/class_aware_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
from mmcv.runner import get_dist_info
from torch.utils.data import Sampler
from mmdet.core.utils import sync_random_seed
class ClassAwareSampler(Sampler):
r"""Sampler that restricts data loading to the label of the dataset.
A class-aw... | 6,543 | 35.971751 | 104 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/datasets/pipelines/formatting.py | # Copyright (c) OpenMMLab. All rights reserved.
from collections.abc import Sequence
import mmcv
import numpy as np
import torch
from mmcv.parallel import DataContainer as DC
from ..builder import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported ty... | 13,853 | 33.292079 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/contextmanagers.py | # Copyright (c) OpenMMLab. All rights reserved.
import asyncio
import contextlib
import logging
import os
import time
from typing import List
import torch
logger = logging.getLogger(__name__)
DEBUG_COMPLETED_TIME = bool(os.environ.get('DEBUG_COMPLETED_TIME', False))
@contextlib.asynccontextmanager
async def comple... | 4,125 | 32.544715 | 79 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/memory.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
from collections import abc
from contextlib import contextmanager
from functools import wraps
import torch
from mmdet.utils import get_root_logger
def cast_tensor_type(inputs, src_type=None, dst_type=None):
"""Recursively convert Tensor in inputs f... | 8,088 | 36.799065 | 103 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/ascend_util.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def masked_fill(ori_tensor, mask, new_value, neg=False):
"""The Value of ori_tensor is new_value, depending on mask.
Args:
ori_tensor (Tensor): Input tensor.
mask (Tensor): If select new_value.
new_value(Tensor | scalar): Va... | 2,359 | 32.714286 | 75 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/profiling.py | # Copyright (c) OpenMMLab. All rights reserved.
import contextlib
import sys
import time
import torch
if sys.version_info >= (3, 7):
@contextlib.contextmanager
def profile_time(trace_name,
name,
enabled=True,
stream=None,
end... | 1,336 | 31.609756 | 73 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import glob
import os
import os.path as osp
import warnings
import mmcv
import torch
from mmcv.utils import TORCH_VERSION, digit_version, print_log
def find_latest_checkpoint(path, suffix='pth'):
"""Find the latest checkpoint from the working directory.
Args:
... | 2,818 | 30.322222 | 74 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/setup_env.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import platform
import warnings
import cv2
import torch.multiprocessing as mp
def setup_multi_processes(cfg):
"""Setup multi-processing environment variables."""
# set multi-process start method as `fork` to speed up the training
if platform.syste... | 2,428 | 43.981481 | 112 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/util_distribution.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
dp_factory = {'cuda': MMDataParallel, 'cpu': MMDataParallel}
ddp_factory = {'cuda': MMDistributedDataParallel}
def build_dp(model, device='cuda', dim=0, *args, **kwargs):
"""build Dat... | 3,189 | 33.301075 | 78 | py |
LineFormer | LineFormer-main/mmdetection/mmdet/utils/split_batch.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def split_batch(img, img_metas, kwargs):
"""Split data_batch by tags.
Code is modified from
<https://github.com/microsoft/SoftTeacher/blob/main/ssod/utils/structure_utils.py> # noqa: E501
Args:
img (Tensor): of shape (N, C, H, W) e... | 1,778 | 37.673913 | 99 | py |
auto_LiRPA | auto_LiRPA-master/setup.py | from setuptools import setup, find_packages
from pathlib import Path
# Check PyTorch version
pytorch_version_l = '1.11.0'
pytorch_version_u = '1.13.0' # excluded
msg_install_pytorch = (f'It is recommended to manually install PyTorch '
f'(>={pytorch_version_u},<{pytorch_version_u}) suitable '
... | 2,285 | 39.821429 | 224 | py |
auto_LiRPA | auto_LiRPA-master/examples/sequence/lstm.py | import os
import shutil
import torch
import torch.nn as nn
from auto_LiRPA.utils import logger
class LSTMCore(nn.Module):
def __init__(self, args):
super(LSTMCore, self).__init__()
self.input_size = args.input_size // args.num_slices
self.hidden_size = args.hidden_size
self.num_cla... | 2,669 | 32.797468 | 88 | py |
auto_LiRPA | auto_LiRPA-master/examples/sequence/data_utils.py | import random
from torchvision import transforms
from torchvision.datasets.mnist import MNIST as mnist
def load_data():
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])
data_train = mnist("data", train=True, download=True, transform=transform)
data_test = ... | 771 | 41.888889 | 103 | py |
auto_LiRPA | auto_LiRPA-master/examples/sequence/train.py | import argparse
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from lstm import LSTM
from data_utils import load_data, get_batches
from auto_LiRPA import BoundedModule, BoundedTensor, PerturbationLpNorm
from auto_LiRPA.utils import AverageMeter, logger, get_spec_matr... | 5,589 | 40.102941 | 166 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/verify_two_node.py | """
Example for multi-node perturbation. An input image is splited to two parts
where each part is perturbed respectively constained by L-inf norm. It is
expected to output the same results as running `simple_verification.py` where
the whole image is perturbed constained by L-inf norm.
"""
import os
import torch.nn as... | 2,819 | 34.25 | 97 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/imagenet_training.py | import random
import time
import argparse
import multiprocessing
import logging
import torch.optim as optim
from torch.nn import CrossEntropyLoss
from auto_LiRPA import BoundedModule, BoundedTensor, BoundDataParallel, CrossEntropyWrapper
from auto_LiRPA.bound_ops import BoundExp
from auto_LiRPA.perturbations import *
f... | 16,082 | 49.259375 | 127 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/tinyimagenet_training.py | import os
import random
import time
import argparse
import multiprocessing
import logging
import torch.optim as optim
from torch.nn import CrossEntropyLoss
from auto_LiRPA import BoundedModule, BoundedTensor, BoundDataParallel, CrossEntropyWrapper
from auto_LiRPA.bound_ops import BoundExp
from auto_LiRPA.perturbations ... | 16,170 | 49.220497 | 127 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/cifar_training.py | import argparse
import multiprocessing
import random
import time
import logging
import os
import torch.optim as optim
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from torch.nn import CrossEntropyLoss
import models
from auto_LiRPA import BoundedModule, BoundedTensor, BoundDataPa... | 16,978 | 49.683582 | 168 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/datasets.py | import multiprocessing
import torch
from torch.utils import data
from functools import partial
import torchvision.transforms as transforms
import torchvision.datasets as datasets
# compute image statistics (by Andreas https://discuss.pytorch.org/t/computing-the-mean-and-std-of-dataset/34949/4)
def get_stats(loader):
... | 8,851 | 45.589474 | 175 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/custom_op.py | """ A example for custom operators.
In this example, we create a custom operator called "PlusConstant", which can
be written as "f(x) = x + c" for some constant "c" (an attribute of the operator).
"""
import torch
import torch.nn as nn
import torchvision
from auto_LiRPA import BoundedModule, BoundedTensor, register_cu... | 5,110 | 39.563492 | 121 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/simple_training.py | """
A simple script to train certified defense using the auto_LiRPA library.
We compute output bounds under input perturbations using auto_LiRPA, and use
them to form a "robust loss" for certified defense. Several different bound
options are supported, such as IBP, CROWN, and CROWN-IBP. This is a basic
example on MNI... | 12,047 | 52.309735 | 163 | py |
auto_LiRPA | auto_LiRPA-master/examples/vision/simple_verification.py | """
A simple example for bounding neural network outputs under input perturbations.
This example serves as a skeleton for robustness verification of neural networks.
"""
import os
from collections import defaultdict
import torch
import torch.nn as nn
import torchvision
from auto_LiRPA import BoundedModule, BoundedTens... | 7,184 | 51.065217 | 165 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.