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 |
|---|---|---|---|---|---|---|
ENCAS | ENCAS-main/subset_selectors/referencebased_subset_selector.py | import numpy as np
from pymoo.algorithms.nsga3 import ReferenceDirectionSurvival, get_extreme_points_c, get_nadir_point, \
associate_to_niches, calc_niche_count, niching
from pymoo.factory import get_reference_directions
from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting
from subset_selectors.bas... | 5,298 | 40.724409 | 119 | py |
ENCAS | ENCAS-main/subset_selectors/__init__.py | from .referencebased_subset_selector import ReferenceBasedSubsetSelector
# since only 1 subset selector is used in the paper, this level of indirectness is not needed
# But if I (or someone else) want to add another one later, this would be convenient.
selector_name_to_class = {
'reference': ReferenceBasedSubsetSe... | 477 | 42.454545 | 93 | py |
ENCAS | ENCAS-main/data_utils/viz_during_run.py | '''
These are just some useful commands for debugging
'''
im = images.cpu().detach().numpy()
def stats(x):
print(f'{x.mean()=:.3f} | {x.std()=:.3f} | {x.min()=:.3f} | {x.max()=:.3f}')
lb = labels.cpu().detach().numpy().transpose((0, 2, 3, 1))
def s(xs):
fig, axs = plt.subplots(1, len(xs))
fig.subplot... | 576 | 20.37037 | 80 | py |
ENCAS | ENCAS-main/data_utils/split_imagenet_train.py | '''
Separate a part of the train for setting batch norms. If you have the full ImageNet train set on your machine, this
is not necessary.
'''
import numpy as np
import os
from os.path import join
import random
import shutil
from pathlib import Path
random.seed(3179)
np.random.seed(3179)
n_select = 10
in_path = j... | 1,026 | 22.340909 | 115 | py |
ENCAS | ENCAS-main/data_utils/store_labels.py | import numpy as np
import torch
import yaml
from run_manager import get_run_config
from utils import NAT_PATH, NAT_DATA_PATH
import os
'''
Store labels of val & test sets for all the datasets.
To not specify all data-related information again, simply use any NAT config that uses the appropriate dataset
'''
def get_v... | 2,011 | 48.073171 | 110 | py |
ENCAS | ENCAS-main/data_providers/auto_augment_tf.py | # taken verbatim from https://github.com/facebookresearch/AttentiveNAS
""" Auto Augment
Implementation adapted from timm: https://github.com/rwightman/pytorch-image-models
"""
import random
import math
from PIL import Image, ImageOps, ImageEnhance
import PIL
_PIL_VER = tuple([int(x) for x in PIL.__version__.split('... | 13,406 | 32.185644 | 105 | py |
ENCAS | ENCAS-main/data_providers/cifar.py | import functools
import math
import numpy as np
import torchvision
import torch.utils.data
import torchvision.transforms as transforms
from ofa.imagenet_classification.data_providers.imagenet import DataProvider
from timm.data import rand_augment_transform
import utils_train
from utils import _pil_interp
from dynam... | 11,902 | 40.618881 | 126 | py |
ENCAS | ENCAS-main/data_providers/imagenet.py | import functools
import warnings
import os
import math
import numpy as np
import torch.utils.data
import torchvision
import torchvision.transforms as transforms
import torchvision.datasets as datasets
from ofa.imagenet_classification.data_providers.imagenet import DataProvider
import utils
import utils_train
from dy... | 14,256 | 46.052805 | 131 | py |
LATTE | LATTE-master/tools/DLtab/DLtab.py | #!/usr/bin/env python
'''
Convert DFTB parameters in skf format into LATTE's table format
Usage
-----
```bash
DLtab.py <skf folder> <LATTE parameter folder>
```
Three files will be generate for LATTE, electrons.dat, bondints.table and ppots.dftb.
[note for electron.dat file]
* The spin parameter is not included in... | 10,808 | 30.97929 | 95 | py |
LATTE | LATTE-master/tests/test-optim.py | #!/usr/bin/env python
def compare_coordinates(reference, current, reltol):
"""Compare coordinates.
Given a reference output and the current output, compare the
coordinates to within the relative tolerance given by reltol.
"""
import re
position = re.compile("^\s*([a-zA-Z]+)\s+([0-9eE.+-]+)\s... | 3,418 | 34.614583 | 102 | py |
LATTE | LATTE-master/tests/test-energy.py | #!/usr/bin/env python
def compare_MD(reference, current, reltol):
"""Compare MD energies.
Given a reference output and the current output, compare the MD
energies to within the relative tolerance given by reltol.
"""
import sys
#energy = re.compile("MD_data\s+([0-9eE.+-]+)\s+([0-9eE.+-]+)")
... | 2,228 | 30.842857 | 110 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/LFOICA.py | import numpy as np
import torch
import torch.nn as nn
from torch import Tensor
import torch.optim as optim
import torch.nn.functional as F
from libs.distance_measure.mmd import mix_rbf_mmd2
from libs.common_utils import cos_act, normalize_mixing_matrix
from scipy.stats import semicircular
from scipy.stats import hypsec... | 6,446 | 41.695364 | 118 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/pytorch_pgm.py | from torch.optim.sgd import SGD
import torch
from torch.optim.optimizer import required
class PGM(SGD):
def __init__(self, params, proxs, lr=required, reg_lambda=0, momentum=0, dampening=0,
nesterov=False):
kwargs = dict(lr=lr, momentum=momentum, dampening=dampening, weight_decay=0, nestero... | 1,798 | 34.98 | 125 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/common_utils.py | import torch
import numpy as np
def gumbel_softmax(p, device, sample_num=1, tau=0.2):
g = np.random.uniform(0.0001, 0.9999, [sample_num, p.shape[0]])
g = -torch.log(-torch.log(torch.Tensor(g)))
numerator = torch.exp((torch.log(p).repeat(sample_num, 1) + g.to(device)) / tau)
denominator = torch.sum(num... | 1,497 | 33.045455 | 104 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/__init__.py | 0 | 0 | 0 | py | |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/distance_measure/kernel_density.py | import torch
def kernel_density_loss(X, Y, sigma_list):
assert (X.size(0) == Y.size(0))
m = X.size(0)
n = X.size(1)
expand_X = X.unsqueeze(2).expand(-1, -1, m).permute(0, 2, 1)
expand_Y = Y.unsqueeze(2).expand(-1, -1, m).permute(2, 0, 1)
X_Y = expand_X - expand_Y
X_Y_norm = torch.zeros((m, ... | 729 | 37.421053 | 113 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/distance_measure/mmd.py | #!/usr/bin/env python
# encoding: utf-8
import torch
min_var_est = 1e-8
# Consider linear time MMD with a linear kernel:
# K(f(x), f(y)) = f(x)^Tf(y)
# h(z_i, z_j) = k(x_i, x_j) + k(y_i, y_j) - k(x_i, y_j) - k(x_j, y_i)
# = [f(x_i) - f(y_i)]^T[f(x_j) - f(y_j)]
#
# f_of_X: batch_size * k
# f_of_Y: batch... | 7,282 | 37.739362 | 131 | py |
Likelihood-free_OICA | Likelihood-free_OICA-master/libs/distance_measure/__init__.py | 0 | 0 | 0 | py | |
DSLA-DSLA | DSLA-DSLA/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,
... | 8,008 | 34.914798 | 125 | py |
DSLA-DSLA | DSLA-DSLA/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.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dis... | 9,774 | 37.789683 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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
from mmcv import Config, DictAction
from mmcv.runner import get_dist_info, init_dist
from mmcv.utils import get_git_hash
from mmdet import __version__
from m... | 7,317 | 36.147208 | 115 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/tools/deployment/test.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import mmcv
from mmcv import Config, DictAction
from mmcv.parallel import MMDataParallel
from mmdet.apis import single_gpu_test
from mmdet.datasets import (build_dataloader, build_dataset,
replace_ImageToTensor)
def parse_ar... | 5,481 | 37.069444 | 78 | py |
DSLA-DSLA | DSLA-DSLA/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... | 8,516 | 32.4 | 78 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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,781 | 33.052023 | 79 | py |
DSLA-DSLA | DSLA-DSLA/tools/misc/print_config.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import warnings
from mmcv import Config, DictAction
def parse_args():
parser = argparse.ArgumentParser(description='Print the whole config')
parser.add_argument('config', help='config file path')
parser.add_argument(
'--options',
... | 1,697 | 31.653846 | 78 | py |
DSLA-DSLA | DSLA-DSLA/tools/misc/browse_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
from collections import Sequence
from pathlib import Path
import mmcv
from mmcv import Config, DictAction
from mmdet.core.utils import mask2ndarray
from mmdet.core.visualization import imshow_det_bboxes
from mmdet.datasets.builder import build_... | 3,261 | 29.773585 | 78 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/tools/analysis_tools/analyze_results.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
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 build_dataset, get_loading_pipeline
... | 6,897 | 33.49 | 78 | py |
DSLA-DSLA | DSLA-DSLA/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
def parse_args():
parser = argparse.ArgumentParser(description='Evaluate metric of the '
'results saved in pkl format')
... | 2,919 | 35.049383 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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,416 | 33.132979 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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,161 | 34.477089 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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,995 | 29.571429 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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... | 6,300 | 33.812155 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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
def parse_args():... | 9,603 | 35.656489 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/convert_train_benchmark_script.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
def parse_args():
parser = argparse.ArgumentParser(
description='Convert benchmark model json to script')
parser.add_argument(
'txt_path', type=str, help='txt path output by benchmark_filter')
p... | 3,307 | 32.08 | 74 | py |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/gather_test_benchmark_metric.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import glob
import os.path as osp
import mmcv
from mmcv import Config
def parse_args():
parser = argparse.ArgumentParser(
description='Gather benchmarked models metric')
parser.add_argument('config', help='test config file path')
par... | 3,916 | 39.381443 | 79 | py |
DSLA-DSLA | DSLA-DSLA/.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,101 | 41.27381 | 92 | py |
DSLA-DSLA | DSLA-DSLA/.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... | 10,489 | 34.924658 | 79 | py |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/test_init_backbone.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Check out backbone whether successfully load pretrained checkpoint."""
import copy
import os
from os.path import dirname, exists, join
import pytest
from mmcv import Config, ProgressBar
from mmcv.runner import _load_checkpoint
from mmdet.models import build_detector
... | 6,625 | 35.406593 | 78 | py |
DSLA-DSLA | DSLA-DSLA/.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,763 | 38.788235 | 79 | py |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/gather_train_benchmark_metric.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import glob
import os.path as osp
import mmcv
from gather_models import get_final_results
try:
import xlrd
except ImportError:
xlrd = None
try:
import xlutils
from xlutils.copy import copy
except ImportError:
xlutils = None
def pars... | 5,843 | 37.701987 | 79 | py |
DSLA-DSLA | DSLA-DSLA/.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 |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/benchmark_test_image.py | # Copyright (c) OpenMMLab. All rights reserved.
import logging
import os.path as osp
from argparse import ArgumentParser
from mmcv import Config
from mmdet.apis import inference_detector, init_detector, show_result_pyplot
from mmdet.utils import get_root_logger
def parse_args():
parser = ArgumentParser()
pa... | 3,674 | 34.679612 | 77 | py |
DSLA-DSLA | DSLA-DSLA/.dev_scripts/convert_test_benchmark_script.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
from mmcv import Config
def parse_args():
parser = argparse.ArgumentParser(
description='Convert benchmark model list to script')
parser.add_argument('config', help='test config file path')
parser.add_... | 3,604 | 29.041667 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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,152 | 39.733871 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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,
... | 7,860 | 35.393519 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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... | 23,230 | 32.092593 | 110 | py |
DSLA-DSLA | DSLA-DSLA/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 (FPN, YOLOXPAFPN, ChannelMapper, CTResNetNeck,
DilatedEncoder, SSDNeck, YOLOV3Neck)
def test_fpn():
"""Tests fpn."""
s = ... | 13,273 | 31.614251 | 79 | py |
DSLA-DSLA | DSLA-DSLA/tests/test_models/test_plugins.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
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, warmup_iters=0)
out_feat = dropblock(feat)
assert (out_feat =... | 840 | 27.033333 | 67 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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,648 | 30.915663 | 79 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/tests/test_models/test_backbones/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import check_norm_state, is_block, is_norm
__all__ = ['is_block', 'is_norm', 'check_norm_state']
| 158 | 30.8 | 54 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/tests/test_models/test_utils/test_model_misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmdet.models.utils import interpolate_as
def test_interpolate_as():
source = torch.rand((1, 5, 4, 4))
target = torch.rand((1, 1, 16, 16))
# Test 4D source and target
result = interpolate_as(source, target)
asser... | 805 | 27.785714 | 54 | py |
DSLA-DSLA | DSLA-DSLA/tests/test_models/test_utils/test_se_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmdet.models.utils import SELayer
def test_se_layer():
with pytest.raises(AssertionError):
# act_cfg sequence length must equal to 2
SELayer(channels=32, act_cfg=(dict(type='ReLU'), ))
with pytest.raises(Assertio... | 674 | 26 | 76 | py |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
DSLA-DSLA | DSLA-DSLA/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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.