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 |
|---|---|---|---|---|---|---|
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_beit.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones.beit import BEiT
from .utils import check_norm_state
def test_beit_backbone():
with pytest.raises(TypeError):
# pretrained must be a string path
model = BEiT()
model.init_weights(pretrai... | 5,498 | 29.214286 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_bisenetv1.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import BiSeNetV1
from mmseg.models.backbones.bisenetv1 import (AttentionRefinementModule,
ContextPath, FeatureFusionModule,
... | 3,410 | 30.009091 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_bisenetv2.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.cnn import ConvModule
from mmseg.models.backbones import BiSeNetV2
from mmseg.models.backbones.bisenetv2 import (BGALayer, DetailBranch,
SemanticBranch)
def test_bisenetv2_backbone():
# Test BiSeN... | 1,843 | 30.793103 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_blocks.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import pytest
import torch
from mmcv.utils import TORCH_VERSION, digit_version
from mmseg.models.utils import (InvertedResidual, InvertedResidualV3, SELayer,
make_divisible)
def test_make_divisible():
# test with min_valu... | 7,301 | 38.048128 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_cgnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import CGNet
from mmseg.models.backbones.cgnet import (ContextGuidedBlock,
GlobalContextExtractor)
def test_cgnet_GlobalContextExtractor():
block = GlobalContextExtract... | 5,214 | 33.309211 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_erfnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import ERFNet
from mmseg.models.backbones.erfnet import (DownsamplerBlock, NonBottleneck1d,
UpsamplerBlock)
def test_erfnet_backbone():
# Test ERFNet Standard Forward.... | 5,419 | 35.870748 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_fast_scnn.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import FastSCNN
def test_fastscnn_backbone():
with pytest.raises(AssertionError):
# Fast-SCNN channel constraints.
FastSCNN(
3, (32, 48),
64, (64, 96, 128), (2, 2, 1),
... | 1,189 | 26.674419 | 63 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_hrnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.utils.parrots_wrapper import _BatchNorm
from mmseg.models.backbones.hrnet import HRModule, HRNet
from mmseg.models.backbones.resnet import BasicBlock, Bottleneck
@pytest.mark.parametrize('block', [BasicBlock, Bottleneck])
def test_h... | 4,266 | 28.427586 | 68 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_icnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import ICNet
def test_icnet_backbone():
with pytest.raises(TypeError):
# Must give backbone dict in config file.
ICNet(
in_channels=3,
layer_channels=(128, 512),
... | 1,526 | 28.941176 | 74 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_mae.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones.mae import MAE
from .utils import check_norm_state
def test_mae_backbone():
with pytest.raises(TypeError):
# pretrained must be a string path
model = MAE()
model.init_weights(pretrained=... | 5,918 | 29.668394 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_mit.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import MixVisionTransformer
from mmseg.models.backbones.mit import (EfficientMultiheadAttention, MixFFN,
TransformerEncoderLayer)
def test_mit():
with pytest.raises(TypeE... | 4,378 | 34.601626 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_mobilenet_v3.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import MobileNetV3
def test_mobilenet_v3():
with pytest.raises(AssertionError):
# check invalid arch
MobileNetV3('big')
with pytest.raises(AssertionError):
# check invalid reduction... | 1,961 | 27.852941 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_mscan.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.backbones import MSCAN
from mmseg.models.backbones.mscan import (MSCAAttention, MSCASpatialAttention,
OverlapPatchEmbed, StemConv)
def test_mscan_backbone():
# Test MSCAN Standard Forward
... | 2,378 | 32.985714 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_resnest.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import ResNeSt
from mmseg.models.backbones.resnest import Bottleneck as BottleneckS
def test_resnest_bottleneck():
with pytest.raises(AssertionError):
# Style must be in ['pytorch', 'caffe']
Bot... | 1,468 | 31.644444 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.ops import DeformConv2dPack
from mmcv.utils.parrots_wrapper import _BatchNorm
from torch.nn.modules import AvgPool2d, GroupNorm
from mmseg.models.backbones import ResNet, ResNetV1d
from mmseg.models.backbones.resnet import BasicBlock,... | 20,399 | 34.416667 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_resnext.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import ResNeXt
from mmseg.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... | 1,982 | 30.47619 | 72 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_stdc.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import STDCContextPathNet
from mmseg.models.backbones.stdc import (AttentionRefinementModule,
FeatureFusionModule, STDCModule,
STDCNet... | 4,458 | 32.780303 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_swin.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones.swin import SwinBlock, SwinTransformer
def test_swin_block():
# test SwinBlock structure and forward
block = SwinBlock(embed_dims=32, num_heads=4, feedforward_channels=128)
assert block.ffn.embed_dims =... | 3,209 | 30.782178 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_timm_backbone.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones import TIMMBackbone
from .utils import check_norm_state
def test_timm_backbone():
with pytest.raises(TypeError):
# pretrained must be a string path
model = TIMMBackbone()
model.init_weig... | 4,674 | 33.88806 | 77 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_twins.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones.twins import (PCPVT, SVT,
ConditionalPositionEncoding,
LocallyGroupedSelfAttention)
def test_pcpvt():
# Test normal input
... | 5,967 | 33.697674 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_unet.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.cnn import ConvModule
from mmseg.models.backbones.unet import (BasicConvBlock, DeconvModule,
InterpConv, UNet, UpConvBlock)
from mmseg.ops import Upsample
from .utils import check_norm_state
... | 30,122 | 35.601458 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/test_vit.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.backbones.vit import (TransformerEncoderLayer,
VisionTransformer)
from .utils import check_norm_state
def test_vit_backbone():
with pytest.raises(TypeError):
# pretrained m... | 6,203 | 32.354839 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from torch.nn.modules import GroupNorm
from torch.nn.modules.batchnorm import _BatchNorm
from mmseg.models.backbones.resnet import BasicBlock, Bottleneck
from mmseg.models.backbones.resnext import Bottleneck as BottleneckX
def is_block(modules):
"""Che... | 1,306 | 28.704545 | 71 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_ann_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import ANNHead
from .utils import to_cuda
def test_ann_head():
inputs = [torch.randn(1, 4, 45, 45), torch.randn(1, 8, 21, 21)]
head = ANNHead(
in_channels=[4, 8],
channels=2,
num_classes=19,
... | 538 | 24.666667 | 67 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_apc_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import APCHead
from .utils import _conv_has_norm, to_cuda
def test_apc_head():
with pytest.raises(AssertionError):
# pool_scales must be list|tuple
APCHead(in_channels=8, channels=2, num_cla... | 1,751 | 28.2 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_aspp_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import ASPPHead, DepthwiseSeparableASPPHead
from .utils import _conv_has_norm, to_cuda
def test_aspp_head():
with pytest.raises(AssertionError):
# pool_scales must be list|tuple
ASPPHead(in_... | 2,577 | 32.480519 | 74 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_cc_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import CCHead
from .utils import to_cuda
def test_cc_head():
head = CCHead(in_channels=16, channels=8, num_classes=19)
assert len(head.convs) == 2
assert hasattr(head, 'cca')
if not torch.cuda.is... | 546 | 27.789474 | 61 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_da_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import DAHead
from .utils import to_cuda
def test_da_head():
inputs = [torch.randn(1, 16, 23, 23)]
head = DAHead(in_channels=16, channels=8, num_classes=19, pam_channels=8)
if torch.cuda.is_available():
h... | 649 | 31.5 | 77 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_decode_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from unittest.mock import patch
import pytest
import torch
from mmseg.models.decode_heads.decode_head import BaseDecodeHead
from .utils import to_cuda
@patch.multiple(BaseDecodeHead, __abstractmethods__=set())
def test_decode_head():
with pytest.raises(AssertionE... | 6,590 | 36.02809 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_dm_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import DMHead
from .utils import _conv_has_norm, to_cuda
def test_dm_head():
with pytest.raises(AssertionError):
# filter_sizes must be list|tuple
DMHead(in_channels=8, channels=4, num_class... | 1,754 | 28.25 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_dnl_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import DNLHead
from .utils import to_cuda
def test_dnl_head():
# DNL with 'embedded_gaussian' mode
head = DNLHead(in_channels=8, channels=4, num_classes=19)
assert len(head.convs) == 2
assert hasattr(head, 'dn... | 1,584 | 34.222222 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_dpt_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import DPTHead
def test_dpt_head():
with pytest.raises(AssertionError):
# input_transform must be 'multiple_select'
head = DPTHead(
in_channels=[768, 768, 768, 768],
... | 1,368 | 26.38 | 54 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_ema_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import EMAHead
from .utils import to_cuda
def test_emanet_head():
head = EMAHead(
in_channels=4,
ema_channels=3,
channels=2,
num_stages=3,
num_bases=2,
num_classes=19)
f... | 647 | 26 | 57 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_enc_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import EncHead
from .utils import to_cuda
def test_enc_head():
# with se_loss, w.o. lateral
inputs = [torch.randn(1, 8, 21, 21)]
head = EncHead(in_channels=[8], channels=4, num_classes=19, in_index=[-1])
if to... | 1,613 | 32.625 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_fcn_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
from mmcv.utils.parrots_wrapper import SyncBatchNorm
from mmseg.models.decode_heads import DepthwiseSeparableFCNHead, FCNHead
from .utils import to_cuda
def test_fcn_head():
w... | 4,511 | 33.181818 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_gc_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import GCHead
from .utils import to_cuda
def test_gc_head():
head = GCHead(in_channels=4, channels=4, num_classes=19)
assert len(head.convs) == 2
assert hasattr(head, 'gc_block')
inputs = [torch.randn(1, 4, 23... | 491 | 27.941176 | 60 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_ham_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import LightHamHead
from .utils import _conv_has_norm, to_cuda
ham_norm_cfg = dict(type='GN', num_groups=32, requires_grad=True)
def test_ham_head():
# test without sync_bn
head = LightHamHead(
in_channels=[... | 1,259 | 27 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_isa_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import ISAHead
from .utils import to_cuda
def test_isa_head():
inputs = [torch.randn(1, 8, 23, 23)]
isa_head = ISAHead(
in_channels=8,
channels=4,
num_classes=19,
isa_channels=4,
... | 521 | 23.857143 | 60 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_knet_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads.knet_head import (IterativeDecodeHead,
KernelUpdateHead)
from .utils import to_cuda
num_stages = 3
conv_kernel_size = 1
kernel_updator_cfg = dict(
type='KernelUpdator',
... | 6,292 | 31.107143 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_lraspp_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import LRASPPHead
def test_lraspp_head():
with pytest.raises(ValueError):
# check invalid input_transform
LRASPPHead(
in_channels=(4, 4, 123),
in_index=(0, 1, 2),
... | 2,093 | 29.347826 | 77 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_nl_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import NLHead
from .utils import to_cuda
def test_nl_head():
head = NLHead(in_channels=8, channels=4, num_classes=19)
assert len(head.convs) == 2
assert hasattr(head, 'nl_block')
inputs = [torch.randn(1, 8, 23... | 491 | 27.941176 | 60 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_ocr_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import FCNHead, OCRHead
from .utils import to_cuda
def test_ocr_head():
inputs = [torch.randn(1, 8, 23, 23)]
ocr_head = OCRHead(
in_channels=8, channels=4, num_classes=19, ocr_channels=8)
fcn_head = FCNHe... | 637 | 30.9 | 66 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_point_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmcv.utils import ConfigDict
from mmseg.models.decode_heads import FCNHead, PointHead
from .utils import to_cuda
def test_point_head():
inputs = [torch.randn(1, 32, 45, 45)]
point_head = PointHead(
in_channels=[32], in_index=[0], chan... | 2,340 | 36.758065 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_psa_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import PSAHead
from .utils import _conv_has_norm, to_cuda
def test_psa_head():
with pytest.raises(AssertionError):
# psa_type must be in 'bi-direction', 'collect', 'distribute'
PSAHead(
... | 3,617 | 28.414634 | 70 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_psp_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import PSPHead
from .utils import _conv_has_norm, to_cuda
def test_psp_head():
with pytest.raises(AssertionError):
# pool_scales must be list|tuple
PSPHead(in_channels=4, channels=2, num_cla... | 1,131 | 29.594595 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_segformer_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import SegformerHead
def test_segformer_head():
with pytest.raises(AssertionError):
# `in_channels` must have same length as `in_index`
SegformerHead(
in_channels=(1, 2, 3), in_in... | 1,204 | 28.390244 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_segmenter_mask_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import SegmenterMaskTransformerHead
from .utils import _conv_has_norm, to_cuda
def test_segmenter_mask_transformer_head():
head = SegmenterMaskTransformerHead(
in_channels=2,
channels=2,
num_classe... | 697 | 26.92 | 66 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_setr_mla_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import SETRMLAHead
from .utils import to_cuda
def test_setr_mla_head(capsys):
with pytest.raises(AssertionError):
# MLA requires input multiple stage feature information.
SETRMLAHead(in_chan... | 1,887 | 28.5 | 77 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_setr_up_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import SETRUPHead
from .utils import to_cuda
def test_setr_up_head(capsys):
with pytest.raises(AssertionError):
# kernel_size must be [1/3]
SETRUPHead(num_classes=19, kernel_size=2)
wit... | 1,616 | 27.368421 | 67 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_stdc_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.decode_heads import STDCHead
from .utils import to_cuda
def test_stdc_head():
inputs = [torch.randn(1, 32, 21, 21)]
head = STDCHead(
in_channels=32,
channels=8,
num_convs=1,
num_classes=2,
i... | 1,068 | 32.40625 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/test_uper_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.decode_heads import UPerHead
from .utils import _conv_has_norm, to_cuda
def test_uper_head():
with pytest.raises(AssertionError):
# fpn_in_channels must be list|tuple
UPerHead(in_channels=4, channels=2, ... | 1,066 | 28.638889 | 74 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_heads/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import ConvModule
from mmcv.utils.parrots_wrapper import SyncBatchNorm
def _conv_has_norm(module, sync_bn):
for m in module.modules():
if isinstance(m, ConvModule):
if not m.with_norm:
return False
if syn... | 614 | 25.73913 | 55 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_ce_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.losses.cross_entropy_loss import _expand_onehot_labels
@pytest.mark.parametrize('use_sigmoid', [True, False])
@pytest.mark.parametrize('reduction', ('mean', 'sum', 'none'))
@pytest.mark.parametrize('avg_non_ignore', [True, F... | 11,382 | 37.586441 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_dice_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
def test_dice_lose():
from mmseg.models import build_loss
# test dice loss with loss_type = 'multi_class'
loss_cfg = dict(
type='DiceLoss',
reduction='none',
class_weight=[1.0, 2.0, 3.0],
loss_weight=1.0,
... | 2,207 | 26.949367 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_focal_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
import torch.nn.functional as F
from mmseg.models import build_loss
# test focal loss with use_sigmoid=False
def test_use_sigmoid():
# can't init with use_sigmoid=True
with pytest.raises(AssertionError):
loss_cfg = dict(type='... | 7,673 | 34.364055 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_lovasz_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
def test_lovasz_loss():
from mmseg.models import build_loss
# loss_type should be 'binary' or 'multi_class'
with pytest.raises(AssertionError):
loss_cfg = dict(
type='LovaszLoss',
loss_type='Binary'... | 3,632 | 29.529412 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_tversky_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
def test_tversky_lose():
from mmseg.models import build_loss
# test alpha + beta != 1
with pytest.raises(AssertionError):
loss_cfg = dict(
type='TverskyLoss',
class_weight=[1.0, 2.0, 3.0],
... | 2,699 | 28.347826 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_losses/test_utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from mmseg.models.losses import Accuracy, reduce_loss, weight_reduce_loss
def test_weight_reduce_loss():
loss = torch.rand(1, 3, 4, 4)
weight = torch.zeros(1, 3, 4, 4)
weight[:, :, :2, :2] = 1
# test reduce... | 4,481 | 33.476923 | 74 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_feature2pyramid.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models import Feature2Pyramid
def test_feature2pyramid():
# test
rescales = [4, 2, 1, 0.5]
embed_dim = 64
inputs = [torch.randn(1, embed_dim, 32, 32) for i in range(len(rescales))]
fpn = Feature2Pyramid(
... | 1,383 | 34.487179 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_fpn.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models import FPN
def test_fpn():
in_channels = [64, 128, 256, 512]
inputs = [
torch.randn(1, c, 56 // 2**i, 56 // 2**i)
for i, c in enumerate(in_channels)
]
fpn = FPN(in_channels, 64, len(in_channels))
outpu... | 967 | 30.225806 | 60 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_ic_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.necks import ICNeck
from mmseg.models.necks.ic_neck import CascadeFeatureFusion
from ..test_heads.utils import _conv_has_norm, to_cuda
def test_ic_neck():
# test with norm_cfg
neck = ICNeck(
in_channels=(4, 1... | 1,559 | 27.888889 | 59 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_jpu.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.necks import JPU
def test_fastfcn_neck():
# Test FastFCN Standard Forward
model = JPU(
in_channels=(64, 128, 256),
mid_channels=64,
start_level=0,
end_level=-1,
dilations=(1, 2... | 1,415 | 29.12766 | 72 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_mla_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models import MLANeck
def test_mla():
in_channels = [4, 4, 4, 4]
mla = MLANeck(in_channels, 32)
inputs = [torch.randn(1, c, 12, 12) for i, c in enumerate(in_channels)]
outputs = mla(inputs)
assert outputs[0].shape == torch.S... | 518 | 29.529412 | 75 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_necks/test_multilevel_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models import MultiLevelNeck
def test_multilevel_neck():
# Test init_weights
MultiLevelNeck([266], 32).init_weights()
# Test multi feature maps
in_channels = [32, 64, 128, 256]
inputs = [torch.randn(1, c, 14, 14) for i, c i... | 1,051 | 30.878788 | 75 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_segmentors/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_segmentors/test_cascade_encoder_decoder.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv import ConfigDict
from mmseg.models import build_segmentor
from .utils import _segmentor_forward_train_test
def test_cascade_encoder_decoder():
# test 1 decode head, w.o. aux head
cfg = ConfigDict(
type='CascadeEncoderDecoder',
num_st... | 1,828 | 30.534483 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_segmentors/test_encoder_decoder.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv import ConfigDict
from mmseg.models import build_segmentor
from .utils import _segmentor_forward_train_test
def test_encoder_decoder():
# test 1 decode head, w.o. aux head
cfg = ConfigDict(
type='EncoderDecoder',
backbone=dict(type='... | 1,717 | 30.814815 | 76 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_segmentors/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from torch import nn
from mmseg.models import BACKBONES, HEADS
from mmseg.models.decode_heads.cascade_decode_head import BaseCascadeDecodeHead
from mmseg.models.decode_heads.decode_head import BaseDecodeHead
def _demo_mm_inputs(input_sha... | 4,174 | 28.609929 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_utils/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_utils/test_embed.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmseg.models.utils.embed import AdaptivePadding, PatchEmbed, PatchMerging
def test_adaptive_padding():
for padding in ('same', 'corner'):
kernel_size = 16
stride = 16
dilation = 1
input = torch.rand(1... | 12,979 | 27.095238 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_utils/test_shape_convert.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmseg.models.utils import (nchw2nlc2nchw, nchw_to_nlc, nlc2nchw2nlc,
nlc_to_nchw)
def test_nchw2nlc2nchw():
# Test nchw2nlc2nchw function
shape_nchw = (4, 2, 5, 5)
shape_nlc = (4, 25, 2)
def test_func(x... | 2,423 | 25.933333 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_utils/test_misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
from mmseg.utils import find_latest_checkpoint
def test_find_latest_checkpoint():
with tempfile.TemporaryDirectory() as tempdir:
# no checkpoints in the path
path = tempdir
latest = find_latest_checkpoin... | 1,454 | 34.487805 | 73 | py |
mmsegmentation | mmsegmentation-master/tests/test_utils/test_set_env.py | # Copyright (c) OpenMMLab. All rights reserved.
import multiprocessing as mp
import os
import platform
import cv2
import pytest
from mmcv import Config
from mmseg.utils import setup_multi_processes
@pytest.mark.parametrize('workers_per_gpu', (0, 2))
@pytest.mark.parametrize(('valid', 'env_cfg'), [(True,
... | 3,616 | 41.05814 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_utils/test_util_distribution.py | # Copyright (c) OpenMMLab. All rights reserved.
from unittest.mock import MagicMock, patch
import mmcv
import torch
import torch.nn as nn
from mmcv.parallel import (MMDataParallel, MMDistributedDataParallel,
is_module_wrapper)
from mmseg import digit_version
from mmseg.utils import build_dd... | 2,797 | 32.309524 | 74 | py |
mmsegmentation | mmsegmentation-master/tools/analyze_logs.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Modified from https://github.com/open-
mmlab/mmdetection/blob/master/tools/analysis_tools/analyze_logs.py."""
import argparse
import json
from collections import defaultdict
import matplotlib.pyplot as plt
import seaborn as sns
def plot_curve(log_dicts, args):
i... | 4,459 | 33.573643 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/benchmark.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import time
import mmcv
import numpy as np
import torch
from mmcv import Config
from mmcv.parallel import MMDataParallel
from mmcv.runner import load_checkpoint, wrap_fp16_model
from mmseg.datasets import build_dataloader, build_dat... | 4,328 | 34.77686 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/browse_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import warnings
from pathlib import Path
import mmcv
import numpy as np
from mmcv import Config, DictAction
from mmseg.datasets.builder import build_dataset
def parse_args():
parser = argparse.ArgumentParser(description='Browse a dataset'... | 6,231 | 33.054645 | 78 | py |
mmsegmentation | mmsegmentation-master/tools/confusion_matrix.py | # Copyright (c) OpenMMLab. All rights reserved.
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 mmseg.datasets import build_dataset
def parse_args():
parser = argparse.ArgumentParser(
... | 6,368 | 32.87766 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/deploy_test.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import shutil
import warnings
from typing import Any, Iterable
import mmcv
import numpy as np
import torch
from mmcv.parallel import MMDataParallel
from mmcv.runner import get_dist_info
from mmcv.utils import DictAction
fr... | 13,175 | 37.867257 | 78 | py |
mmsegmentation | mmsegmentation-master/tools/dist_test.sh | 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_ADDR \
--nproc_per... | 458 | 20.857143 | 43 | sh |
mmsegmentation | mmsegmentation-master/tools/dist_train.sh | 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 \
--nproc_per_node=$GPUS \
... | 421 | 22.444444 | 43 | sh |
mmsegmentation | mmsegmentation-master/tools/get_flops.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from mmcv import Config
from mmcv.cnn import get_model_complexity_info
from mmseg.models import build_segmentor
def parse_args():
parser = argparse.ArgumentParser(
description='Get the FLOPs of a segmentor')
parser.add_argument('config'... | 1,724 | 27.278689 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/imagenets_submit.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import shutil
def parse_args():
parser = argparse.ArgumentParser(description='Inference')
parser.add_argument(
'--imgfile_prefix',
type=str,
required=True,
help='The prefix of output image file')
pars... | 1,864 | 30.610169 | 78 | py |
mmsegmentation | mmsegmentation-master/tools/model_ensemble.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import mmcv
import numpy as np
import torch
from mmcv.parallel import MMDataParallel
from mmcv.parallel.scatter_gather import scatter_kwargs
from mmcv.runner import load_checkpoint, wrap_fp16_model
from PIL import Image
from mmseg.datasets impo... | 3,780 | 29.991803 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/onnx2tensorrt.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import warnings
from typing import Iterable, Optional, Union
import matplotlib.pyplot as plt
import mmcv
import numpy as np
import onnxruntime as ort
import torch
from mmcv.ops import get_onnxruntime_op_path
from mmcv.tenso... | 9,866 | 33.024138 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/print_config.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import warnings
from mmcv import Config, DictAction
from mmseg.apis import init_segmentor
def parse_args():
parser = argparse.ArgumentParser(description='Print the whole config')
parser.add_argument('config', help='config file path')
parser... | 2,584 | 35.928571 | 78 | py |
mmsegmentation | mmsegmentation-master/tools/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,076 | 28.108108 | 77 | py |
mmsegmentation | mmsegmentation-master/tools/pytorch2onnx.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import warnings
from functools import partial
import mmcv
import numpy as np
import onnxruntime as rt
import torch
import torch._C
import torch.serialization
from mmcv import DictAction
from mmcv.onnx import register_extra_symbolics
from mmcv.runner impor... | 14,147 | 33.847291 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/pytorch2torchscript.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import mmcv
import numpy as np
import torch
import torch._C
import torch.serialization
from mmcv.runner import load_checkpoint
from torch import nn
from mmseg.models import build_segmentor
torch.manual_seed(3)
def digit_version(version_str):
digit... | 6,057 | 31.569892 | 77 | py |
mmsegmentation | mmsegmentation-master/tools/slurm_test.sh | #!/usr/bin/env bash
set -x
PARTITION=$1
JOB_NAME=$2
CONFIG=$3
CHECKPOINT=$4
GPUS=${GPUS:-4}
GPUS_PER_NODE=${GPUS_PER_NODE:-4}
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 |
mmsegmentation | mmsegmentation-master/tools/slurm_train.sh | #!/usr/bin/env bash
set -x
PARTITION=$1
JOB_NAME=$2
CONFIG=$3
GPUS=${GPUS:-4}
GPUS_PER_NODE=${GPUS_PER_NODE:-4}
CPUS_PER_TASK=${CPUS_PER_TASK:-5}
SRUN_ARGS=${SRUN_ARGS:-""}
PY_ARGS=${@:4}
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
srun -p ${PARTITION} \
--job-name=${JOB_NAME} \
--gres=gpu:${GPUS_PER_NODE} \... | 539 | 21.5 | 68 | sh |
mmsegmentation | mmsegmentation-master/tools/test.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import shutil
import time
import warnings
import mmcv
import torch
from mmcv.cnn.utils import revert_sync_batchnorm
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
wrap_fp16_mode... | 12,704 | 38.212963 | 79 | py |
mmsegmentation | mmsegmentation-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.cnn.utils import revert_sync_batchnorm
from mmcv.runner import get_dist_info, init_dist
from mmcv.utils import Conf... | 9,480 | 37.54065 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/convert_datasets/chase_db1.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import tempfile
import zipfile
import mmcv
CHASE_DB1_LEN = 28 * 3
TRAINING_LEN = 60
def parse_args():
parser = argparse.ArgumentParser(
description='Convert CHASE_DB1 dataset to mmsegmentation format')
pa... | 3,196 | 34.921348 | 78 | py |
mmsegmentation | mmsegmentation-master/tools/convert_datasets/cityscapes.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import mmcv
from cityscapesscripts.preparation.json2labelImg import json2labelImg
def convert_json_to_label(json_file):
label_file = json_file.replace('_polygons.json', '_labelTrainIds.png')
json2labelImg(json_file, label_f... | 1,857 | 31.596491 | 75 | py |
mmsegmentation | mmsegmentation-master/tools/convert_datasets/coco_stuff10k.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import shutil
from functools import partial
import mmcv
import numpy as np
from PIL import Image
from scipy.io import loadmat
COCO_LEN = 10000
clsID_to_trID = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
... | 6,716 | 20.808442 | 79 | py |
mmsegmentation | mmsegmentation-master/tools/convert_datasets/coco_stuff164k.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os.path as osp
import shutil
from functools import partial
from glob import glob
import mmcv
import numpy as np
from PIL import Image
COCO_LEN = 123287
clsID_to_trID = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7:... | 5,115 | 18.30566 | 79 | py |