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 |
|---|---|---|---|---|---|---|
AlignShift | AlignShift-master/nn/converter.py |
import torch.nn as nn
import functools
import torch
from ..utiles import _triple_same
from collections import OrderedDict
#TODO #1#通过名字来跳过相应的层。
#2#2d weighjts 转3d weights
#3# sycnb
class Converter():
"""
Decorator class for converting 2d convolution modules
to corresponding conv version in an... | 7,688 | 45.319277 | 185 | py |
AlignShift | AlignShift-master/nn/models/truncated_densenet3d_alignshift.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import model_urls
import math
import torch.utils.model_zoo as model_zoo
import ... | 10,288 | 42.413502 | 140 | py |
AlignShift | AlignShift-master/nn/models/truncated_densenet3d_a3d.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import model_urls
import math
import torch.utils.model_zoo as model_zoo
import ... | 9,821 | 41.154506 | 128 | py |
AlignShift | AlignShift-master/nn/models/truncated_densenet3d_tsm.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import model_urls
import math
import torch.utils.model_zoo as model_zoo
import ... | 9,413 | 41.026786 | 120 | py |
AlignShift | AlignShift-master/nn/operators/tsmconv.py | import torch
from torch.nn.modules.conv import _ConvNd
from torch.nn import functional as F
import numpy as np
from ..utiles import as_triple, _pair_same
class TSMConv(_ConvNd):
'''
Args:
n_fold (int): Divisor of channels to shift.
tsm(bool) : if apply tsm operation before conv
inplac... | 3,243 | 32.791667 | 86 | py |
AlignShift | AlignShift-master/nn/operators/a3dconv.py | import torch
from torch.nn.modules.conv import _ConvNd
from torch.nn import functional as F
from torch.nn import init
import numpy as np
from ..utiles import as_triple, _pair_same
from torch.nn.parameter import Parameter
class A3DConv(_ConvNd):
'''
Args:
dimension (int): number of dimensions to shift... | 3,716 | 35.441176 | 105 | py |
AlignShift | AlignShift-master/nn/operators/alignshiftconv.py | import torch
from torch.nn.modules.conv import _ConvNd
from torch.nn import functional as F
import numpy as np
from ..utiles import as_triple, _pair_same
class AlignShiftConv(_ConvNd):
'''
Args:
n_fold (int): Divisor of channels to shift.
alignshift(bool): if apply alignshift operation before... | 5,671 | 48.321739 | 150 | py |
AlignShift | AlignShift-master/deeplesion/train_dist.py |
from __future__ import division
import argparse
import sys
#sys.path.append('add your worck space here')
import os
import torch
torch.multiprocessing.set_sharing_strategy('file_system')
from mmcv import Config
from mmdet import __version__
from mmdet.apis import (get_root_logger, init_dist, set_random_seed,
... | 4,031 | 32.04918 | 77 | py |
AlignShift | AlignShift-master/deeplesion/eval.py | import torch
torch.multiprocessing.set_sharing_strategy('file_system')
import numpy as np
from pycocotools import mask as mutils
import sys
# sys.path.append('/your alignshit path')
import os
# from dataset import DeepLesionDataset
import cv2
import random
import matplotlib.pyplot as plt
from mmcv import Config
import ... | 8,161 | 37.866667 | 156 | py |
AlignShift | AlignShift-master/deeplesion/evaluation/evaluation_metrics.py | import numpy as np
from scipy import interpolate
import torch
def recall(pred, target):
pred_label = pred.detach().clone()
pred_label[pred_label>=0] = 1
pred_label[pred_label<0] = 0
pred_label = pred_label.flatten()
correct = pred_label.eq(target) * target
return correct.sum().to(torch.float... | 3,239 | 32.402062 | 106 | py |
AlignShift | AlignShift-master/deeplesion/evaluation/evaluation.py | from mmdet.core.evaluation.eval_hooks import DistEvalHook
from deeplesion.evaluation.evaluation_metrics import sens_at_FP
import numpy as np
import torch.distributed as dist
from mmcv.parallel import collate, scatter
from mmcv.runner import Hook
from torch.utils.data import Dataset
from mmdet import datasets
import mmc... | 3,745 | 36.089109 | 124 | py |
AlignShift | AlignShift-master/deeplesion/dataset/DeepLesionDataset_25d.py | import numpy as np
import os
import csv
import cv2
import logging
from pycocotools import mask as mutils
from mmcv import Config
import torch
import os
from mmdet.datasets.registry import DATASETS
import pickle
from mmdet.datasets.pipelines import Compose
from mmdet.datasets.custom import CustomDataset
@DATASETS.regi... | 10,139 | 34.208333 | 125 | py |
AlignShift | AlignShift-master/deeplesion/dataset/DeepLesionDataset_align.py | import numpy as np
import os
import csv
import cv2
import logging
from pycocotools import mask as mutils
from mmcv import Config
import torch
import os
from mmdet.datasets.registry import DATASETS
import pickle
from mmdet.datasets.pipelines import Compose
from mmdet.datasets.custom import CustomDataset
@DATASETS.regi... | 9,694 | 34.126812 | 125 | py |
AlignShift | AlignShift-master/deeplesion/dataset/DeepLesionDataset_tsm.py | '''
Copyright Apache-
borrow from
'''
import numpy as np
import os
import csv
import cv2
import logging
from pycocotools import mask as mutils
from mmcv import Config
import torch
import os
from mmdet.datasets.registry import DATASETS
import pickle
from mmdet.datasets.pipelines import Compose
from mmdet.datasets.c... | 11,411 | 34.774295 | 125 | py |
AlignShift | AlignShift-master/deeplesion/dataset/DeepLesionDataset_a3d.py | import numpy as np
import os
import csv
import cv2
import logging
from pycocotools import mask as mutils
from mmcv import Config
import torch
import os
from mmdet.datasets.registry import DATASETS
import pickle
from mmdet.datasets.pipelines import Compose
from mmdet.datasets.custom import CustomDataset
@DATASETS.regi... | 12,082 | 36.641745 | 125 | py |
AlignShift | AlignShift-master/deeplesion/models/truncated_densenet3d_alignshift.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import model_urls
import math
import torch.utils.model_zoo as model_zoo
import ... | 10,288 | 42.413502 | 140 | py |
AlignShift | AlignShift-master/deeplesion/models/truncated_densenet.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import _DenseBlock, _Transition, model_urls
import math
import torch.utils.mode... | 5,125 | 37.833333 | 114 | py |
AlignShift | AlignShift-master/deeplesion/models/detector.py | from mmdet.models.registry import DETECTORS
from mmdet.models.detectors.two_stage import TwoStageDetector
import torch
import torch.nn as nn
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler, auto_fp16
from mmdet.models import builder
from mmdet.models.detectors.base import BaseDetector
from... | 10,742 | 41.295276 | 128 | py |
AlignShift | AlignShift-master/deeplesion/models/truncated_densenet3d_tsm.py | # Ke Yan, Imaging Biomarkers and Computer-Aided Diagnosis Laboratory,
from collections import namedtuple
import torch
import torch.nn.functional as F
from torch import nn
import torchvision.models as models
from torchvision.models.densenet import model_urls
import math
import torch.utils.model_zoo as model_zoo
import ... | 9,413 | 41.026786 | 120 | py |
AlignShift | AlignShift-master/deeplesion/losses/diceloss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmdet.models.registry import LOSSES
def dice_loss(input, target):
smooth = 0.01
input = input.sigmoid()
# intersection = ((input * target).sum(dim=(1,2)))#减少一个中间变量 是否可以减少内存#hyadd
dice = ((2. * ((input * target).sum(dim=(1,2))) + sm... | 2,058 | 33.316667 | 79 | py |
AlignShift | AlignShift-master/mmdet/apis/inference.py | import warnings
import matplotlib.pyplot as plt
import mmcv
import numpy as np
import pycocotools.mask as maskUtils
import torch
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint
from mmdet.core import get_classes
from mmdet.datasets.pipelines import Compose
from mmdet.models import b... | 5,973 | 33.732558 | 79 | py |
AlignShift | AlignShift-master/mmdet/apis/train.py | from __future__ import division
import re
from collections import OrderedDict
import torch
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import DistSamplerSeedHook, Runner, obj_from_dict
from mmdet import datasets
from mmdet.core import (CocoDistEvalmAPHook, CocoDistEvalRecallHo... | 9,499 | 38.256198 | 78 | py |
AlignShift | AlignShift-master/mmdet/apis/env.py | import logging
import os
import random
import subprocess
import numpy as np
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from mmcv.runner import get_dist_info
def init_dist(launcher, backend='nccl', **kwargs):
if mp.get_start_method(allow_none=True) is None:
mp.set_sta... | 2,041 | 28.171429 | 70 | py |
AlignShift | AlignShift-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.parallel import collate, scatter
from mmcv.runner import Hook
from pycocotools.cocoeval import COCOeval
from torch.utils.data import Dataset
from mmdet import datasets
from .coco_utils import fast_ev... | 6,301 | 35.853801 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/post_processing/merge_augs.py | import numpy as np
import torch
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
schem... | 3,573 | 34.039216 | 78 | py |
AlignShift | AlignShift-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,451 | 35.597015 | 78 | py |
AlignShift | AlignShift-master/mmdet/core/mask/mask_target.py | import mmcv
import numpy as np
import torch
from torch.nn.modules.utils import _pair
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,
... | 1,700 | 39.5 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/fp16/hooks.py | import copy
import torch
import torch.nn as nn
from mmcv.runner import OptimizerHook
from ..utils.dist_utils import allreduce_grads
from .utils import cast_tensor_type
class Fp16OptimizerHook(OptimizerHook):
"""FP16 optimizer hook.
The steps of fp16 optimizer is as follows.
1. Scale the loss value.
... | 5,828 | 36.606452 | 83 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/core/bbox/bbox_target.py | import torch
from ..utils import multi_apply
from .transforms import bbox2delta
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,717 | 35.72973 | 78 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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.... | 7,887 | 33.902655 | 79 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/core/bbox/assigners/point_assigner.py | import torch
from .assign_result import AssignResult
from .base_assigner import BaseAssigner
class PointAssigner(BaseAssigner):
"""Assign a corresponding gt bbox or background to each point.
Each proposals will be assigned with `0`, or a positive integer
indicating the ground truth index.
- 0: nega... | 5,183 | 43.307692 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/bbox/assigners/approx_max_iou_assigner.py | import torch
from ..geometry import bbox_overlaps
from .max_iou_assigner import MaxIoUAssigner
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... | 5,910 | 42.463235 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/bbox/assigners/max_iou_assigner.py | import torch
from ..geometry import bbox_overlaps
from .assign_result import AssignResult
from .base_assigner import BaseAssigner
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... | 7,657 | 42.76 | 79 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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,806 | 34.531646 | 88 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/core/bbox/samplers/ohem_sampler.py | import torch
from ..transforms import bbox2roi
from .base_sampler import BaseSampler
class OHEMSampler(BaseSampler):
"""
Online Hard Example Mining Sampler described in [1]_.
References:
.. [1] https://arxiv.org/pdf/1604.03540.pdf
"""
def __init__(self,
num,
... | 2,912 | 35.4125 | 77 | py |
AlignShift | AlignShift-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,956 | 42.801471 | 79 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/core/utils/dist_utils.py | from collections import OrderedDict
import torch.distributed as dist
from mmcv.runner import OptimizerHook
from torch._utils import (_flatten_dense_tensors, _take_tensors,
_unflatten_dense_tensors)
def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1):
if bucket_size_mb > 0:
... | 1,967 | 32.355932 | 73 | py |
AlignShift | AlignShift-master/mmdet/core/anchor/anchor_target.py | import torch
from ..bbox import PseudoSampler, assign_and_sample, bbox2delta, build_assigner
from ..utils import multi_apply
def anchor_target(anchor_list,
valid_flag_list,
gt_bboxes_list,
img_metas,
target_means,
target_stds,
... | 7,318 | 37.724868 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/anchor/guided_anchor_target.py | import torch
from ..bbox import PseudoSampler, build_assigner, build_sampler
from ..utils import multi_apply, unmap
def calc_region(bbox, ratio, featmap_size=None):
"""Calculate a proportional bbox region.
The bbox center are fixed and the new h' and w' is h * ratio and w * ratio.
Args:
bbox (T... | 11,809 | 40.006944 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/anchor/point_generator.py | import torch
class PointGenerator(object):
def _meshgrid(self, x, y, row_major=True):
xx = x.repeat(len(y))
yy = y.view(-1, 1).repeat(1, len(x)).view(-1)
if row_major:
return xx, yy
else:
return yy, xx
def grid_points(self, featmap_size, stride=16, dev... | 1,287 | 35.8 | 71 | py |
AlignShift | AlignShift-master/mmdet/core/anchor/anchor_generator.py | import torch
class AnchorGenerator(object):
"""
Examples:
>>> from mmdet.core import AnchorGenerator
>>> self = AnchorGenerator(9, [1.], [1.])
>>> all_anchors = self.grid_anchors((2, 2), device='cpu')
>>> print(all_anchors)
tensor([[ 0., 0., 8., 8.],
... | 3,599 | 35.363636 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/anchor/point_target.py | import torch
from ..bbox import PseudoSampler, assign_and_sample, build_assigner
from ..utils import multi_apply
def point_target(proposals_list,
valid_flag_list,
gt_bboxes_list,
img_metas,
cfg,
gt_bboxes_ignore_list=None,
... | 6,441 | 37.807229 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/builder.py | from torch import nn
from mmdet.utils import build_from_cfg
from .registry import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,
ROI_EXTRACTORS, SHARED_HEADS)
def build(cfg, registry, default_args=None):
if isinstance(cfg, list):
modules = [
build_from_cfg(cfg_, registry,... | 959 | 20.818182 | 78 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/two_stage.py | import torch
import torch.nn as nn
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .base import BaseDetector
from .test_mixins import BBoxTestMixin, MaskTestMixin, RPNTestMixin
@DETECTORS.register_module
class TwoStageDetector(B... | 24,777 | 41.64716 | 126 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/base.py | import logging
from abc import ABCMeta, abstractmethod
import mmcv
import numpy as np
import pycocotools.mask as maskUtils
import torch.nn as nn
from mmdet.core import auto_fp16, get_classes, tensor2imgs
class BaseDetector(nn.Module):
"""Base class for detectors"""
__metaclass__ = ABCMeta
def __init__... | 6,397 | 35.352273 | 131 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/single_stage.py | import torch.nn as nn
from mmdet.core import bbox2result
from .. import builder
from ..registry import DETECTORS
from .base import BaseDetector
import numpy as np
@DETECTORS.register_module
class SingleStageDetector(BaseDetector):
"""Base class for single-stage detectors.
Single-stage detectors directly and ... | 4,032 | 34.690265 | 108 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/reppoints_detector.py | import torch
from mmdet.core import bbox2result, bbox_mapping_back, multiclass_nms
from ..registry import DETECTORS
from .single_stage import SingleStageDetector
@DETECTORS.register_module
class RepPointsDetector(SingleStageDetector):
"""RepPoints: Point Set Representation for Object Detection.
This det... | 3,089 | 36.682927 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/cascade_rcnn.py | from __future__ import division
import torch
import torch.nn as nn
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multiclass_nms)
from .. import builder
from ..registry import DETECTORS
from... | 23,674 | 41.276786 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/grid_rcnn.py | import torch
from mmdet.core import bbox2result, bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class GridRCNN(TwoStageDetector):
"""Grid R-CNN.
This detector is the implementation of:
- G... | 9,225 | 39.113043 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/double_head_rcnn.py | import torch
from mmdet.core import bbox2roi, build_assigner, build_sampler
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class DoubleHeadRCNN(TwoStageDetector):
def __init__(self, reg_roi_scale_factor, **kwargs):
super().__init__(**kwargs)
s... | 7,453 | 40.642458 | 77 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/htc.py | import torch
import torch.nn.functional as F
from mmdet.core import (bbox2result, bbox2roi, bbox_mapping, build_assigner,
build_sampler, merge_aug_bboxes, merge_aug_masks,
multiclass_nms)
from .. import builder
from ..registry import DETECTORS
from .cascade_rcnn import C... | 24,580 | 43.210432 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/mask_scoring_rcnn.py | import torch
from mmdet.core import bbox2roi, build_assigner, build_sampler
from .. import builder
from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class MaskScoringRCNN(TwoStageDetector):
"""Mask Scoring RCNN.
https://arxiv.org/abs/1903.00241
"""
... | 8,580 | 41.691542 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/test_mixins.py | import torch
from mmdet.core import (bbox2roi, bbox_mapping, merge_aug_bboxes,
merge_aug_masks, merge_aug_proposals, multiclass_nms)
class RPNTestMixin(object):
def simple_test_rpn(self, x, img_meta, rpn_test_cfg):
rpn_outs = self.rpn_head(x)
proposal_inputs = rpn_outs + ... | 7,380 | 42.417647 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/plugins/non_local.py | import torch
import torch.nn as nn
from mmcv.cnn import constant_init, normal_init
from ..utils import ConvModule
class NonLocal2D(nn.Module):
"""Non-local module.
See https://arxiv.org/abs/1711.07971 for details.
Args:
in_channels (int): Channels of the input feature map.
reduction (in... | 3,708 | 31.252174 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/plugins/generalized_attention.py | import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import kaiming_init
class GeneralizedAttention(nn.Module):
"""GeneralizedAttention module.
See 'An Empirical Study of Spatial Attention Mechanisms in Deep Networks'
(https://arxiv.org/abs/1711... | 15,004 | 38.075521 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/necks/fpn.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmdet.core import auto_fp16
from ..registry import NECKS
from ..utils import ConvModule
@NECKS.register_module
class FPN(nn.Module):
def __init__(self,
in_channels,
out_channels,
... | 5,289 | 36.253521 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/necks/just_one_outs_neck.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmcv.cnn.weight_init import caffe2_xavier_init
from mmdet.core import auto_fp16
from ..registry import NECKS
from ..utils import ConvModule
import torch
import gc
@NECKS.register_module
class FPNLast(nn.Module):
def __in... | 11,514 | 32.184438 | 105 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/models/necks/hrfpn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn.weight_init import caffe2_xavier_init
from torch.utils.checkpoint import checkpoint
from ..registry import NECKS
from ..utils import ConvModule
@NECKS.register_module
class HRFPN(nn.Module):
"""HRFPN (High Resolution Feature Pyrmami... | 3,363 | 32.306931 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/roi_extractors/single_level.py | from __future__ import division
import torch
import torch.nn as nn
from mmdet import ops
from mmdet.core import force_fp32
from ..registry import ROI_EXTRACTORS
@ROI_EXTRACTORS.register_module
class SingleRoIExtractor(nn.Module):
"""Extract RoI features from a single level feature map.
If there are mulitpl... | 3,794 | 34.138889 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/reppoints_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (PointGenerator, multi_apply, multiclass_nms,
point_target)
from mmdet.ops import DeformConv
from ..builder import build_loss
from ..registry import HEA... | 27,172 | 44.515913 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/rpn_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import normal_init
from mmdet.core import delta2bbox
from mmdet.ops import nms
from ..registry import HEADS
from .anchor_head import AnchorHead
@HEADS.register_module
class RPNHead(AnchorHead):
def __init__(self, in_channels, **kwa... | 4,180 | 37.712963 | 83 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/anchor_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGenerator, anchor_target, delta2bbox, force_fp32,
multi_apply, multiclass_nms)
from ..builder import build_loss
from ..registry import HEADS
@HE... | 14,032 | 41.268072 | 97 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/retina_head.py | import numpy as np
import torch.nn as nn
from mmcv.cnn import normal_init
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .anchor_head import AnchorHead
@HEADS.register_module
class RetinaHead(AnchorHead):
"""
An anchor-based head used in [1]_.
The head contains two... | 3,603 | 33.653846 | 77 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/ga_rpn_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import normal_init
from mmdet.core import delta2bbox
from mmdet.ops import nms
from ..registry import HEADS
from .guided_anchor_head import GuidedAnchorHead
@HEADS.register_module
class GARPNHead(GuidedAnchorHead):
"""Guided-Anchor-... | 4,981 | 37.921875 | 78 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/ga_retina_head.py | import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.ops import MaskedConv2d
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .guided_anchor_head import FeatureAdaption, GuidedAnchorHead
@HEADS.register_module
class GARetinaHead(GuidedAnchorHead):
"""Guided-Ancho... | 3,760 | 33.824074 | 78 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/ssd_head.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import xavier_init
from mmdet.core import AnchorGenerator, anchor_target, multi_apply
from ..losses import smooth_l1_loss
from ..registry import HEADS
from .anchor_head import AnchorHead
# TODO: add loss evaluator for... | 7,762 | 38.607143 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/fcos_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import distance2bbox, force_fp32, multi_apply, multiclass_nms
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule, Scale, bias_init_with_prob
INF = 1e8
@HEADS.register_module
class FCOSHead(n... | 16,509 | 39.366748 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/free_anchor_retina_head.py | import torch
import torch.nn.functional as F
from mmdet.core import bbox2delta, bbox_overlaps, delta2bbox
from ..registry import HEADS
from .retina_head import RetinaHead
@HEADS.register_module
class FreeAnchorRetinaHead(RetinaHead):
def __init__(self,
num_classes,
in_channels,... | 7,396 | 38.137566 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/guided_anchor_head.py | from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import (AnchorGenerator, anchor_inside_flags, anchor_target,
delta2bbox, force_fp32, ga_loc_target, ga_shape_target,
multi_apply, multi... | 25,250 | 39.596463 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/anchor_heads/fovea_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from mmdet.core import multi_apply, multiclass_nms
from mmdet.ops import DeformConv
from ..builder import build_loss
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
INF = 1e8
class FeatureAlign(nn.Module):
def ... | 16,360 | 41.167526 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/bbox_heads/bbox_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from mmdet.core import (auto_fp16, bbox_target, delta2bbox, force_fp32,
multiclass_nms)
from ..builder import build_loss
from ..losses import accuracy
from ..registry import HEADS
@HEAD... | 9,344 | 37.29918 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/bbox_heads/convfc_bbox_head.py | import torch.nn as nn
from ..registry import HEADS
from ..utils import ConvModule
from .bbox_head import BBoxHead
@HEADS.register_module
class ConvFCBBoxHead(BBoxHead):
r"""More general bbox head, with shared conv and fc layers and two optional
separated branches.
/-> cls con... | 7,308 | 37.067708 | 82 | py |
AlignShift | AlignShift-master/mmdet/models/bbox_heads/double_bbox_head.py | import torch.nn as nn
from mmcv.cnn.weight_init import normal_init, xavier_init
from ..backbones.resnet import Bottleneck
from ..registry import HEADS
from ..utils import ConvModule
from .bbox_head import BBoxHead
class BasicResBlock(nn.Module):
"""Basic residual block.
This block is a little different from... | 5,274 | 29.847953 | 78 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/models/utils/scale.py | import torch
import torch.nn as nn
class Scale(nn.Module):
"""
A learnable scale parameter
"""
def __init__(self, scale=1.0):
super(Scale, self).__init__()
self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float))
def forward(self, x):
return x * self.scale
| 314 | 18.6875 | 73 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/models/utils/conv_module.py | import warnings
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from .conv_ws import ConvWS2d
from .norm import build_norm_layer
conv_cfg = {
'Conv': nn.Conv2d,
'ConvWS': ConvWS2d,
# TODO: octave conv
}
def build_conv_layer(cfg, *args, **kwargs):
""" Build convolution layer
... | 5,745 | 33.824242 | 78 | py |
AlignShift | AlignShift-master/mmdet/models/losses/ghm_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
def _expand_binary_labels(labels, label_weights, label_channels):
bin_labels = labels.new_full((labels.size(0), label_channels), 0)
inds = torch.nonzero(labels >= 1).squeeze()
if inds.numel() > 0:
bin... | 6,304 | 35.656977 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/losses/mse_loss.py | import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
from .utils import weighted_loss
mse_loss = weighted_loss(F.mse_loss)
@LOSSES.register_module
class MSELoss(nn.Module):
def __init__(self, reduction='mean', loss_weight=1.0):
super().__init__()
self.reduction = ... | 632 | 23.346154 | 66 | py |
AlignShift | AlignShift-master/mmdet/models/losses/balanced_l1_loss.py | import numpy as np
import torch
import torch.nn as nn
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def balanced_l1_loss(pred,
target,
beta=1.0,
alpha=0.5,
gamma=1.5,
reduction='me... | 1,884 | 25.928571 | 73 | py |
AlignShift | AlignShift-master/mmdet/models/losses/iou_loss.py | import torch
import torch.nn as nn
from mmdet.core import bbox_overlaps
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def iou_loss(pred, target, eps=1e-6):
"""IoU loss.
Computing the IoU loss between a set of predicted bboxes and target bboxes.
The loss is calculated as n... | 4,339 | 30.911765 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/losses/smooth_l1_loss.py | import torch
import torch.nn as nn
from ..registry import LOSSES
from .utils import weighted_loss
@weighted_loss
def smooth_l1_loss(pred, target, beta=1.0):
assert beta > 0
assert pred.size() == target.size() and target.numel() > 0
diff = torch.abs(pred - target)
loss = torch.where(diff < beta, 0.5 *... | 1,288 | 27.021739 | 73 | py |
AlignShift | AlignShift-master/mmdet/models/losses/utils.py | import functools
import torch.nn.functional as F
def reduce_loss(loss, reduction):
"""Reduce loss as specified.
Args:
loss (Tensor): Elementwise loss tensor.
reduction (str): Options are "none", "mean" and "sum".
Return:
Tensor: Reduced loss tensor.
"""
reduction_enum = ... | 3,003 | 29.343434 | 79 | py |
AlignShift | AlignShift-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 |
AlignShift | AlignShift-master/mmdet/models/losses/focal_loss.py | import torch.nn as nn
import torch.nn.functional as F
from mmdet.ops import sigmoid_focal_loss as _sigmoid_focal_loss
from ..registry import LOSSES
from .utils import weight_reduce_loss
# This method is only for debugging
def py_sigmoid_focal_loss(pred,
target,
wei... | 2,784 | 32.554217 | 76 | py |
AlignShift | AlignShift-master/mmdet/models/losses/cross_entropy_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..registry import LOSSES
from .utils import weight_reduce_loss
def cross_entropy(pred, label, weight=None, reduction='mean', avg_factor=None):
# element-wise losses
loss = F.cross_entropy(pred, label, reduction='none')
# apply weigh... | 3,386 | 31.567308 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/backbones/hrnet.py | import logging
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import BasicBlock, Bottleneck
class HRM... | 19,868 | 36.773764 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/backbones/resnet.py | import logging
import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.plugins import GeneralizedAttention
from mmdet.ops import ContextBlock, DeformConv, Modu... | 18,099 | 32.272059 | 79 | py |
AlignShift | AlignShift-master/mmdet/models/backbones/ssd_vgg.py | import logging
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import VGG, constant_init, kaiming_init, normal_init, xavier_init
from mmcv.runner import load_checkpoint
from ..registry import BACKBONES
@BACKBONES.register_module
class SSDVGG(VGG):
"""VGG Backbone network for sin... | 5,335 | 33.425806 | 79 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.