Search is not available for this dataset
repo stringlengths 2 152 ⌀ | file stringlengths 15 239 | code stringlengths 0 58.4M | file_length int64 0 58.4M | avg_line_length float64 0 1.81M | max_line_length int64 0 12.7M | extension_type stringclasses 364
values |
|---|---|---|---|---|---|---|
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_mobilenet_v2.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from torch.nn.modules import GroupNorm
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.backbones.mobilenet_v2 import MobileNetV2
from .utils import check_norm_state, is_block, is_norm
def test_mobilenetv2_backbone():
w... | 6,546 | 36.626437 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_pvt.py | import pytest
import torch
from mmdet.models.backbones.pvt import (PVTEncoderLayer,
PyramidVisionTransformer,
PyramidVisionTransformerV2)
def test_pvt_block():
# test PVT structure and forward
block = PVTEncoderLayer(
emb... | 3,332 | 31.048077 | 69 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_regnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones import RegNet
regnet_test_data = [
('regnetx_400mf',
dict(w0=24, wa=24.48, wm=2.54, group_w=16, depth=22,
bot_mul=1.0), [32, 64, 160, 384]),
('regnetx_800mf',
dict(w0=56, wa=35.73, wm=2.2... | 2,177 | 35.915254 | 73 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_renext.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones import ResNeXt
from mmdet.models.backbones.resnext import Bottleneck as BottleneckX
from .utils import is_block
def test_renext_bottleneck():
with pytest.raises(AssertionError):
# Style must be in ['pyt... | 3,528 | 32.292453 | 73 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_res2net.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones import Res2Net
from mmdet.models.backbones.res2net import Bottle2neck
from .utils import is_block
def test_res2net_bottle2neck():
with pytest.raises(AssertionError):
# Style must be in ['pytorch', 'caff... | 1,976 | 30.380952 | 72 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_resnest.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones import ResNeSt
from mmdet.models.backbones.resnest import Bottleneck as BottleneckS
def test_resnest_bottleneck():
with pytest.raises(AssertionError):
# Style must be in ['pytorch', 'caffe']
Bot... | 1,473 | 29.708333 | 76 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv import assert_params_all_zeros
from mmcv.ops import DeformConv2dPack
from torch.nn.modules import AvgPool2d, GroupNorm
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.backbones import ResNet, ResNetV1d
from mmdet.m... | 22,380 | 34.35703 | 78 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_swin.py | import pytest
import torch
from mmdet.models.backbones.swin import SwinBlock, SwinTransformer
def test_swin_block():
# test SwinBlock structure and forward
block = SwinBlock(embed_dims=64, num_heads=4, feedforward_channels=256)
assert block.ffn.embed_dims == 64
assert block.attn.w_msa.num_heads == 4
... | 2,827 | 31.136364 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/test_trident_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones import TridentResNet
from mmdet.models.backbones.trident_resnet import TridentBottleneck
def test_trident_resnet_bottleneck():
trident_dilations = (1, 2, 3)
test_branch_idx = 1
concat_output = True
... | 6,372 | 34.209945 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_backbones/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
from torch.nn.modules import GroupNorm
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.backbones.res2net import Bottle2neck
from mmdet.models.backbones.resnet import BasicBlock, Bottleneck
from mmdet.models.backbones.resnext import Bottleneck as Bottl... | 1,026 | 30.121212 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_anchor_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import AnchorHead
def test_anchor_head_loss():
"""Tests anchor head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'... | 2,548 | 34.901408 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_ascend_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import (AscendAnchorHead, AscendRetinaHead,
AscendSSDHead)
def test_ascend_anchor_head_loss():
"""Tests AscendAnchorHead loss when truth is empty and non-empty."""
s = ... | 8,285 | 37.361111 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_atss_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import ATSSHead
def test_atss_head_loss():
"""Tests atss head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_sh... | 2,949 | 36.820513 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_autoassign_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads.autoassign_head import AutoAssignHead
from mmdet.models.dense_heads.paa_head import levels_to_images
def test_autoassign_head_loss():
"""Tests autoassign head loss when truth is empty and non-empty."""
s =... | 3,580 | 37.923913 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_centernet_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmcv import ConfigDict
from mmdet.models.dense_heads import CenterNetHead
def test_center_head_loss():
"""Tests center head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3)... | 4,385 | 39.611111 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_corner_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core.evaluation.bbox_overlaps import bbox_overlaps
from mmdet.models.dense_heads import CornerHead
def test_corner_head_loss():
"""Tests corner head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape... | 6,756 | 39.220238 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_ddod_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import DDODHead
def test_ddod_head_loss():
"""Tests ddod head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_sh... | 2,886 | 38.547945 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_dense_heads_attr.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
from terminaltables import AsciiTable
from mmdet.models import dense_heads
from mmdet.models.dense_heads import * # noqa: F401,F403
def test_dense_heads_test_attr():
"""Tests inference methods such as simple_test and aug_test."""
# make list o... | 1,702 | 36.844444 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_detr_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv import ConfigDict
from mmdet.models.dense_heads import DETRHead
def test_detr_head_loss():
"""Tests transformer head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_fact... | 4,130 | 38.342857 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_fcos_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import FCOSHead
def test_fcos_head_loss():
"""Tests fcos head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_sh... | 2,406 | 36.030769 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_fsaf_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import FSAFHead
def test_fsaf_head_loss():
"""Tests anchor head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_... | 3,097 | 36.325301 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_ga_anchor_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import GuidedAnchorHead
def test_ga_anchor_head_loss():
"""Tests anchor head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
... | 3,410 | 36.076087 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_gfl_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import GFLHead
def test_gfl_head_loss():
"""Tests gfl head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_shape... | 2,786 | 36.16 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_lad_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import torch
from mmdet.models.dense_heads import LADHead, lad_head
from mmdet.models.dense_heads.lad_head import levels_to_images
def test_lad_head_loss():
"""Tests lad head loss when truth is empty and non-empty."""
class mock_... | 5,294 | 34.3 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_ld_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import GFLHead, LDHead
def test_ld_head_loss():
"""Tests vfnet head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'... | 4,605 | 36.754098 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_mask2former_head.py | import numpy as np
import pytest
import torch
from mmcv import ConfigDict
from mmdet.core.mask import BitmapMasks
from mmdet.models.dense_heads import Mask2FormerHead
@pytest.mark.parametrize('num_stuff_classes, \
label_num', [(53, 100), (0, 80)])
def test_mask2former_head_loss(num_stuff_classes, label_num):
... | 9,110 | 37.605932 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_maskformer_head.py | import numpy as np
import torch
from mmcv import ConfigDict
from mmdet.core.mask import BitmapMasks
from mmdet.models.dense_heads import MaskFormerHead
def test_maskformer_head_loss():
"""Tests head loss when truth is empty and non-empty."""
base_channels = 64
# batch_input_shape = (128, 160)
img_met... | 8,154 | 38.396135 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_paa_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import torch
from mmdet.models.dense_heads import PAAHead, paa_head
from mmdet.models.dense_heads.paa_head import levels_to_images
def test_paa_head_loss():
"""Tests paa head loss when truth is empty and non-empty."""
class mock_... | 4,800 | 34.301471 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_pisa_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import PISARetinaHead, PISASSDHead
from mmdet.models.roi_heads import PISARoIHead
def test_pisa_retinanet_head_loss():
"""Tests pisa retinanet head loss when truth is empty and non-empty."""
s = 256
img... | 8,805 | 34.796748 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_sabl_retina_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import SABLRetinaHead
def test_sabl_retina_head_loss():
"""Tests anchor head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
... | 3,080 | 39.012987 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_solo_head.py | import pytest
import torch
from mmdet.models.dense_heads import (DecoupledSOLOHead,
DecoupledSOLOLightHead, SOLOHead)
def test_solo_head_loss():
"""Tests solo head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
... | 9,519 | 32.403509 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_tood_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import TOODHead
def test_tood_head_loss():
"""Tests paa head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad_sh... | 4,942 | 37.317829 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_vfnet_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import VFNetHead
def test_vfnet_head_loss():
"""Tests vfnet head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad... | 2,561 | 39.03125 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_yolact_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import YOLACTHead, YOLACTProtonet, YOLACTSegmHead
def test_yolact_head_loss():
"""Tests yolact head losses when truth is empty and non-empty."""
s = 550
img_metas = [{
'img_shape': (s, s, 3),
... | 5,247 | 37.028986 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_yolof_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.dense_heads import YOLOFHead
def test_yolof_head_loss():
"""Tests yolof head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'img_shape': (s, s, 3),
'scale_factor': 1,
'pad... | 2,716 | 34.285714 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_dense_heads/test_yolox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
from mmdet.models.dense_heads import YOLOXHead
def test_yolox_head_loss():
"""Tests yolox head loss when truth is empty and non-empty."""
s = 256
img_metas = [{
'... | 3,809 | 41.808989 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import _dummy_bbox_sampling
__all__ = ['_dummy_bbox_sampling']
| 124 | 24 | 47 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/test_bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import pytest
import torch
from mmdet.core import bbox2roi
from mmdet.models.roi_heads.bbox_heads import BBoxHead
from .utils import _dummy_bbox_sampling
def test_bbox_head_loss():
"""Tests bbox head loss when truth is empty and non-e... | 7,910 | 30.392857 | 78 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/test_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.models.roi_heads.mask_heads import (DynamicMaskHead, FCNMaskHead,
MaskIoUHead)
from .utils import _dummy_bbox_sampling
def test_mask_head_loss():
"""Test mask head loss when mask tar... | 3,431 | 34.020408 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/test_roi_extractor.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.roi_heads.roi_extractors import GenericRoIExtractor
def test_groie():
# test with pre/post
cfg = dict(
roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=2),
out_channels=256,
featm... | 3,257 | 27.330435 | 77 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/test_sabl_bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmdet.core import bbox2roi
from mmdet.models.roi_heads.bbox_heads import SABLHead
from .utils import _dummy_bbox_sampling
def test_sabl_bbox_head_loss():
"""Tests bbox head loss when truth is empty and non-empty."""
self = SABLHead... | 2,979 | 37.205128 | 75 | py |
mmdetection | mmdetection-master/tests/test_models/test_roi_heads/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmdet.core import build_assigner, build_sampler
def _dummy_bbox_sampling(proposal_list, gt_bboxes, gt_labels):
"""Create sample results that can be passed to BBoxHead.get_targets."""
num_imgs = 1
feat = torch.rand(1, 1, 3, 3)
assign_co... | 1,249 | 31.051282 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_seg_heads/test_maskformer_fusion_head.py | import pytest
import torch
from mmcv import ConfigDict
from mmdet.models.seg_heads.panoptic_fusion_heads import MaskFormerFusionHead
def test_maskformer_fusion_head():
img_metas = [
{
'batch_input_shape': (128, 160),
'img_shape': (126, 160, 3),
'ori_shape': (63, 80, 3)... | 1,673 | 30 | 78 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_brick_wrappers.py | from unittest.mock import patch
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmdet.models.utils import AdaptiveAvgPool2d, adaptive_avg_pool2d
if torch.__version__ != 'parrots':
torch_version = '1.7'
else:
torch_version = 'parrots'
@patch('torch.__version__', torch_version)
def te... | 2,931 | 30.191489 | 69 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_conv_upsample.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.utils import ConvUpsample
@pytest.mark.parametrize('num_layers', [0, 1, 2])
def test_conv_upsample(num_layers):
num_upsample = num_layers if num_layers > 0 else 0
num_layers = num_layers if num_layers > 0 else 1
... | 628 | 24.16 | 54 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_inverted_residual.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.cnn import is_norm
from torch.nn.modules import GroupNorm
from mmdet.models.utils import InvertedResidual, SELayer
def test_inverted_residual():
with pytest.raises(AssertionError):
# stride must be in [1, 2]
Inv... | 2,635 | 33.233766 | 71 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_model_misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from torch.autograd import gradcheck
from mmdet.models.utils import interpolate_as, sigmoid_geometric_mean
def test_interpolate_as():
source = torch.rand((1, 5, 4, 4))
target = torch.rand((1, 1, 16, 16))
# Test 4D source and... | 1,149 | 30.081081 | 73 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_position_encoding.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.utils import (LearnedPositionalEncoding,
SinePositionalEncoding)
def test_sine_positional_encoding(num_feats=16, batch_size=2):
# test invalid type of scale
with pytest.raises(Assertio... | 1,437 | 34.95 | 79 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_se_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
import torch.nn.functional as F
from mmcv.cnn import constant_init
from mmdet.models.utils import DyReLU, SELayer
def test_se_layer():
with pytest.raises(AssertionError):
# act_cfg sequence length must equal to 2
SELayer(c... | 1,616 | 28.4 | 76 | py |
mmdetection | mmdetection-master/tests/test_models/test_utils/test_transformer.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.utils import ConfigDict
from mmdet.models.utils.transformer import (AdaptivePadding,
DetrTransformerDecoder,
DetrTransformerEncoder, PatchEmbed,
... | 16,994 | 28.815789 | 79 | py |
mmdetection | mmdetection-master/tests/test_onnx/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import ort_validate
__all__ = ['ort_validate']
| 108 | 20.8 | 47 | py |
mmdetection | mmdetection-master/tests/test_onnx/test_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
from functools import partial
import mmcv
import numpy as np
import pytest
import torch
from mmcv.cnn import Scale
from mmdet import digit_version
from mmdet.models import build_detector
from mmdet.models.dense_heads import (FCOSHead, FSAFHead, Ret... | 14,104 | 30.068282 | 78 | py |
mmdetection | mmdetection-master/tests/test_onnx/test_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import mmcv
import pytest
import torch
from mmdet import digit_version
from mmdet.models.necks import FPN, YOLOV3Neck
from .utils import ort_validate
if digit_version(torch.__version__) <= digit_version('1.5.0'):
pytest.skip(
'ort back... | 4,808 | 28.323171 | 77 | py |
mmdetection | mmdetection-master/tests/test_onnx/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import os.path as osp
import warnings
import numpy as np
import onnx
import onnxruntime as ort
import torch
import torch.nn as nn
ort_custom_op_path = ''
try:
from mmcv.ops import get_onnxruntime_op_path
ort_custom_op_path = get_onnxruntime_op_path()
e... | 4,141 | 29.014493 | 79 | py |
mmdetection | mmdetection-master/tests/test_runtime/async_benchmark.py | # Copyright (c) OpenMMLab. All rights reserved.
import asyncio
import os
import shutil
import urllib
import mmcv
import torch
from mmdet.apis import (async_inference_detector, inference_detector,
init_detector)
from mmdet.utils.contextmanagers import concurrent
from mmdet.utils.profiling impor... | 3,215 | 30.223301 | 77 | py |
mmdetection | mmdetection-master/tests/test_runtime/test_apis.py | import os
from pathlib import Path
import pytest
from mmdet.apis import init_detector
def test_init_detector():
project_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
project_dir = os.path.join(project_dir, '..')
config_file = os.path.join(
project_dir, 'configs/mask_rcnn/mas... | 1,019 | 29.909091 | 78 | py |
mmdetection | mmdetection-master/tests/test_runtime/test_async.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Tests for async interface."""
import asyncio
import os
import sys
import asynctest
import mmcv
import torch
from mmdet.apis import async_inference_detector, init_detector
if sys.version_info >= (3, 7):
from mmdet.utils.contextmanagers import concurrent
class ... | 2,608 | 30.059524 | 75 | py |
mmdetection | mmdetection-master/tests/test_runtime/test_config.py | # Copyright (c) OpenMMLab. All rights reserved.
from os.path import dirname, exists, join
from unittest.mock import Mock
import pytest
from mmdet.core import BitmapMasks, PolygonMasks
from mmdet.datasets.builder import DATASETS
from mmdet.datasets.utils import NumClassCheckHook
def _get_config_directory():
"""F... | 15,154 | 39.52139 | 79 | py |
mmdetection | mmdetection-master/tests/test_runtime/test_eval_hook.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import unittest.mock as mock
from collections import OrderedDict
from unittest.mock import MagicMock, patch
import pytest
import torch
import torch.nn as nn
from mmcv.runner import EpochBasedRunner, build_optimizer
from mmcv.utils im... | 8,590 | 32.956522 | 79 | py |
mmdetection | mmdetection-master/tests/test_runtime/test_fp16.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
import torch.nn as nn
from mmcv.runner import auto_fp16, force_fp32
from mmcv.runner.fp16_utils import cast_tensor_type
def test_cast_tensor_type():
inputs = torch.FloatTensor([5.])
src_type = torch.float32
dst_t... | 9,746 | 31.274834 | 75 | py |
mmdetection | mmdetection-master/tests/test_utils/test_anchor.py | # Copyright (c) OpenMMLab. All rights reserved.
"""
CommandLine:
pytest tests/test_utils/test_anchor.py
xdoctest tests/test_utils/test_anchor.py zero
"""
import pytest
import torch
def test_standard_points_generator():
from mmdet.core.anchor import build_prior_generator
# teat init
anchor_genera... | 33,157 | 42.062338 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_assigner.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Tests the Assigner objects.
CommandLine:
pytest tests/test_utils/test_assigner.py
xdoctest tests/test_utils/test_assigner.py zero
"""
import pytest
import torch
from mmdet.core.bbox.assigners import (ApproxMaxIoUAssigner,
... | 24,349 | 33.736091 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_coder.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.core.bbox.coder import (DeltaXYWHBBoxCoder, DistancePointBBoxCoder,
TBLRBBoxCoder, YOLOBBoxCoder)
def test_yolo_bbox_coder():
coder = YOLOBBoxCoder()
bboxes = torch.Tensor([[-42., -29., 74... | 5,779 | 44.15625 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_compat_config.py | import pytest
from mmcv import ConfigDict
from mmdet.utils.compat_config import (compat_imgs_per_gpu, compat_loader_args,
compat_runner_args)
def test_compat_runner_args():
cfg = ConfigDict(dict(total_epochs=12))
with pytest.warns(None) as record:
cfg = compat_r... | 3,947 | 33.034483 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_general_data.py | import copy
import numpy as np
import pytest
import torch
from mmdet.core import GeneralData, InstanceData
def _equal(a, b):
if isinstance(a, (torch.Tensor, np.ndarray)):
return (a == b).all()
else:
return a == b
def test_general_data():
# test init
meta_info = dict(
img_s... | 21,205 | 34.820946 | 78 | py |
mmdetection | mmdetection-master/tests/test_utils/test_hook.py | # Copyright (c) OpenMMLab. All rights reserved.
import logging
import shutil
import sys
import tempfile
from unittest.mock import MagicMock, Mock, call, patch
import numpy as np
import pytest
import torch
import torch.nn as nn
from mmcv.runner import (CheckpointHook, IterTimerHook, PaviLoggerHook,
... | 13,257 | 30.870192 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_layer_decay_optimizer_constructor.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmdet.core.optimizers import LearningRateDecayOptimizerConstructor
base_lr = 1
decay_rate = 2
base_wd = 0.05
weight_decay = 0.05
expected_stage_wise_lr_wd_convnext = [{
'weight_decay': 0.0,
... | 4,383 | 25.569697 | 77 | py |
mmdetection | mmdetection-master/tests/test_utils/test_logger.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
from mmdet.utils import get_caller_name, log_img_scale
def callee_func():
caller_name = get_caller_name()
return caller_name
class CallerClassForTest:
def __init__(self):
self.caller_name = callee_func()
def test_get_caller_name()... | 1,223 | 24.5 | 68 | py |
mmdetection | mmdetection-master/tests/test_utils/test_masks.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from mmdet.core import BitmapMasks, PolygonMasks, mask2bbox
def dummy_raw_bitmap_masks(size):
"""
Args:
size (tuple): expected shape of dummy masks, (H, W) or (N, H, W)
Return:
ndarray: dummy ma... | 28,276 | 38.603641 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_memory.py | import numpy as np
import pytest
import torch
from mmdet.utils import AvoidOOM
from mmdet.utils.memory import cast_tensor_type
def test_avoidoom():
tensor = torch.from_numpy(np.random.random((20, 20)))
if torch.cuda.is_available():
tensor = tensor.cuda()
# get default result
default_r... | 4,261 | 42.050505 | 75 | py |
mmdetection | mmdetection-master/tests/test_utils/test_misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import numpy as np
import pytest
import torch
from mmdet.core.bbox import distance2bbox
from mmdet.core.mask.structures import BitmapMasks, PolygonMasks
from mmdet.core.utils import (center_of_mass, filter_scores_and_topk,
... | 7,361 | 34.912195 | 79 | py |
mmdetection | mmdetection-master/tests/test_utils/test_nms.py | import pytest
import torch
from mmdet.core.post_processing import mask_matrix_nms
def _create_mask(N, h, w):
masks = torch.rand((N, h, w)) > 0.5
labels = torch.rand(N)
scores = torch.rand(N)
return masks, labels, scores
def test_nms_input_errors():
with pytest.raises(AssertionError):
ma... | 2,528 | 32.276316 | 69 | py |
mmdetection | mmdetection-master/tests/test_utils/test_replace_cfg_vals.py | import os.path as osp
import tempfile
from copy import deepcopy
import pytest
from mmcv.utils import Config
from mmdet.utils import replace_cfg_vals
def test_replace_cfg_vals():
temp_file = tempfile.NamedTemporaryFile()
cfg_path = f'{temp_file.name}.py'
with open(cfg_path, 'w') as f:
f.write('co... | 2,980 | 34.488095 | 77 | py |
mmdetection | mmdetection-master/tests/test_utils/test_setup_env.py | # Copyright (c) OpenMMLab. All rights reserved.
import multiprocessing as mp
import os
import platform
import cv2
from mmcv import Config
from mmdet.utils import setup_multi_processes
def test_setup_multi_processes():
# temp save system setting
sys_start_mehod = mp.get_start_method(allow_none=True)
sys_... | 2,221 | 31.202899 | 69 | py |
mmdetection | mmdetection-master/tests/test_utils/test_split_batch.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
from copy import deepcopy
import mmcv
import numpy as np
import torch
from mmdet.utils import split_batch
def test_split_batch():
img_root = osp.join(osp.dirname(__file__), '../data/color.jpg')
img = mmcv.imread(img_root, 'color')
h, ... | 3,704 | 37.59375 | 78 | py |
mmdetection | mmdetection-master/tests/test_utils/test_version.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmdet import digit_version
def test_version_check():
assert digit_version('1.0.5') > digit_version('1.0.5rc0')
assert digit_version('1.0.5') > digit_version('1.0.4rc0')
assert digit_version('1.0.5') > digit_version('1.0rc0')
assert digit_version('1.... | 798 | 46 | 64 | py |
mmdetection | mmdetection-master/tests/test_utils/test_visualization.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import os.path as osp
import tempfile
import mmcv
import numpy as np
import pytest
import torch
from mmdet.core import visualization as vis
from mmdet.datasets import (CityscapesDataset, CocoDataset,
CocoPanopticDataset, VOCDataset)... | 6,080 | 33.948276 | 78 | py |
mmdetection | mmdetection-master/tools/dist_test.sh | #!/usr/bin/env bash
CONFIG=$1
CHECKPOINT=$2
GPUS=$3
NNODES=${NNODES:-1}
NODE_RANK=${NODE_RANK:-0}
PORT=${PORT:-29500}
MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"}
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
python -m torch.distributed.launch \
--nnodes=$NNODES \
--node_rank=$NODE_RANK \
--master_addr=$MASTER_A... | 479 | 19.869565 | 43 | sh |
mmdetection | mmdetection-master/tools/dist_train.sh | #!/usr/bin/env bash
CONFIG=$1
GPUS=$2
NNODES=${NNODES:-1}
NODE_RANK=${NODE_RANK:-0}
PORT=${PORT:-29500}
MASTER_ADDR=${MASTER_ADDR:-"127.0.0.1"}
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
python -m torch.distributed.launch \
--nnodes=$NNODES \
--node_rank=$NODE_RANK \
--master_addr=$MASTER_ADDR \
--np... | 457 | 20.809524 | 43 | sh |
mmdetection | mmdetection-master/tools/slurm_test.sh | #!/usr/bin/env bash
set -x
PARTITION=$1
JOB_NAME=$2
CONFIG=$3
CHECKPOINT=$4
GPUS=${GPUS:-8}
GPUS_PER_NODE=${GPUS_PER_NODE:-8}
CPUS_PER_TASK=${CPUS_PER_TASK:-5}
PY_ARGS=${@:5}
SRUN_ARGS=${SRUN_ARGS:-""}
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
srun -p ${PARTITION} \
--job-name=${JOB_NAME} \
--gres=gpu:${GP... | 566 | 21.68 | 81 | sh |
mmdetection | mmdetection-master/tools/slurm_train.sh | #!/usr/bin/env bash
set -x
PARTITION=$1
JOB_NAME=$2
CONFIG=$3
WORK_DIR=$4
GPUS=${GPUS:-8}
GPUS_PER_NODE=${GPUS_PER_NODE:-8}
CPUS_PER_TASK=${CPUS_PER_TASK:-5}
SRUN_ARGS=${SRUN_ARGS:-""}
PY_ARGS=${@:5}
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
srun -p ${PARTITION} \
--job-name=${JOB_NAME} \
--gres=gpu:${GPUS... | 574 | 22 | 91 | sh |
mmdetection | mmdetection-master/tools/test.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import time
import warnings
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
wrap_fp... | 10,997 | 37.320557 | 79 | py |
mmdetection | mmdetection-master/tools/train.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy
import os
import os.path as osp
import time
import warnings
import mmcv
import torch
import torch.distributed as dist
from mmcv import Config, DictAction
from mmcv.runner import get_dist_info, init_dist
from mmcv.utils import get_git_hash
fro... | 9,260 | 36.342742 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/analyze_logs.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import json
from collections import defaultdict
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
def cal_train_time(log_dicts, args):
for i, log_dict in enumerate(log_dicts):
print(f'{"-" * 5}Analyze train time of {ar... | 7,359 | 34.902439 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/analyze_results.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
from multiprocessing import Pool
import mmcv
import numpy as np
from mmcv import Config, DictAction
from mmdet.core.evaluation import eval_map
from mmdet.core.visualization import imshow_gt_det_bboxes
from mmdet.datasets import buil... | 13,742 | 36.143243 | 78 | py |
mmdetection | mmdetection-master/tools/analysis_tools/benchmark.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy
import os
import time
import torch
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.parallel import MMDistributedDataParallel
from mmcv.runner import init_dist, load_checkpoint, wrap_fp16_model
from mmdet.datase... | 6,638 | 32.872449 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/coco_error_analysis.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os
from argparse import ArgumentParser
from multiprocessing import Pool
import matplotlib.pyplot as plt
import numpy as np
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
def makeplot(rs, ps, outDir, class_name, iou_type):... | 12,389 | 35.441176 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/coco_occluded_separated_recall.py | # Copyright (c) OpenMMLab. All rights reserved.
from argparse import ArgumentParser
import mmcv
from mmcv.utils import print_log
from mmdet.datasets import OccludedSeparatedCocoDataset
def main():
parser = ArgumentParser(
description='Compute recall of COCO occluded and separated masks '
'presen... | 1,505 | 32.466667 | 77 | py |
mmdetection | mmdetection-master/tools/analysis_tools/confusion_matrix.py | import argparse
import os
import matplotlib.pyplot as plt
import mmcv
import numpy as np
from matplotlib.ticker import MultipleLocator
from mmcv import Config, DictAction
from mmcv.ops import nms
from mmdet.core.evaluation.bbox_overlaps import bbox_overlaps
from mmdet.datasets import build_dataset
from mmdet.utils im... | 9,981 | 35.430657 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/eval_metric.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import mmcv
from mmcv import Config, DictAction
from mmdet.datasets import build_dataset
from mmdet.utils import replace_cfg_vals, update_data_root
def parse_args():
parser = argparse.ArgumentParser(description='Evaluate metric of the '
... | 3,141 | 34.303371 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/get_flops.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import numpy as np
import torch
from mmcv import Config, DictAction
from mmdet.models import build_detector
try:
from mmcv.cnn import get_model_complexity_info
except ImportError:
raise ImportError('Please upgrade mmcv to >0.6.2')
def parse_ar... | 2,992 | 29.540816 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/optimize_anchors.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Optimize anchor settings on a specific dataset.
This script provides two method to optimize YOLO anchors including k-means
anchor cluster and differential evolution. You can use ``--algorithm k-means``
and ``--algorithm differential_evolution`` to switch two method.
... | 13,359 | 34.437666 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/robustness_eval.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
from argparse import ArgumentParser
import mmcv
import numpy as np
def print_coco_results(results):
def _print(result, ap=1, iouThr=None, areaRng='all', maxDets=100):
titleStr = 'Average Precision' if ap == 1 else 'Average Recall'
... | 8,112 | 31.194444 | 79 | py |
mmdetection | mmdetection-master/tools/analysis_tools/test_robustness.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy
import os
import os.path as osp
import mmcv
import torch
from mmcv import DictAction
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
... | 15,222 | 38.234536 | 79 | py |
mmdetection | mmdetection-master/tools/dataset_converters/cityscapes.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import glob
import os.path as osp
import cityscapesscripts.helpers.labels as CSLabels
import mmcv
import numpy as np
import pycocotools.mask as maskUtils
def collect_files(img_dir, gt_dir):
suffix = 'leftImg8bit.png'
files = []
for img_file ... | 5,172 | 32.810458 | 75 | py |
mmdetection | mmdetection-master/tools/dataset_converters/images2coco.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import mmcv
from PIL import Image
def parse_args():
parser = argparse.ArgumentParser(
description='Convert images to coco format without annotations')
parser.add_argument('img_path', help='The root path of images')
parser.a... | 3,109 | 29.490196 | 77 | py |
mmdetection | mmdetection-master/tools/dataset_converters/pascal_voc.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import xml.etree.ElementTree as ET
import mmcv
import numpy as np
from mmdet.core import voc_classes
label_ids = {name: i for i, name in enumerate(voc_classes())}
def parse_xml(args):
xml_path, img_path = args
tree = ET.p... | 7,841 | 31.94958 | 79 | py |
mmdetection | mmdetection-master/tools/deployment/mmdet2torchserve.py | # Copyright (c) OpenMMLab. All rights reserved.
from argparse import ArgumentParser, Namespace
from pathlib import Path
from tempfile import TemporaryDirectory
import mmcv
try:
from model_archiver.model_packaging import package_model
from model_archiver.model_packaging_utils import ModelExportUtils
except Imp... | 3,693 | 32.279279 | 78 | py |
mmdetection | mmdetection-master/tools/deployment/mmdet_handler.py | # Copyright (c) OpenMMLab. All rights reserved.
import base64
import os
import mmcv
import torch
from ts.torch_handler.base_handler import BaseHandler
from mmdet.apis import inference_detector, init_detector
class MMdetHandler(BaseHandler):
threshold = 0.5
def initialize(self, context):
properties ... | 2,560 | 34.569444 | 79 | py |
mmdetection | mmdetection-master/tools/deployment/onnx2tensorrt.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import warnings
import numpy as np
import onnx
import torch
from mmcv import Config
from mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine
from mmdet.core.export import preprocess_example_input
from... | 9,035 | 32.842697 | 79 | py |