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 |
|---|---|---|---|---|---|---|
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/core/xcorr.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn.functional as F
def xcorr_slow(x, kernel):
"""for loop to calculate cross correlation,... | 1,410 | 27.795918 | 74 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/iou_loss.py | import torch
from torch import nn
from DFAT.core.config import cfg
class IOULoss(nn.Module):
def __init__(self, loc_loss_type):
super(IOULoss, self).__init__()
self.loc_loss_type = loc_loss_type
def forward(self, pred, target, weight=None):
# a, b = pred.shape
# print("%d,%d\n"... | 2,207 | 38.428571 | 95 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/pytorch_msssim.py | import torch
import torch.nn.functional as F
from math import exp
import numpy as np
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size, channel=1):
_1D_window = gaus... | 4,380 | 31.69403 | 118 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/init_weight.py | import torch.nn as nn
def init_weights(model):
for m in model.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight.data,
mode='fan_out',
nonlinearity='relu')
elif isinstance(m, nn.BatchNorm2d):
... | 387 | 28.846154 | 56 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/loss.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from DFAT.core.con... | 4,358 | 33.872 | 120 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/RFN.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
import pdb
import numpy as np
from DFAT.core.config import cfg
EPSILON = 1e-10
class ConvLayer(torch.nn... | 4,050 | 33.922414 | 98 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/model_builder.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
import pdb
import numpy as np
from DFAT.core.config i... | 31,853 | 38.570186 | 209 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/backbone/resnet_atrous.py | import math
import torch.nn as nn
import torch
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50']
def conv3x3(in_planes, out_planes, stride=1, dilation=1):
"3x3 convolution with padding"
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=dilation, bias=... | 7,235 | 29.15 | 78 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/backbone/resnet.py | import torch.nn as nn
import torch
import math
__all__ = ['ResNet', 'resnet18_', 'resnet34_', 'resnet50_', 'resnet101_',
'resnet152_']
model_urls = {
'resnet18_': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34_': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth... | 8,854 | 28.915541 | 100 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/backbone/mobile_v2.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
def conv_bn(inp, oup, stride, padding=1):
return nn.Sequential(
nn.Conv2d(inp, oup, 3, stride, padding, bias=False),
... | 4,367 | 27.180645 | 77 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/backbone/alexnet.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch.nn as nn
class AlexNetLegacy(nn.Module):
configs = [3, 96, 256, 384, 384, 256]
def __init__(self, width_mult=1):
configs = list(map(lambda... | 2,991 | 31.521739 | 72 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/neck/neck.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch.nn as nn
class AdjustLayer(nn.Module):
def __init__(self, in_channels, out_channels, center_size=7):
... | 1,911 | 32.54386 | 76 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/neck/__init__.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
from DFAT.models.neck.neck import AdjustLayer, Adjust... | 493 | 22.52381 | 61 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/head/rpn.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
from DFAT.core.config import cfg
from DFAT.core.xcorr... | 5,187 | 33.586667 | 95 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/models/head/mask.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
import torch.nn as nn
import torch.nn.functional as F
from DFAT.models.head.rpn import DepthwiseXCorr
from ... | 4,317 | 40.12381 | 128 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/datasets/dataset_RFN.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import json
import logging
import sys
import os
import numbers
import cv2
import numpy as np
import torch
from torch.uti... | 17,624 | 39.424312 | 125 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/datasets/dataset.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import json
import logging
import sys
import os
import cv2
import numpy as np
from torch.utils.data import Dataset
from... | 12,439 | 37.753894 | 112 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/utils/lr_scheduler.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import math
import numpy as np
from torch.optim.lr_scheduler import _LRScheduler
from DFAT.core.config import cfg
cla... | 6,838 | 30.086364 | 76 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/utils/model_load.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import torch
logger = logging.getLogger('global')
def check_keys(model, pretrained_state_dict):
c... | 3,091 | 34.953488 | 72 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/DFAT/utils/distributed.py | # Copyright (c) SenseTime. All Rights Reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import os
import socket
import logging
import torch
import torch.nn as nn
import torch.distributed as dist
from DFAT.ut... | 3,429 | 23.5 | 78 | py |
DFAT-Information-Fusion | DFAT-Information-Fusion-master/experiments/siam_base/convert_model.py | import torch
from collections import OrderedDict
model = torch.load('/vol/vssp/facer2vm/people/tianyang/Codes/DFAT/experiments/siammask_r50_l3_q/checkpoint_e0.pth', map_location=lambda storage, loc: storage)
new_model = OrderedDict()
for k, v in model['state_dict'].items():
if k.startswith('features.features'):
... | 851 | 37.727273 | 158 | py |
LineFormer | LineFormer-main/mmdetection/setup.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import os
import os.path as osp
import platform
import shutil
import sys
import warnings
from setuptools import find_packages, setup
import torch
from torch.utils.cpp_extension import (BuildExtension, CppExtension,
... | 7,887 | 34.692308 | 125 | py |
LineFormer | LineFormer-main/mmdetection/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... | 11,391 | 36.973333 | 79 | py |
LineFormer | LineFormer-main/mmdetection/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,148 | 36.342857 | 79 | py |
LineFormer | LineFormer-main/mmdetection/tools/deployment/test_torchserver.py | from argparse import ArgumentParser
import numpy as np
import requests
from mmdet.apis import inference_detector, init_detector, show_result_pyplot
from mmdet.core import bbox2result
def parse_args():
parser = ArgumentParser()
parser.add_argument('img', help='Image file')
parser.add_argument('config', h... | 2,357 | 30.44 | 77 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tools/deployment/pytorch2onnx.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import warnings
from functools import partial
import numpy as np
import onnx
import torch
from mmcv import Config, DictAction
from mmdet.core.export import build_model_from_cfg, preprocess_example_input
from mmdet.core.export.model_... | 11,729 | 33.098837 | 79 | py |
LineFormer | LineFormer-main/mmdetection/tools/misc/download_dataset.py | import argparse
from itertools import repeat
from multiprocessing.pool import ThreadPool
from pathlib import Path
from tarfile import TarFile
from zipfile import ZipFile
import torch
def parse_args():
parser = argparse.ArgumentParser(
description='Download datasets for training')
parser.add_argument(... | 3,374 | 31.76699 | 108 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/selfsup2mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
def moco_convert(src, dst):
"""Convert keys in pycls pretrained moco models to mmdet style."""
# load caffe model
moco_model = torch.load(src)
blobs = moco_model['state_dict']
# conver... | 1,243 | 27.930233 | 74 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/publish_model.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import subprocess
import torch
def parse_args():
parser = argparse.ArgumentParser(
description='Process a checkpoint to be published')
parser.add_argument('in_file', help='input checkpoint filename')
parser.add_argument('out_file', h... | 1,301 | 28.590909 | 78 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/regnet2mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
def convert_stem(model_key, model_weight, state_dict, converted_names):
new_key = model_key.replace('stem.conv', 'conv1')
new_key = new_key.replace('stem.bn', 'bn1')
state_dict[new_key] = mode... | 3,063 | 32.67033 | 77 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/upgrade_model_version.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import re
import tempfile
from collections import OrderedDict
import torch
from mmcv import Config
def is_head(key):
valid_head_list = [
'bbox_head', 'mask_head', 'semantic_head', 'grid_head', 'mask_iou_head'
]
return any(key.starts... | 6,848 | 31.459716 | 79 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/upgrade_ssd_version.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import tempfile
from collections import OrderedDict
import torch
from mmcv import Config
def parse_config(config_strings):
temp_file = tempfile.NamedTemporaryFile()
config_path = f'{temp_file.name}.py'
with open(config_path, 'w') as f:
... | 1,789 | 29.338983 | 78 | py |
LineFormer | LineFormer-main/mmdetection/tools/model_converters/detectron2pytorch.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import mmcv
import torch
arch_settings = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3)}
def convert_bn(blobs, state_dict, caffe_name, torch_name, converted_names):
# detectron replace bn with affine channel layer
sta... | 3,578 | 41.607143 | 78 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/.dev_scripts/benchmark_filter.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
def parse_args():
parser = argparse.ArgumentParser(description='Filter configs to train')
parser.add_argument(
'--basic-arch',
action='store_true',
help='to train models in basic arch')
... | 7,106 | 41.303571 | 92 | py |
LineFormer | LineFormer-main/mmdetection/.dev_scripts/gather_models.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import glob
import json
import os.path as osp
import shutil
import subprocess
from collections import OrderedDict
import mmcv
import torch
import yaml
def ordered_yaml_dump(data, stream=None, Dumper=yaml.SafeDumper, **kwds):
class OrderedDumper(Dum... | 12,487 | 35.408163 | 79 | py |
LineFormer | LineFormer-main/mmdetection/.dev_scripts/benchmark_inference_fps.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import mmcv
from mmcv import Config, DictAction
from mmcv.runner import init_dist
from terminaltables import GithubFlavoredMarkdownTable
from tools.analysis_tools.benchmark import repeat_measure_inference_speed
def parse... | 6,764 | 38.561404 | 79 | py |
LineFormer | LineFormer-main/mmdetection/.dev_scripts/batch_test_list.py | # Copyright (c) OpenMMLab. All rights reserved.
# yapf: disable
atss = dict(
config='configs/atss/atss_r50_fpn_1x_coco.py',
checkpoint='atss_r50_fpn_1x_coco_20200209-985f7bd0.pth',
eval='bbox',
metric=dict(bbox_mAP=39.4),
)
autoassign = dict(
config='configs/autoassign/autoassign_r50_fpn_8x2_1x_coco... | 12,707 | 34.3 | 117 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.utils import digit_version
from mmdet.models.losses import (BalancedL1Loss, CrossEntropyLoss, DiceLoss,
DistributionFocalLoss, FocalLoss,
GaussianFocalLoss,
... | 8,705 | 36.364807 | 79 | py |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_forward.py | # Copyright (c) OpenMMLab. All rights reserved.
"""pytest tests/test_forward.py."""
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _get_config_directory():
"""Find the predefined detector config directory."""
try:
# Assume we are running in the... | 31,150 | 32.280983 | 110 | py |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_necks.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.necks import (FPG, FPN, FPN_CARAFE, NASFCOS_FPN, NASFPN,
YOLOXPAFPN, ChannelMapper, CTResNetNeck,
DilatedEncoder... | 20,961 | 30.10089 | 79 | py |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_plugins.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv import ConfigDict
from mmcv.cnn import build_plugin_layer
from mmdet.models.plugins import DropBlock
def test_dropblock():
feat = torch.rand(1, 1, 11, 11)
drop_prob = 1.0
dropblock = DropBlock(drop_prob, block_size=11, w... | 6,057 | 35.059524 | 77 | py |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_loss_compatibility.py | # Copyright (c) OpenMMLab. All rights reserved.
"""pytest tests/test_loss_compatibility.py."""
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _get_config_directory():
"""Find the predefined detector config directory."""
try:
# Assume we are run... | 6,361 | 30.49505 | 79 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_backbones/test_hourglass.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones.hourglass import HourglassNet
def test_hourglass_backbone():
with pytest.raises(AssertionError):
# HourglassNet's num_stacks should larger than 0
HourglassNet(num_stacks=0)
with pytest.rais... | 1,464 | 28.3 | 65 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_backbones/test_efficientnet.py | import pytest
import torch
from mmdet.models.backbones import EfficientNet
def test_efficientnet_backbone():
"""Test EfficientNet backbone."""
with pytest.raises(AssertionError):
# EfficientNet arch should be a key in EfficientNet.arch_settings
EfficientNet(arch='c3')
model = EfficientNe... | 859 | 32.076923 | 73 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_backbones/test_hrnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.backbones.hrnet import HRModule, HRNet
from mmdet.models.backbones.resnet import BasicBlock, Bottleneck
@pytest.mark.parametrize('block', [BasicBlock, Bottleneck])
def test_hrmodule(block):
# Test multiscale forward
... | 3,089 | 26.589286 | 68 | py |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_backbones/test_csp_darknet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from torch.nn.modules.batchnorm import _BatchNorm
from mmdet.models.backbones.csp_darknet import CSPDarknet
from .utils import check_norm_state, is_norm
def test_csp_darknet_backbone():
with pytest.raises(ValueError):
# frozen_sta... | 4,117 | 34.196581 | 79 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/tests/test_models/test_backbones/test_detectors_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
from mmdet.models.backbones import DetectoRS_ResNet
def test_detectorrs_resnet_backbone():
detectorrs_cfg = dict(
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requi... | 1,611 | 32.583333 | 77 | py |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
LineFormer | LineFormer-main/mmdetection/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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.