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 |
|---|---|---|---|---|---|---|
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/base_dense_head.py | from abc import ABCMeta, abstractmethod
import torch.nn as nn
class BaseDenseHead(nn.Module, metaclass=ABCMeta):
"""Base class for DenseHeads."""
def __init__(self):
super(BaseDenseHead, self).__init__()
@abstractmethod
def loss(self, **kwargs):
"""Compute losses of the head."""
... | 2,051 | 33.2 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/free_anchor_retina_head.py | import torch
import torch.nn.functional as F
from mmdet.core import bbox_overlaps
from ..builder import HEADS
from .retina_head import RetinaHead
EPS = 1e-12
@HEADS.register_module()
class FreeAnchorRetinaHead(RetinaHead):
"""FreeAnchor RetinaHead used in https://arxiv.org/abs/1909.02466.
Args:
num... | 11,148 | 40.140221 | 94 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/guided_anchor_head.py | import torch
import torch.nn as nn
from mmcv.cnn import bias_init_with_prob, normal_init
from mmcv.ops import DeformConv2d, MaskedConv2d
from mmcv.runner import force_fp32
from mmdet.core import (anchor_inside_flags, build_anchor_generator,
build_assigner, build_bbox_coder, build_sampler,
... | 36,623 | 41.536585 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/sabl_retina_head.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, bias_init_with_prob, normal_init
from mmcv.runner import force_fp32
from mmdet.core import (build_anchor_generator, build_assigner,
build_bbox_coder, build_sampler, images_to_levels,
m... | 27,171 | 42.684887 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/fovea_head.py | import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, normal_init
from mmcv.ops import DeformConv2d
from mmdet.core import multi_apply, multiclass_nms
from ..builder import HEADS
from .anchor_free_head import AnchorFreeHead
INF = 1e8
class FeatureAlign(nn.Module):
def __init__(self,
... | 14,405 | 41.122807 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/dense_test_mixins.py | from inspect import signature
import torch
from mmdet.core import bbox2result, bbox_mapping_back, multiclass_nms
class BBoxTestMixin(object):
"""Mixin class for test time augmentation of bboxes."""
def merge_aug_bboxes(self, aug_bboxes, aug_scores, img_metas):
"""Merge augmented detection bboxes an... | 4,092 | 39.524752 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/dense_heads/transformer_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import Conv2d, Linear, build_activation_layer
from mmcv.runner import force_fp32
from mmdet.core import (bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh,
build_assigner, build_sampler, multi_apply,
... | 30,957 | 46.264122 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/utils/gaussian_target.py | from math import sqrt
import torch
def gaussian2D(radius, sigma=1, dtype=torch.float32, device='cpu'):
"""Generate 2D gaussian kernel.
Args:
radius (int): Radius of gaussian kernel.
sigma (int): Sigma of gaussian function. Default: 1.
dtype (torch.dtype): Dtype of gaussian tensor. De... | 5,784 | 30.102151 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/utils/res_layer.py | from mmcv.cnn import build_conv_layer, build_norm_layer
from torch import nn as nn
class ResLayer(nn.Sequential):
"""ResLayer to build ResNet style backbone.
Args:
block (nn.Module): block used to build ResLayer.
inplanes (int): inplanes of block.
planes (int): planes of block.
... | 6,261 | 32.308511 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/utils/transformer.py | import torch
import torch.nn as nn
from mmcv.cnn import (Linear, build_activation_layer, build_norm_layer,
xavier_init)
from .builder import TRANSFORMER
class MultiheadAttention(nn.Module):
"""A warpper for torch.nn.MultiheadAttention.
This module implements MultiheadAttention with res... | 36,776 | 41.714286 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/utils/positional_encoding.py | import math
import torch
import torch.nn as nn
from mmcv.cnn import uniform_init
from .builder import POSITIONAL_ENCODING
@POSITIONAL_ENCODING.register_module()
class SinePositionalEncoding(nn.Module):
"""Position encoding with sine and cosine functions.
See `End-to-End Object Detection with Transformers
... | 5,800 | 37.417219 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/standard_roi_head.py | 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()
class StandardRoIHead(BaseRoIHead, BBoxTestMixin,... | 12,334 | 40.672297 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/grid_roi_head.py | 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 for Grid R-CNN.
https://arxiv.org/abs/1811.12030
"""
de... | 7,100 | 39.118644 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/scnet_roi_head.py | 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 .cascade_roi_head import CascadeRoIHead
@HEADS.register_module()
class... | 24,292 | 40.668954 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/sparse_roi_head.py | 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(CascadeRoIHead):
r"""The RoIHead for `Sparse R-CNN: End-to-End Ob... | 14,207 | 44.538462 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/cascade_roi_head.py | import torch
import torch.nn as nn
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multiclass_nms)
from ..builder import HEADS, build_head, build_roi_extractor
from .base_roi_head import BaseR... | 22,053 | 42.413386 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/trident_roi_head.py | 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.register_module()
class TridentRoIHead(StandardR... | 5,273 | 42.95 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/dynamic_roi_head.py | 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):
"""RoI head for `Dynamic R-CNN <https://arxiv.org/ab... | 6,606 | 41.625806 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/point_rend_roi_head.py | # Modified from https://github.com/facebookresearch/detectron2/tree/master/projects/PointRend # noqa
import torch
import torch.nn.functional as F
from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
from mmdet.core import bbox2roi, bbox_mapping, merge_aug_masks
from .. import builder
from ..builder impo... | 10,311 | 46.086758 | 101 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/base_roi_head.py | from abc import ABCMeta, abstractmethod
import torch.nn as nn
from ..builder import build_shared_head
class BaseRoIHead(nn.Module, metaclass=ABCMeta):
"""Base class for RoIHeads."""
def __init__(self,
bbox_roi_extractor=None,
bbox_head=None,
mask_roi_extra... | 3,021 | 28.057692 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_scoring_roi_head.py | 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.org/abs/1903.00241
"""
def __init__(se... | 5,503 | 43.747967 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/htc_roi_head.py | 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 .cascade_roi_head import CascadeRoIHead
@HEADS.register_module()
class... | 25,900 | 42.9 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/test_mixins.py | import logging
import sys
import torch
from mmdet.core import (bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, multiclass_nms)
logger = logging.getLogger(__name__)
if sys.version_info >= (3, 7):
from mmdet.utils.contextmanagers import completed
class BBoxTestMixin(object):
... | 15,155 | 42.426934 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/roi_extractors/base_roi_extractor.py | from abc import ABCMeta, abstractmethod
import torch
import torch.nn as nn
from mmcv import ops
class BaseRoIExtractor(nn.Module, metaclass=ABCMeta):
"""Base class for RoI extractor.
Args:
roi_layer (dict): Specify RoI layer type and arguments.
out_channels (int): Output channels of RoI laye... | 2,772 | 32.011905 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/roi_extractors/single_level_roi_extractor.py | 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 level feature map.
If there are multiple input ... | 4,465 | 39.972477 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/bbox_heads/bbox_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.runner import 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 HEADS, build_loss
from mmdet.models.losses import accuracy
@H... | 21,344 | 43.10124 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/bbox_heads/sabl_head.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule, kaiming_init, normal_init, xavier_init
from mmcv.runner import force_fp32
from mmdet.core import build_bbox_coder, multi_apply, multiclass_nms
from mmdet.models.builder import HEADS, build_loss
from m... | 24,584 | 41.905759 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/bbox_heads/dii_head.py | import torch
import torch.nn as nn
from mmcv.cnn import (bias_init_with_prob, build_activation_layer,
build_norm_layer)
from mmcv.runner import auto_fp16, force_fp32
from mmdet.core import multi_apply
from mmdet.models.builder import HEADS, build_loss
from mmdet.models.dense_heads.atss_head impor... | 18,681 | 43.908654 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/bbox_heads/convfc_bbox_head.py | import torch.nn as nn
from mmcv.cnn import ConvModule
from mmdet.models.builder import HEADS
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.
.. code-block:: none
... | 7,436 | 35.101942 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/bbox_heads/double_bbox_head.py | import torch.nn as nn
from mmcv.cnn import ConvModule, normal_init, xavier_init
from mmdet.models.backbones.resnet import Bottleneck
from mmdet.models.builder import HEADS
from .bbox_head import BBoxHead
class BasicResBlock(nn.Module):
"""Basic residual block.
This block is a little different from the block... | 5,380 | 30.104046 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/shared_heads/res_layer.py | import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import auto_fp16, load_checkpoint
from mmdet.models.backbones import ResNet
from mmdet.models.builder import SHARED_HEADS
from mmdet.models.utils import ResLayer as _ResLayer
from mmdet.utils import get_root_logger
@SHARED_HEADS.... | 2,454 | 30.474359 | 74 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/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 ConvModule, kaiming_init, normal_init
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class GridHead(nn.Module):
def __init__(self,
grid_points=9,
... | 15,432 | 41.869444 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/coarse_mask_head.py | import torch.nn as nn
from mmcv.cnn import ConvModule, Linear, constant_init, xavier_init
from mmcv.runner import auto_fp16
from mmdet.models.builder import HEADS
from .fcn_mask_head import FCNMaskHead
@HEADS.register_module()
class CoarseMaskHead(FCNMaskHead):
"""Coarse mask head used in PointRend.
Compare... | 3,233 | 34.152174 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/maskiou_head.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import Conv2d, Linear, MaxPool2d, kaiming_init, normal_init
from mmcv.runner import force_fp32
from torch.nn.modules.utils import _pair
from mmdet.models.builder import HEADS, build_loss
@HEADS.register_module()
class MaskIoUHead(nn.Module):
"""... | 7,332 | 38.213904 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/feature_relay_head.py | import torch.nn as nn
from mmcv.cnn import kaiming_init
from mmcv.runner import auto_fp16
from mmdet.models.builder import HEADS
@HEADS.register_module()
class FeatureRelayHead(nn.Module):
"""Feature Relay Head used in `SCNet <https://arxiv.org/abs/2012.10150>`_.
Args:
in_channels (int, optional): n... | 1,854 | 32.125 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/global_context_head.py | import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.runner import auto_fp16, force_fp32
from mmdet.models.builder import HEADS
from mmdet.models.utils import ResLayer, SimplifiedBasicBlock
@HEADS.register_module()
class GlobalContextHead(nn.Module):
"""Global context head used in `SCNet <https://arxi... | 3,685 | 34.786408 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/fcn_mask_head.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import Conv2d, ConvModule, build_upsample_layer
from mmcv.ops.carafe import CARAFEPack
from mmcv.runner import auto_fp16, force_fp32
from torch.nn.modules.utils import _pair
from mmdet.core import mask_target
from mmdet... | 15,621 | 40.328042 | 85 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/fused_semantic_head.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule, kaiming_init
from mmcv.runner import auto_fp16, force_fp32
from mmdet.models.builder import HEADS
@HEADS.register_module()
class FusedSemanticHead(nn.Module):
r"""Multi-level fused semantic segmentation head.
.. code-bloc... | 3,610 | 32.435185 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/mask_point_head.py | # 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, normal_init
from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
from mmdet.models.builder import HEADS, build... | 13,190 | 42.82392 | 126 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/roi_heads/mask_heads/condconv_mask_head.py | from typing import Dict
import math
import torch
from torch import nn
import torch.functional as F
from mmcv.cnn import ConvModule
from functools import partial
from mmdet.models.builder import HEADS, build_loss
from mmdet.utils.common import compute_locations
import torch.nn.functional as F
INF = 100000000
@HEAD... | 20,312 | 38.214286 | 157 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/ghm_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
def _expand_onehot_labels(labels, label_weights, label_channels):
bin_labels = labels.new_full((labels.size(0), label_channels), 0)
inds = torch.nonzero(
(labels >= 0) & (labels < label_channels), as_tuple... | 6,365 | 35.797688 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/mse_loss.py | 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):
"""Warpper of mse loss."""
return F.mse_loss(pred, target, reduction='none')
@LOSSES.register_module()
class MSELoss(nn.Module):
"""MSELoss.
... | 1,463 | 28.28 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/pisa_loss.py | 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,
bias=0,
num_class=80):
"... | 7,168 | 37.961957 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/balanced_l1_loss.py | 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,
alpha=0.5,
... | 4,168 | 33.454545 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/iou_loss.py | import math
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, eps=1e-6):
"""IoU loss.
Computing the IoU loss betwee... | 16,776 | 31.201536 | 89 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/smooth_l1_loss.py | 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): The prediction.
target (torch.Tensor):... | 4,515 | 31.257143 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/gfocal_loss.py | import mmcv
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .utils import weighted_loss
from mmdet.core import bbox_overlaps
@mmcv.jit(derivate=True, coderize=True)
@weighted_loss
def quality_focal_loss(pred, target, beta=2.0, background_label=None):
r"""Quality Focal Loss... | 10,789 | 38.236364 | 90 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/varifocal_loss.py | 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,
alpha=0.75,
gamma=2.0,... | 5,317 | 38.686567 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/utils.py | import functools
import mmcv
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.
"""
reduc... | 3,055 | 29.257426 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/ae_loss.py | 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 Embedding Loss including two parts: pull loss and push... | 3,809 | 35.990291 | 143 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/accuracy.py | 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)
target (torch.Tensor): The target of each prediction,... | 2,942 | 36.253165 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/focal_loss.py | 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,
target,
... | 9,482 | 37.706122 | 86 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/cross_entropy_loss.py | 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',
avg_factor=None,
class_weight=N... | 7,910 | 35.795349 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/gaussian_focal_loss.py | 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.02002>`_ for targets in gaussian
distribution... | 3,264 | 34.48913 | 108 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/losses/kd_loss.py | 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,
soft_label,
... | 2,864 | 31.556818 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/hrnet.py | import torch.nn as nn
from mmcv.cnn import (build_conv_layer, build_norm_layer, 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 ..builder import BACKBONES
from .resnet import BasicB... | 20,358 | 36.842007 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/regnet.py | 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 backbone.
More details can be found in `paper <https://arxi... | 12,271 | 36.644172 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/trident_resnet.py | 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, kaiming_init
from torch.nn.modules.utils import _pair
from mmdet.models.backbones.resnet import Bottleneck, ResNet
from mmdet.models.builder import BACKBONES
... | 10,863 | 36.078498 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/detectors_resnext.py | 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__(self,
inplanes,
... | 3,872 | 30.487805 | 77 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/swin_transformer.py | # --------------------------------------------------------
# Swin Transformer
# Copyright (c) 2021 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ze Liu, Yutong Lin, Yixuan Wei
# --------------------------------------------------------
import torch
import torch.nn as nn
import torch.... | 24,552 | 37.911252 | 123 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/resnet.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import (build_conv_layer, build_norm_layer, build_plugin_layer,
constant_init, kaiming_init)
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.utils import get_root_logger
fr... | 23,377 | 34.207831 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/detectors_resnet.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import build_conv_layer, build_norm_layer, constant_init
from ..builder import BACKBONES
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet
class Bottleneck(_Bottleneck):
r"""Bottleneck for the ResNet backbone in `Detec... | 10,517 | 33.372549 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-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 ..builder import BACKBONES
@BACKBONES.register_module()
class SSDVGG(VGG):
"""VGG... | 5,882 | 33.605882 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/resnext.py | 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__(self,
inplanes,
... | 5,664 | 35.785714 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/resnest.py | 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 ..builder import BACKBONES
from ..utils import ResLayer
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNetV1d
class RS... | 10,352 | 31.556604 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/hourglass.py | import torch.nn as nn
from mmcv.cnn import ConvModule
from ..builder import BACKBONES
from ..utils import ResLayer
from .resnet import BasicBlock
class HourglassModule(nn.Module):
"""Hourglass Module for HourglassNet backbone.
Generate module recursively and use BasicBlock as the base unit.
Args:
... | 6,452 | 31.427136 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/res2net.py | 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, constant_init,
kaiming_init)
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.utils import get_root_log... | 12,675 | 35.011364 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/models/backbones/darknet.py | # Copyright (c) 2019 Western Digital Corporation or its affiliates.
import logging
import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from ..builder import BACKBONES
class ResBlock(nn.Module):
... | 7,574 | 36.875 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/datasets/custom.py | import os.path as osp
import warnings
from collections import OrderedDict
import mmcv
import numpy as np
from mmcv.utils import print_log
from torch.utils.data import Dataset
from mmdet.core import eval_map, eval_recalls
from .builder import DATASETS
from .pipelines import Compose
@DATASETS.register_module()
class ... | 11,581 | 34.746914 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/datasets/dataset_wrappers.py | import bisect
import math
from collections import defaultdict
import numpy as np
from mmcv.utils import print_log
from torch.utils.data.dataset import ConcatDataset as _ConcatDataset
from .builder import DATASETS
from .coco import CocoDataset
@DATASETS.register_module()
class ConcatDataset(_ConcatDataset):
"""A... | 11,088 | 38.183746 | 167 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/datasets/builder.py | import copy
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 mmcv.utils import Registry, build_from_cfg
from torch.utils.data import DataLoader
from .samplers import DistributedGroupSampler, DistributedSampler, ... | 5,284 | 35.701389 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/datasets/samplers/group_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 Sampler
class GroupSampler(Sampler):
def __init__(self, dataset, samples_per_gpu=1):
assert hasattr(dataset, 'flag')
self.dataset = dataset
self.... | 5,368 | 35.033557 | 78 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/datasets/samplers/distributed_sampler.py | import math
import torch
from torch.utils.data import DistributedSampler as _DistributedSampler
class DistributedSampler(_DistributedSampler):
def __init__(self,
dataset,
num_replicas=None,
rank=None,
shuffle=True,
seed=0):
... | 1,310 | 31.775 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-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 ..builder import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported types are: :class:`numpy.ndarray`, :class:`torch.T... | 15,424 | 33.126106 | 92 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-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,077 | 32.42623 | 79 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/utils/instances.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import itertools
from typing import Any, Dict, List, Tuple, Union
import torch
class Instances:
"""
This class represents a list of instances in an image.
It stores the attributes of instances (e.g., boxes, masks, labels, scores) as "f... | 6,207 | 32.376344 | 100 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-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,288 | 31.225 | 73 | py |
Swin-Transformer-Object-Detection | Swin-Transformer-Object-Detection-master/mmdet/utils/common.py | import torch
def compute_locations(h, w, stride, device):
shifts_x = torch.arange(
0, w * stride, step=stride,
dtype=torch.float32, device=device
)
shifts_y = torch.arange(
0, h * stride, step=stride,
dtype=torch.float32, device=device
)
shift_y, shift_x = torch.meshg... | 502 | 30.4375 | 68 | py |
pytorch_influence_functions | pytorch_influence_functions-master/setup.py | import setuptools
from pathlib import Path
this_dir = Path(__file__).resolve().parent
with open(this_dir / 'README.md', "r", encoding='utf-8') as fh:
long_description = fh.read()
setuptools.setup(
name="pytorch_influence_functions",
version="0.1.1",
author="Nimar Blume",
author_email="l.nimar.b@gm... | 1,469 | 38.72973 | 250 | py |
pytorch_influence_functions | pytorch_influence_functions-master/examples/test_influence_functions.py | #! /usr/bin/env python3
import pytorch_influence_functions as ptif
from train_influence_functions import load_model, load_data
if __name__ == "__main__":
config = ptif.get_default_config()
model = load_model()
trainloader, testloader = load_data()
ptif.init_logging('logfile.log')
ptif.calc_img_wis... | 362 | 29.25 | 62 | py |
pytorch_influence_functions | pytorch_influence_functions-master/examples/train_influence_functions.py | #! /usr/bin/env python3
import torch
import torchvision
import torchvision.transforms as transforms
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
# Source: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html
# Last access: 2019-11-20
def load_data():
transform ... | 4,189 | 30.984733 | 79 | py |
pytorch_influence_functions | pytorch_influence_functions-master/pytorch_influence_functions/influence_function.py | #! /usr/bin/env python3
import torch
from torch.autograd import grad
from pytorch_influence_functions.utils import display_progress
def s_test(z_test, t_test, model, z_loader, gpu=-1, damp=0.01, scale=25.0,
recursion_depth=5000):
"""s_test can be precomputed for each test point of interest, and then
... | 4,917 | 35.42963 | 79 | py |
pytorch_influence_functions | pytorch_influence_functions-master/pytorch_influence_functions/calc_influence_function.py | #! /usr/bin/env python3
import torch
import time
import datetime
import numpy as np
import copy
import logging
from pathlib import Path
from pytorch_influence_functions.influence_function import s_test, grad_z
from pytorch_influence_functions.utils import save_json, display_progress
def calc_s_test(model, test_load... | 22,850 | 41.316667 | 79 | py |
UMR | UMR-master/external/SoftRas/setup.py | from setuptools import setup, find_packages
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
CUDA_FLAGS = []
ext_modules=[
CUDAExtension('soft_renderer.cuda.load_textures', [
'soft_renderer/cuda/load_textures_cuda.cpp',
'soft_renderer/cuda/load_textures_cuda_kernel.cu',
... | 1,400 | 34.025 | 91 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/renderer.py |
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy
import soft_renderer as sr
class Renderer(nn.Module):
def __init__(self, image_size=256, background_color=[0,0,0], near=1, far=100,
anti_aliasing=True, fill_back=True, eps=1e-6,
camera... | 4,366 | 41.813725 | 91 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/losses.py | import torch
import torch.nn as nn
import numpy as np
class LaplacianLoss(nn.Module):
def __init__(self, vertex, faces, average=False):
super(LaplacianLoss, self).__init__()
self.nv = vertex.size(0)
self.nf = faces.size(0)
self.average = average
laplacian = np.zeros([self.n... | 3,795 | 32.298246 | 113 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/rasterizer.py |
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import soft_renderer.functional as srf
class SoftRasterizer(nn.Module):
def __init__(self, image_size=256, background_color=[0, 0, 0], near=1, far=100,
anti_aliasing=False, fill_back=False, eps=1e-3,
... | 2,414 | 42.125 | 104 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/transform.py |
import math
import numpy as np
import torch
import torch.nn as nn
import soft_renderer.functional as srf
class Projection(nn.Module):
def __init__(self, P, dist_coeffs=None, orig_size=512):
super(Projection, self).__init__()
self.P = P
self.dist_coeffs = dist_coeffs
self.orig_siz... | 3,998 | 36.373832 | 114 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/lighting.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import soft_renderer.functional as srf
class AmbientLighting(nn.Module):
def __init__(self, light_intensity=0.5, light_color=(1,1,1)):
super(AmbientLighting, self).__init__()
self.light_intensity = light_intens... | 2,622 | 38.149254 | 90 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/mesh.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import soft_renderer.functional as srf
class Mesh(object):
'''
A simple class for creating and manipulating trimesh objects
'''
def __init__(self, vertices, faces, textures=None, texture_res=1, texture_type='surface... | 6,884 | 37.463687 | 116 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/soft_rasterize.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Function
import numpy as np
import soft_renderer.cuda.soft_rasterize as soft_rasterize_cuda
class SoftRasterizeFunction(Function):
@staticmethod
def forward(ctx, face_vertices, textures, image_size=256,
... | 6,172 | 47.992063 | 136 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/vertex_normals.py | import torch
import torch.nn.functional as F
def vertex_normals(vertices, faces):
"""
:param vertices: [batch size, number of vertices, 3]
:param faces: [batch size, number of faces, 3]
:return: [batch size, number of vertices, 3]
"""
assert (vertices.ndimension() == 3)
assert (faces.ndimen... | 1,543 | 39.631579 | 125 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/voxelization.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Function
import soft_renderer.cuda.voxelization as voxelization_cuda
def voxelize_sub1(faces, size, dim):
bs = faces.size(0)
nf = faces.size(1)
if dim == 0:
faces = faces[:, :, :, [2, 1, 0]].contiguous()... | 1,694 | 26.33871 | 83 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/ambient_lighting.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
def ambient_lighting(light, light_intensity=0.5, light_color=(1,1,1)):
device = light.device
if isinstance(light_color, tuple) or isinstance(light_color, list):
light_color = torch.tensor(light_color, dtype=torch.fl... | 625 | 31.947368 | 83 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/save_obj.py | import os
import torch
from skimage.io import imsave
import soft_renderer.cuda.create_texture_image as create_texture_image_cuda
def create_texture_image(textures, texture_res=16):
num_faces = textures.shape[0]
tile_width = int((num_faces - 1.) ** 0.5) + 1
tile_height = int((num_faces - 1.) / tile_width... | 4,122 | 38.266667 | 99 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/perspective.py | import math
import torch
def perspective(vertices, angle=30.):
'''
Compute perspective distortion from a given angle
'''
if (vertices.ndimension() != 3):
raise ValueError('vertices Tensor should have 3 dimensions')
device = vertices.device
angle = torch.tensor(angle / 180 * math.pi, dt... | 600 | 27.619048 | 83 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/directional_lighting.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
def directional_lighting(light, normals, light_intensity=0.5, light_color=(1,1,1),
light_direction=(0,1,0)):
# normals: [nb, :, 3]
device = light.device
if isinstance(light_color, tuple) or is... | 1,210 | 42.25 | 91 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/face_vertices.py | import torch
def face_vertices(vertices, faces):
"""
:param vertices: [batch size, number of vertices, 3]
:param faces: [batch size, number of faces, 3]
:return: [batch size, number of faces, 3, 3]
"""
assert (vertices.ndimension() == 3)
assert (faces.ndimension() == 3)
assert (vertice... | 742 | 31.304348 | 88 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/get_points_from_angles.py | import math
import torch
def get_points_from_angles(distance, elevation, azimuth, degrees=True):
if isinstance(distance, float) or isinstance(distance, int):
if degrees:
elevation = math.radians(elevation)
azimuth = math.radians(azimuth)
return (
distance * math... | 836 | 33.875 | 71 | py |
UMR | UMR-master/external/SoftRas/soft_renderer/functional/load_obj.py | import os
import torch
import numpy as np
from skimage.io import imread
import soft_renderer.cuda.load_textures as load_textures_cuda
def load_mtl(filename_mtl):
'''
load color (Kd) and filename of textures from *.mtl
'''
texture_filenames = {}
colors = {}
material_name = ''
with open(fil... | 5,923 | 34.261905 | 107 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.