repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
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/evaluation/visualize.py | import numpy as np
import PIL.Image as Image
import PIL.ImageDraw as ImageDraw
import PIL.ImageFont as ImageFont
INDIGO = (75, 0, 130)
def draw_bounding_box_on_image(
image,
x_min,
y_min,
x_max,
y_max,
color,
thickness=4,
display_str_list=(),
use_normalized_coordinates=True,
f... | 2,523 | 36.117647 | 118 | 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/mask_generateor.py | import numpy as np
import csv
import cv2
import logging
import os
from pycocotools import mask as mutils
import argparse
def parse_args():
parser = argparse.ArgumentParser(description='generate mask through')
# parser.add_argument('config', help='train config file path')
parser.add_argument('--dataroot')
... | 11,294 | 39.339286 | 125 | py |
AlignShift | AlignShift-master/deeplesion/dataset/transform.py | from mmdet.datasets.registry import PIPELINES
from mmcv.parallel import DataContainer as DC
from mmdet.datasets.pipelines import to_tensor
import numpy as np
@PIPELINES.register_module
class ImageToTensor_3d(object):
def __init__(self, keys):
self.keys = keys
def __call__(self, results):
for ... | 2,217 | 37.241379 | 97 | 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/mconfigs/densenet_a3d.py | from deeplesion.ENVIRON import data_root
anchor_scales = [4, 6, 8, 12, 24, 48]#, 64
# fp16 = dict(loss_scale=96.)
dataset_transform = dict(
IMG_DO_CLIP = False,
# PIXEL_MEAN = 0.5,
WINDOWING = [-1024, 2050],
DATA_AUG_POSITION = False,
NORM_SPACING = 0.,
SLICE_INTV = 2.0,
NUM_SLICES = 3,
... | 7,181 | 29.561702 | 129 | py |
AlignShift | AlignShift-master/deeplesion/mconfigs/densenet_tsm.py | from deeplesion.ENVIRON import data_root
anchor_scales = [4, 6, 8, 12, 24, 48]#, 64
# fp16 = dict(loss_scale=96.)
dataset_transform = dict(
IMG_DO_CLIP = False,
# PIXEL_MEAN = 0.5,
WINDOWING = [-1024, 2050],
DATA_AUG_POSITION = False,
NORM_SPACING = 0.,
SLICE_INTV = 2.0,
NUM_SLICES = 3,
... | 7,229 | 29.506329 | 129 | py |
AlignShift | AlignShift-master/deeplesion/mconfigs/densenet_align.py | from deeplesion.ENVIRON import data_root
anchor_scales = [4, 6, 8, 12, 24, 48]#, 64
# fp16 = dict(loss_scale=96.)
dataset_transform = dict(
IMG_DO_CLIP = False,
WINDOWING = [-1024, 2050],
DATA_AUG_POSITION = False,
NORM_SPACING = 0.,
SLICE_INTV = 2.0,
NUM_SLICES = 3,
GROUNP_ZSAPACING = Fals... | 7,253 | 30 | 127 | py |
AlignShift | AlignShift-master/deeplesion/mconfigs/densenet_25d.py | from deeplesion.ENVIRON import data_root
anchor_scales = [4, 6, 8, 12, 24, 48]#, 64
# fp16 = dict(loss_scale=96.)
dataset_transform = dict(
IMG_DO_CLIP = False,
# PIXEL_MEAN = 0.5,
WINDOWING = [-1024, 2050],
DATA_AUG_POSITION = False,
NORM_SPACING = 0.,
SLICE_INTV = 2.0,
NUM_SLICES = 3,
... | 7,181 | 29.824034 | 127 | 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/version.py | # GENERATED VERSION FILE
# TIME: Tue Sep 28 14:27:47 2021
__version__ = '1.0rc1+c42460f'
short_version = '1.0rc1'
| 115 | 18.333333 | 32 | py |
AlignShift | AlignShift-master/mmdet/__init__.py | from .version import __version__, short_version
__all__ = ['__version__', 'short_version']
| 92 | 22.25 | 47 | 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/__init__.py | from .env import get_root_logger, init_dist, set_random_seed
from .inference import (inference_detector, init_detector, show_result,
show_result_pyplot)
from .train import train_detector
__all__ = [
'init_dist', 'get_root_logger', 'set_random_seed', 'train_detector',
'init_detector', 'i... | 378 | 36.9 | 78 | 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/__init__.py | from .anchor import * # noqa: F401, F403
from .bbox import * # noqa: F401, F403
from .evaluation import * # noqa: F401, F403
from .fp16 import * # noqa: F401, F403
from .mask import * # noqa: F401, F403
from .post_processing import * # noqa: F401, F403
from .utils import * # noqa: F401, F403
| 300 | 36.625 | 50 | py |
AlignShift | AlignShift-master/mmdet/core/evaluation/class_names.py | import mmcv
def wider_face_classes():
return ['face']
def voc_classes():
return [
'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'
]
... | 5,442 | 45.521368 | 79 | py |
AlignShift | AlignShift-master/mmdet/core/evaluation/recall.py | import numpy as np
from terminaltables import AsciiTable
from .bbox_overlaps import bbox_overlaps
def _recalls(all_ious, proposal_nums, thrs):
img_num = all_ious.shape[0]
total_gt_num = sum([ious.shape[0] for ious in all_ious])
_ious = np.zeros((proposal_nums.size, total_gt_num), dtype=np.float32)
... | 5,961 | 31.053763 | 78 | 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/evaluation/__init__.py | from .class_names import (coco_classes, dataset_aliases, get_classes,
imagenet_det_classes, imagenet_vid_classes,
voc_classes)
from .coco_utils import coco_eval, fast_eval_recall, results2json
from .eval_hooks import (CocoDistEvalmAPHook, CocoDistEvalRecallHook,
... | 967 | 49.947368 | 76 | py |
AlignShift | AlignShift-master/mmdet/core/evaluation/coco_utils.py | import itertools
import mmcv
import numpy as np
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
from terminaltables import AsciiTable
from .recall import eval_recalls
def coco_eval(result_files,
result_types,
coco,
max_dets=(100, 300, 1000),
... | 8,159 | 35.756757 | 169 | py |
AlignShift | AlignShift-master/mmdet/core/evaluation/bbox_overlaps.py | import numpy as np
def bbox_overlaps(bboxes1, bboxes2, mode='iou'):
"""Calculate the ious between each bbox of bboxes1 and bboxes2.
Args:
bboxes1(ndarray): shape (n, 4)
bboxes2(ndarray): shape (k, 4)
mode(str): iou (intersection over union) or iof (intersection
over foregr... | 1,642 | 31.86 | 69 | py |
AlignShift | AlignShift-master/mmdet/core/evaluation/mean_ap.py | import mmcv
import numpy as np
from terminaltables import AsciiTable
from .bbox_overlaps import bbox_overlaps
from .class_names import get_classes
def average_precision(recalls, precisions, mode='area'):
"""Calculate average precision (for single or multiple scales).
Args:
recalls (ndarray): shape (... | 16,019 | 40.502591 | 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/post_processing/__init__.py | from .bbox_nms import multiclass_nms
from .merge_augs import (merge_aug_bboxes, merge_aug_masks,
merge_aug_proposals, merge_aug_scores)
__all__ = [
'multiclass_nms', 'merge_aug_proposals', 'merge_aug_bboxes',
'merge_aug_scores', 'merge_aug_masks'
]
| 283 | 30.555556 | 64 | 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/mask/utils.py | import mmcv
def split_combined_polys(polys, poly_lens, polys_per_mask):
"""Split the combined 1-D polys into masks.
A mask is represented as a list of polys, and a poly is represented as
a 1-D array. In dataset, all masks are concatenated into a single 1-D
tensor. Here we need to split the tensor int... | 1,172 | 36.83871 | 75 | py |
AlignShift | AlignShift-master/mmdet/core/mask/__init__.py | from .mask_target import mask_target
from .utils import split_combined_polys
__all__ = ['split_combined_polys', 'mask_target']
| 128 | 24.8 | 49 | 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/__init__.py | from .decorators import auto_fp16, force_fp32
from .hooks import Fp16OptimizerHook, wrap_fp16_model
__all__ = ['auto_fp16', 'force_fp32', 'Fp16OptimizerHook', 'wrap_fp16_model']
| 179 | 35 | 77 | 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/assign_sampling.py | import mmcv
from . import assigners, samplers
def build_assigner(cfg, **kwargs):
if isinstance(cfg, assigners.BaseAssigner):
return cfg
elif isinstance(cfg, dict):
return mmcv.runner.obj_from_dict(cfg, assigners, default_args=kwargs)
else:
raise TypeError('Invalid type {} for buil... | 1,159 | 33.117647 | 77 | 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/__init__.py | from .assigners import AssignResult, BaseAssigner, MaxIoUAssigner
from .bbox_target import bbox_target
from .geometry import bbox_overlaps
from .samplers import (BaseSampler, CombinedSampler,
InstanceBalancedPosSampler, IoUBalancedNegSampler,
PseudoSampler, RandomSampler, S... | 1,106 | 47.130435 | 77 | 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/base_assigner.py | from abc import ABCMeta, abstractmethod
class BaseAssigner(metaclass=ABCMeta):
@abstractmethod
def assign(self, bboxes, gt_bboxes, gt_bboxes_ignore=None, gt_labels=None):
pass
| 195 | 20.777778 | 79 | 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/__init__.py | from .approx_max_iou_assigner import ApproxMaxIoUAssigner
from .assign_result import AssignResult
from .base_assigner import BaseAssigner
from .max_iou_assigner import MaxIoUAssigner
from .point_assigner import PointAssigner
__all__ = [
'BaseAssigner', 'MaxIoUAssigner', 'ApproxMaxIoUAssigner', 'AssignResult',
... | 338 | 29.818182 | 77 | 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/combined_sampler.py | from ..assign_sampling import build_sampler
from .base_sampler import BaseSampler
class CombinedSampler(BaseSampler):
def __init__(self, pos_sampler, neg_sampler, **kwargs):
super(CombinedSampler, self).__init__(**kwargs)
self.pos_sampler = build_sampler(pos_sampler, **kwargs)
self.neg_sa... | 509 | 29 | 63 | 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/__init__.py | from .base_sampler import BaseSampler
from .combined_sampler import CombinedSampler
from .instance_balanced_pos_sampler import InstanceBalancedPosSampler
from .iou_balanced_neg_sampler import IoUBalancedNegSampler
from .ohem_sampler import OHEMSampler
from .pseudo_sampler import PseudoSampler
from .random_sampler impor... | 562 | 36.533333 | 77 | 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/utils/misc.py | from functools import partial
import mmcv
import numpy as np
from six.moves import map, zip
def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
num_imgs = tensor.size(0)
mean = np.array(mean, dtype=np.float32)
std = np.array(std, dtype=np.float32)
imgs = []
for img_id in range(nu... | 1,108 | 28.184211 | 75 | py |
AlignShift | AlignShift-master/mmdet/core/utils/__init__.py | from .dist_utils import DistOptimizerHook, allreduce_grads
from .misc import multi_apply, tensor2imgs, unmap
__all__ = [
'allreduce_grads', 'DistOptimizerHook', 'tensor2imgs', 'unmap',
'multi_apply'
]
| 210 | 25.375 | 67 | 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/__init__.py | from .anchor_generator import AnchorGenerator
from .anchor_target import anchor_inside_flags, anchor_target
from .guided_anchor_target import ga_loc_target, ga_shape_target
from .point_generator import PointGenerator
from .point_target import point_target
__all__ = [
'AnchorGenerator', 'anchor_target', 'anchor_ins... | 407 | 36.090909 | 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/registry.py | from mmdet.utils import Registry
BACKBONES = Registry('backbone')
NECKS = Registry('neck')
ROI_EXTRACTORS = Registry('roi_extractor')
SHARED_HEADS = Registry('shared_head')
HEADS = Registry('head')
LOSSES = Registry('loss')
DETECTORS = Registry('detector')
| 258 | 24.9 | 42 | py |
AlignShift | AlignShift-master/mmdet/models/__init__.py | from .anchor_heads import * # noqa: F401,F403
from .backbones import * # noqa: F401,F403
from .bbox_heads import * # noqa: F401,F403
from .builder import (build_backbone, build_detector, build_head, build_loss,
build_neck, build_roi_extractor, build_shared_head)
from .detectors import * # noqa... | 910 | 44.55 | 78 | 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/fast_rcnn.py | from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class FastRCNN(TwoStageDetector):
def __init__(self,
backbone,
bbox_roi_extractor,
bbox_head,
train_cfg,
test_cfg,
... | 2,326 | 36.532258 | 77 | 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/mask_rcnn.py | from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class MaskRCNN(TwoStageDetector):
def __init__(self,
backbone,
rpn_head,
bbox_roi_extractor,
bbox_head,
mask_roi_extractor,
... | 926 | 27.96875 | 50 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/faster_rcnn.py | from ..registry import DETECTORS
from .two_stage import TwoStageDetector
@DETECTORS.register_module
class FasterRCNN(TwoStageDetector):
def __init__(self,
backbone,
rpn_head,
bbox_roi_extractor,
bbox_head,
train_cfg,
... | 781 | 26.928571 | 50 | 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/rpn.py | import mmcv
from mmdet.core import bbox_mapping, tensor2imgs
from .. import builder
from ..registry import DETECTORS
from .base import BaseDetector
from .test_mixins import RPNTestMixin
@DETECTORS.register_module
class RPN(BaseDetector, RPNTestMixin):
def __init__(self,
backbone,
... | 3,513 | 34.857143 | 78 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/retinanet.py | from ..registry import DETECTORS
from .single_stage import SingleStageDetector
@DETECTORS.register_module
class RetinaNet(SingleStageDetector):
def __init__(self,
backbone,
bbox_head,
mask_head,
neck=None,#hyadd
train_cfg=None,
... | 537 | 28.888889 | 87 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/fcos.py | from ..registry import DETECTORS
from .single_stage import SingleStageDetector
@DETECTORS.register_module
class FCOS(SingleStageDetector):
def __init__(self,
backbone,
neck,
bbox_head,
train_cfg=None,
test_cfg=None,
... | 473 | 26.882353 | 72 | py |
AlignShift | AlignShift-master/mmdet/models/detectors/fovea.py | from ..registry import DETECTORS
from .single_stage import SingleStageDetector
@DETECTORS.register_module
class FOVEA(SingleStageDetector):
def __init__(self,
backbone,
neck,
bbox_head,
train_cfg=None,
test_cfg=None,
... | 476 | 27.058824 | 73 | 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/__init__.py | from .base import BaseDetector
from .cascade_rcnn import CascadeRCNN
from .double_head_rcnn import DoubleHeadRCNN
from .fast_rcnn import FastRCNN
from .faster_rcnn import FasterRCNN
from .fcos import FCOS
from .fovea import FOVEA
from .grid_rcnn import GridRCNN
from .htc import HybridTaskCascade
from .mask_rcnn import ... | 915 | 37.166667 | 77 | 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/__init__.py | from .generalized_attention import GeneralizedAttention
from .non_local import NonLocal2D
__all__ = ['NonLocal2D', 'GeneralizedAttention']
| 140 | 27.2 | 55 | 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/__init__.py | from .bfp import BFP
from .fpn import FPN
from .hrfpn import HRFPN
from .just_one_outs_neck import FPNLast, HRFPNLast, FPNCatLast, MyFPN, MyFPN3
__all__ = ['FPN', 'BFP', 'HRFPN', 'FPNLast', 'HRFPNLast', 'FPNCatLast', 'MyFPN', 'MyFPN3']
| 237 | 33 | 90 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.