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
RSP
RSP-main/Semantic Segmentation/tools/model_converters/twins2mmseg.py
# Copyright (c) OpenMMLab. All rights reserved. import argparse import os.path as osp from collections import OrderedDict import mmcv import torch from mmcv.runner import CheckpointLoader def convert_twins(args, ckpt): new_ckpt = OrderedDict() for k, v in list(ckpt.items()): new_v = v if k....
2,752
30.284091
79
py
RSP
RSP-main/Semantic Segmentation/tools/model_converters/vit2mmseg.py
# Copyright (c) OpenMMLab. All rights reserved. import argparse import os.path as osp from collections import OrderedDict import mmcv import torch from mmcv.runner import CheckpointLoader def convert_vit(ckpt): new_ckpt = OrderedDict() for k, v in ckpt.items(): if k.startswith('head'): ...
2,117
28.830986
79
py
RSP
RSP-main/Semantic Segmentation/tools/model_converters/swin2mmseg.py
# Copyright (c) OpenMMLab. All rights reserved. import argparse import os.path as osp from collections import OrderedDict import mmcv import torch from mmcv.runner import CheckpointLoader def convert_swin(ckpt): new_ckpt = OrderedDict() def correct_unfold_reduction_order(x): out_channel, in_channel ...
2,728
30.011364
79
py
RSP
RSP-main/Semantic Segmentation/tools/model_converters/mit2mmseg.py
# Copyright (c) OpenMMLab. All rights reserved. import argparse import os.path as osp from collections import OrderedDict import mmcv import torch from mmcv.runner import CheckpointLoader def convert_mit(ckpt): new_ckpt = OrderedDict() # Process the concat between q linear weights and kv linear weights f...
3,069
35.987952
79
py
RSP
RSP-main/Semantic Segmentation/tools/model_converters/stdc2mmseg.py
# Copyright (c) OpenMMLab. All rights reserved. import argparse import os.path as osp import mmcv import torch from mmcv.runner import CheckpointLoader def convert_stdc(ckpt, stdc_type): new_state_dict = {} if stdc_type == 'STDC1': stage_lst = ['0', '1', '2.0', '2.1', '3.0', '3.1', '4.0', '4.1'] ...
2,307
31.055556
79
py
RSP
RSP-main/Semantic Segmentation/tools/model_converters/vitjax2mmseg.py
import argparse import os.path as osp import mmcv import numpy as np import torch def vit_jax_to_torch(jax_weights, num_layer=12): torch_weights = dict() # patch embedding conv_filters = jax_weights['embedding/kernel'] conv_filters = conv_filters.permute(3, 2, 0, 1) torch_weights['patch_embed.pr...
4,627
36.626016
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/apis/inference.py
# Copyright (c) OpenMMLab. All rights reserved. import matplotlib.pyplot as plt import mmcv import torch from mmcv.parallel import collate, scatter from mmcv.runner import load_checkpoint from mmseg.datasets.pipelines import Compose from mmseg.models import build_segmentor def init_segmentor(config, checkpoint=None,...
4,630
32.80292
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/apis/test.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import tempfile import warnings import mmcv import numpy as np import torch from mmcv.engine import collect_results_cpu, collect_results_gpu from mmcv.image import tensor2imgs from mmcv.runner import get_dist_info def np2tmp(array, temp_file_name=...
9,246
38.517094
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/apis/train.py
# Copyright (c) OpenMMLab. All rights reserved. import random import warnings import mmcv import numpy as np import torch import torch.distributed as dist from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import HOOKS, build_optimizer, build_runner, get_dist_info from mmcv.utils impo...
6,298
34.994286
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/core/evaluation/eval_hooks.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import warnings import torch.distributed as dist from mmcv.runner import DistEvalHook as _DistEvalHook from mmcv.runner import EvalHook as _EvalHook from torch.nn.modules.batchnorm import _BatchNorm class EvalHook(_EvalHook): """Single GPU Eva...
4,776
36.031008
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/core/evaluation/metrics.py
# Copyright (c) OpenMMLab. All rights reserved. from collections import OrderedDict import mmcv import numpy as np import torch def f_score(precision, recall, beta=1): """calculate the f-score value. Args: precision (float | torch.Tensor): The precision value. recall (float | torch.Tensor): ...
16,077
39.60101
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/core/seg/sampler/ohem_pixel_sampler.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from ..builder import PIXEL_SAMPLERS from .base_pixel_sampler import BasePixelSampler @PIXEL_SAMPLERS.register_module() class OHEMPixelSampler(BasePixelSampler): """Online Hard Example Mining Sample...
3,539
40.162791
103
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/necks/ic_neck.py
import torch.nn.functional as F from mmcv.cnn import ConvModule from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import NECKS class CascadeFeatureFusion(BaseModule): """Cascade Feature Fusion Unit in ICNet. Args: low_channels (int): The number of input channels for ...
5,312
34.898649
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/necks/multilevel_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import ConvModule, xavier_init from mmseg.ops import resize from ..builder import NECKS @NECKS.register_module() class MultiLevelNeck(nn.Module): """MultiLevelNeck. A neck structure connect vit backbone and decoder_heads. ...
2,716
33.392405
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/necks/mla_neck.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import ConvModule, build_norm_layer from ..builder import NECKS class MLAModule(nn.Module): def __init__(self, in_channels=[1024, 1024, 1024, 1024], out_channels=256, norm_cfg=N...
3,873
31.554622
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/necks/jpu.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import NECKS @NECKS.register_module() class JPU(BaseModule): """FastFCN: Rethinking Dilat...
5,079
37.484848
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/necks/fpn.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmcv.runner import BaseModule, auto_fp16 from mmseg.ops import resize from ..builder import NECKS @NECKS.register_module() class FPN(BaseModule): """Feature Pyramid Network. ...
9,238
42.172897
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/fcn_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class FCNHead(BaseDecodeHead): """Fully Convolution Networks for Semantic Segmentation. This head is...
2,845
33.289157
77
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/sep_aspp_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule from mmseg.ops import resize from ..builder import HEADS from .aspp_head import ASPPHead, ASPPModule class DepthwiseSeparableASPPModule(ASPPModule): """Atrous Spatial P...
3,535
33.330097
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/ann_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .decode_head import BaseDecodeHead class PPMConcat(nn.ModuleList): """Pyramid Pooling Module that only ...
9,222
36.340081
77
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/apc_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class ACM(nn.Module): """Adaptive Context Module used in APCNet. ...
5,580
33.88125
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/isa_head.py
import math import torch import torch.nn.functional as F from mmcv.cnn import ConvModule from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .decode_head import BaseDecodeHead class SelfAttentionBlock(_SelfAttentionBlock): """Self-Attention Module. Args: i...
4,929
33.475524
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/ocr_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .cascade_decode_head import BaseCascadeDecodeHea...
4,327
32.550388
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/dm_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule, build_activation_layer, build_norm_layer from ..builder import HEADS from .decode_head import BaseDecodeHead class DCM(nn.Module): """Dynamic Convolutional Module us...
5,032
34.443662
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/ema_head.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.distributed as dist import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from ..builder import HEADS from .decode_head import BaseDecodeHead def reduce_mean(tensor): """Reduce mean when distrib...
5,824
33.264706
77
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/da_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn.functional as F from mmcv.cnn import ConvModule, Scale from torch import nn from mmseg.core import add_prefix from ..builder import HEADS from ..utils import SelfAttentionBlock as _SelfAttentionBlock from .decode_head import BaseDecodeHead ...
5,593
30.077778
77
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/stdc_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn.functional as F from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class STDCHead(FCNHead): """This head is the implementation of `Rethinking BiSeNet For Real-time Semantic Segmentation <https://arxiv...
3,555
40.348837
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/psp_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class PPM(nn.ModuleList): """Pooling Pyramid Module used in PSPNet. Args: pool_scales (t...
3,404
31.740385
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/cc_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..builder import HEADS from .fcn_head import FCNHead try: from mmcv.ops import CrissCrossAttention except ModuleNotFoundError: CrissCrossAttention = None @HEADS.register_module() class CCHead(FCNHead): """CCNet: Criss-Cross Attention for ...
1,331
29.272727
71
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/enc_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule, build_norm_layer from mmseg.ops import Encoding, resize from ..builder import HEADS, build_loss from .decode_head import BaseDecodeHead class EncModule(nn.Module): "...
6,792
34.941799
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/setr_up_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import ConvModule, build_norm_layer from mmseg.ops import Upsample from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class SETRUPHead(BaseDecodeHead): """Naive upsampling head and Progre...
2,962
35.134146
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/setr_mla_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.ops import Upsample from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class SETRMLAHead(BaseDecodeHead): """Multi level feature aggretation head...
2,177
33.03125
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/dpt_head.py
import math import torch import torch.nn as nn from mmcv.cnn import ConvModule, Linear, build_activation_layer from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class ReassembleBlocks(BaseModule): """ViTPostProcessBlock, process c...
10,351
34.210884
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/fpn_head.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.ops import Upsample, resize from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class FPNHead(BaseDecodeHead): """Panoptic Feature Pyramid N...
2,437
33.828571
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/nl_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.cnn import NonLocal2d from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class NLHead(FCNHead): """Non-local Neural Networks. This head is the implementation of `NLNet <https://arxiv.org/abs/1711.07971...
1,605
30.490196
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/dnl_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.cnn import NonLocal2d from torch import nn from ..builder import HEADS from .fcn_head import FCNHead class DisentangledNonLocal2d(NonLocal2d): """Disentangled Non-Local Blocks. Args: temperature (float): Temperature to adjust att...
4,619
33.736842
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/decode_head.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import ABCMeta, abstractmethod import torch import torch.nn as nn from mmcv.runner import BaseModule, auto_fp16, force_fp32 from mmseg.core import build_pixel_sampler from mmseg.ops import resize from ..builder import build_loss from ..losses import accuracy ...
10,632
38.973684
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/lraspp_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv import is_tuple_of from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead @HEADS.register_module() class LRASPPHead(BaseDecodeHead): """Lite R-ASP...
3,086
32.554348
77
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/uper_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead from .psp_head import PPM @HEADS.register_module() class UPerHead(BaseDecodeHead): """Unified Percept...
4,037
30.546875
72
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/segmenter_mask_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_norm_layer from mmcv.cnn.utils.weight_init import (constant_init, trunc_normal_, trunc_normal_init) from mmcv.runner import ModuleList fr...
4,895
35.537313
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/aspp_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead class ASPPModule(nn.ModuleList): """Atrous Spatial Pyramid Pooling (ASPP) Module. Args: ...
3,467
30.816514
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/psa_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmseg.ops import resize from ..builder import HEADS from .decode_head import BaseDecodeHead try: from mmcv.ops import PSAMask except ModuleNotFoundError: PSAM...
7,532
37.045455
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/gc_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.cnn import ContextBlock from ..builder import HEADS from .fcn_head import FCNHead @HEADS.register_module() class GCHead(FCNHead): """GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond. This head is the implementation o...
1,639
32.469388
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/segformer_head.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmseg.models.builder import HEADS from mmseg.models.decode_heads.decode_head import BaseDecodeHead from mmseg.ops import resize @HEADS.register_module() class SegformerHead(BaseDecodeHead): """...
2,044
29.522388
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/decode_heads/point_head.py
# Copyright (c) OpenMMLab. All rights reserved. # Modified from https://github.com/facebookresearch/detectron2/tree/master/projects/PointRend/point_head/point_head.py # noqa import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmcv.ops import point_sample from mmseg.models.builder import HEADS fro...
15,026
41.092437
126
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/embed.py
# Copyright (c) OpenMMLab. All rights reserved. import math from typing import Sequence import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_conv_layer, build_norm_layer from mmcv.runner.base_module import BaseModule from mmcv.utils import to_2tuple class AdaptivePadding(nn.Module): "...
12,216
35.909366
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/se_layer.py
# Copyright (c) OpenMMLab. All rights reserved. import mmcv import torch.nn as nn from mmcv.cnn import ConvModule from .make_divisible import make_divisible class SELayer(nn.Module): """Squeeze-and-Excitation Module. Args: channels (int): The input (and output) channels of the SE layer. rati...
2,151
35.474576
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/res_layer.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import build_conv_layer, build_norm_layer from mmcv.runner import Sequential from torch import nn as nn class ResLayer(Sequential): """ResLayer to build ResNet style backbone. Args: block (nn.Module): block used to build ResLayer. ...
3,395
34.010309
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/self_attention_block.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.cnn import ConvModule, constant_init from torch import nn as nn from torch.nn import functional as F class SelfAttentionBlock(nn.Module): """General self-attention block/non-local block. Please refer to https://arxiv.org/abs/1706.03762 fo...
6,173
37.347826
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/up_conv_block.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule, build_upsample_layer class UpConvBlock(nn.Module): """Upsample convolution block in decoder for UNet. This upsample convolution block consists of one upsample module followed by one convolu...
4,016
38
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/utils/inverted_residual.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import ConvModule from torch import nn from torch.utils import checkpoint as cp from .se_layer import SELayer class InvertedResidual(nn.Module): """InvertedResidual block for MobileNetV2. Args: in_channels (int): The input channels of the...
7,162
32.471963
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/segmentors/base.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings from abc import ABCMeta, abstractmethod from collections import OrderedDict import mmcv import numpy as np import torch import torch.distributed as dist from mmcv.runner import BaseModule, auto_fp16 class BaseSegmentor(BaseModule, metaclass=ABCMeta): ...
11,332
38.487805
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/segmentors/cascade_encoder_decoder.py
# Copyright (c) OpenMMLab. All rights reserved. from torch import nn from mmseg.core import add_prefix from mmseg.ops import resize from .. import builder from ..builder import SEGMENTORS from .encoder_decoder import EncoderDecoder @SEGMENTORS.register_module() class CascadeEncoderDecoder(EncoderDecoder): """Cas...
3,134
35.882353
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/segmentors/encoder_decoder.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from mmseg.core import add_prefix from mmseg.ops import resize from .. import builder from ..builder import SEGMENTORS from .base import BaseSegmentor @SEGMENTORS.register_module() class EncoderDecoder(...
10,889
37.076923
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/dice_loss.py
# Copyright (c) OpenMMLab. All rights reserved. """Modified from https://github.com/LikeLy-Journey/SegmenTron/blob/master/ segmentron/solver/loss.py (Apache-2.0 License)""" import torch import torch.nn as nn import torch.nn.functional as F from ..builder import LOSSES from .utils import get_class_weight, weighted_loss...
4,928
34.717391
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/lovasz_loss.py
# Copyright (c) OpenMMLab. All rights reserved. """Modified from https://github.com/bermanmaxim/LovaszSoftmax/blob/master/pytor ch/lovasz_losses.py Lovasz-Softmax and Jaccard hinge loss in PyTorch Maxim Berman 2018 ESAT-PSI KU Leuven (MIT License)""" import mmcv import torch import torch.nn as nn import torch.nn.funct...
12,223
36.728395
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/utils.py
# Copyright (c) OpenMMLab. All rights reserved. import functools import mmcv import numpy as np import torch.nn.functional as F def get_class_weight(class_weight): """Get class weight for loss function. Args: class_weight (list[float] | str | None): If class_weight is a str, take it as a...
3,738
29.398374
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/accuracy.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn def accuracy(pred, target, topk=1, thresh=None): """Calculate accuracy according to the prediction and target. Args: pred (torch.Tensor): The model prediction, shape (N, num_class, ...) target (torch.Tensor): The target of ...
3,018
36.7375
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/focal_loss.py
# Copyright (c) OpenMMLab. All rights reserved. # Modified from https://github.com/open-mmlab/mmdetection import torch import torch.nn as nn import torch.nn.functional as F from mmcv.ops import sigmoid_focal_loss as _sigmoid_focal_loss from ..builder import LOSSES from .utils import weight_reduce_loss # This method ...
15,001
44.737805
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/losses/cross_entropy_loss.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn import torch.nn.functional as F from ..builder import LOSSES from .utils import get_class_weight, weight_reduce_loss def cross_entropy(pred, label, weight=None, class_weight=None, ...
8,262
36.559091
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/hrnet.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn from mmcv.cnn import build_conv_layer, build_norm_layer from mmcv.runner import BaseModule, ModuleList, Sequential from mmcv.utils.parrots_wrapper import _BatchNorm from mmseg.ops import Upsample, resize from ..builder import BACKBO...
25,112
38.055988
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/mit.py
# Copyright (c) OpenMMLab. All rights reserved. import math import warnings import torch import torch.nn as nn from mmcv.cnn import Conv2d, build_activation_layer, build_norm_layer from mmcv.cnn.bricks.drop import build_dropout from mmcv.cnn.bricks.transformer import MultiheadAttention from mmcv.cnn.utils.weight_init ...
16,814
37.923611
89
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/mobilenet_v2.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn from mmcv.cnn import ConvModule from mmcv.runner import BaseModule from torch.nn.modules.batchnorm import _BatchNorm from ..builder import BACKBONES from ..utils import InvertedResidual, make_divisible @BACKBONES.register_module()...
7,640
37.590909
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/icnet.py
import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import BACKBONES, build_backbone from ..decode_heads.psp_head import PPM @BACKBONES.register_module() class ICNet(BaseModule): """ICNet for Real-Time Semantic Segmenta...
5,839
34.180723
76
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/swin.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings from collections import OrderedDict from copy import deepcopy import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.transformer import FFN, build_d...
29,743
38.291942
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/swin_transformer.py
# -------------------------------------------------------- # Swin Transformer # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Ze Liu, Yutong Lin, Yixuan Wei # -------------------------------------------------------- import warnings from collections import OrderedDi...
28,039
38.60452
123
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/timm_backbone.py
# Copyright (c) OpenMMLab. All rights reserved. try: import timm except ImportError: timm = None from mmcv.cnn.bricks.registry import NORM_LAYERS from mmcv.runner import BaseModule from ..builder import BACKBONES @BACKBONES.register_module() class TIMMBackbone(BaseModule): """Wrapper to use backbones fr...
1,948
29.453125
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/fast_scnn.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule from mmcv.runner import BaseModule from mmseg.models.decode_heads.psp_head import PPM from mmseg.ops import resize from ..builder import BACKBONES from ..utils import Inverte...
15,660
37.197561
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/resnet.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import build_conv_layer, build_norm_layer, build_plugin_layer from mmcv.runner import BaseModule from mmcv.utils.parrots_wrapper import _BatchNorm from ..builder import BACKBONES fro...
25,804
35.090909
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/cgnet.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import ConvModule, build_conv_layer, build_norm_layer from mmcv.runner import BaseModule from mmcv.utils.parrots_wrapper import _BatchNorm from ..builder import BACKBONE...
13,412
34.959786
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/vit.py
# Copyright (c) OpenMMLab. All rights reserved. import math import warnings import torch import torch.nn as nn from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention from mmcv.cnn.utils.weight_init import (constant_init, kaiming_init, ...
16,979
40.113801
128
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/resnext.py
# Copyright (c) OpenMMLab. All rights reserved. import math from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from ..utils import ResLayer from .resnet import Bottleneck as _Bottleneck from .resnet import ResNet class Bottleneck(_Bottleneck): """Bottleneck block for ResNeXt...
5,321
34.245033
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/mobilenet_v3.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import mmcv from mmcv.cnn import ConvModule from mmcv.cnn.bricks import Conv2dAdaptivePadding from mmcv.runner import BaseModule from torch.nn.modules.batchnorm import _BatchNorm from ..builder import BACKBONES from ..utils import InvertedResidualV3 as I...
10,845
39.470149
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/unet.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn import torch.utils.checkpoint as cp from mmcv.cnn import (UPSAMPLE_LAYERS, ConvModule, build_activation_layer, build_norm_layer) from mmcv.runner import BaseModule from mmcv.utils.parrots_wrapper import _BatchNo...
18,611
41.396355
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/our_resnet.py
import math import torch import torch.nn as nn import torch.utils.model_zoo as model_zoo import os import torchvision torchvision.models.resnext50_32x4d() from mmcv.cnn import (constant_init, kaiming_init) #from ..backbones.custom_load import load_checkpoint from mmseg.utils import get_root_logger #from mmcv.utils.r...
17,308
38.974596
112
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/twins.py
import math import warnings import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import build_norm_layer from mmcv.cnn.bricks.drop import build_dropout from mmcv.cnn.bricks.transformer import FFN from mmcv.cnn.utils.weight_init import (constant_init, normal_init, ...
23,774
39.433673
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/resnest.py
# Copyright (c) OpenMMLab. All rights reserved. import math import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint as cp from mmcv.cnn import build_conv_layer, build_norm_layer from ..builder import BACKBONES from ..utils import ResLayer from .resnet import Bottleneck as _Bot...
10,259
31.163009
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/erfnet.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import build_activation_layer, build_conv_layer, build_norm_layer from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import BACKBONES class DownsamplerBlock(BaseModule): """Downsampler blo...
13,068
38.60303
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/bisenetv2.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import (ConvModule, DepthwiseSeparableConvModule, build_activation_layer, build_norm_layer) from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import BACKBONES class Deta...
23,042
35.987159
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/stdc.py
# Copyright (c) OpenMMLab. All rights reserved. """Modified from https://github.com/MichaelFan01/STDC-Seg.""" import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmcv.runner.base_module import BaseModule, ModuleList, Sequential from mmseg.ops import resize from ..bui...
16,158
37.200946
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/bisenetv1.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule from mmcv.runner import BaseModule from mmseg.ops import resize from ..builder import BACKBONES, build_backbone class SpatialPath(BaseModule): """Spatial Path to preserve the spatial size of the ori...
12,006
35.057057
78
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/custom_load/checkpoint.py
# Copyright (c) Open-MMLab. All rights reserved. import io import os import os.path as osp import pkgutil import time import warnings from collections import OrderedDict from importlib import import_module from tempfile import TemporaryDirectory import torch import torchvision from torch.optim import Optimizer from to...
21,203
37.906422
117
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/base_model.py
from functools import partial import torch import torch.nn as nn from timm.models.layers import trunc_normal_ import numpy as np from torch.nn.functional import instance_norm from torch.nn.modules.batchnorm import BatchNorm2d from .NormalCell import NormalCell from .ReductionCell import ReductionCell #from ..custom_lo...
16,934
45.270492
199
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/swin.py
# -------------------------------------------------------- # Swin Transformer # Copyright (c) 2021 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Ze Liu # -------------------------------------------------------- import torch import torch.nn as nn import torch.utils.checkpoint as chec...
24,644
40.559865
142
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/ReductionCell.py
import math from numpy.core.fromnumeric import resize, shape import torch import torch.nn as nn import torch.nn.functional as F from timm.models.layers import DropPath, to_2tuple, trunc_normal_ import numpy as np from .token_transformer import Token_transformer from .token_performer import Token_performer from .SELayer...
11,032
46.761905
179
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/NormalCell.py
# Copyright (c) [2012]-[2021] Shanghai Yitu Technology Co., Ltd. # # This source code is licensed under the Clear BSD License # LICENSE file in the root directory of this file # All rights reserved. """ Borrow from timm(https://github.com/rwightman/pytorch-image-models) """ import torch import torch.nn as nn import num...
11,944
43.240741
177
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/token_performer.py
""" Take Performer as T2T Transformer """ import math import torch import torch.nn as nn import numpy as np class Token_performer(nn.Module): def __init__(self, dim, in_dim, head_cnt=1, kernel_ratio=0.5, dp1=0.1, dp2 = 0.1, gamma=False, init_values=1e-4): super().__init__() self.head_dim = in_dim ...
3,147
35.604651
128
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/SELayer.py
import torch import torch.nn as nn class SELayer(nn.Module): def __init__(self, channel, reduction=16): super(SELayer, self).__init__() self.avg_pool = nn.AdaptiveAvgPool1d(1) self.fc = nn.Sequential( nn.Linear(channel, channel // reduction, bias=False), nn.ReLU(inpl...
726
32.045455
65
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/token_transformer.py
# Copyright (c) [2012]-[2021] Shanghai Yitu Technology Co., Ltd. # # This source code is licensed under the Clear BSD License # LICENSE file in the root directory of this file # All rights reserved. """ Take the standard Transformer as T2T Transformer """ import torch import torch.nn as nn from timm.models.layers impor...
2,703
39.358209
165
py
RSP
RSP-main/Semantic Segmentation/mmseg/models/backbones/ViTAE_Window_NoShift/models.py
# Copyright (c) [2012]-[2021] Shanghai Yitu Technology Co., Ltd. # # This source code is licensed under the Clear BSD License # LICENSE file in the root directory of this file # All rights reserved. """ T2T-ViT """ from math import gamma import torch import torch.nn as nn from timm.models.helpers import load_pretraine...
1,657
38.47619
269
py
RSP
RSP-main/Semantic Segmentation/mmseg/datasets/custom.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import warnings from collections import OrderedDict import mmcv import numpy as np from mmcv.utils import print_log from prettytable import PrettyTable from torch.utils.data import Dataset from mmseg.core import eval_metrics, intersect_and_union, p...
17,677
36.85439
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/datasets/dataset_wrappers.py
# Copyright (c) OpenMMLab. All rights reserved. import bisect import collections import copy from itertools import chain import mmcv import numpy as np from mmcv.utils import build_from_cfg, print_log from torch.utils.data.dataset import ConcatDataset as _ConcatDataset from .builder import DATASETS, PIPELINES from .c...
10,339
36.194245
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/datasets/builder.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import platform import random from functools import partial import numpy as np import torch from mmcv.parallel import collate from mmcv.runner import get_dist_info from mmcv.utils import Registry, build_from_cfg, digit_version from torch.utils.data import Dat...
6,868
35.343915
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/datasets/pipelines/formatting.py
# Copyright (c) OpenMMLab. All rights reserved. from collections.abc import Sequence import mmcv import numpy as np import torch from mmcv.parallel import DataContainer as DC from ..builder import PIPELINES def to_tensor(data): """Convert objects of various python types to :obj:`torch.Tensor`. Supported ty...
9,290
31.037931
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/utils/set_env.py
# Copyright (c) OpenMMLab. All rights reserved. import os import platform import cv2 import torch.multiprocessing as mp from ..utils import get_root_logger def setup_multi_processes(cfg): """Setup multi-processing environment variables.""" logger = get_root_logger() # set multi-process start method ...
2,309
40.25
116
py
RSP
RSP-main/Semantic Segmentation/mmseg/ops/wrappers.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings import torch.nn as nn import torch.nn.functional as F def resize(input, size=None, scale_factor=None, mode='nearest', align_corners=None, warning=True): if warning: if size is not None a...
1,875
35.076923
79
py
RSP
RSP-main/Semantic Segmentation/mmseg/ops/encoding.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch import nn from torch.nn import functional as F class Encoding(nn.Module): """Encoding Layer: a learnable residual encoder. Input is of shape (batch_size, channels, height, width). Output is of shape (batch_size, num_codes, channels)...
2,836
36.328947
78
py
RSP
RSP-main/Semantic Segmentation/tests/test_config.py
# Copyright (c) OpenMMLab. All rights reserved. import glob import os from os.path import dirname, exists, isdir, join, relpath from mmcv import Config from torch import nn from mmseg.models import build_segmentor def _get_config_directory(): """Find the predefined segmentor config directory.""" try: ...
6,067
36.45679
79
py
RSP
RSP-main/Semantic Segmentation/tests/test_eval_hook.py
# Copyright (c) OpenMMLab. All rights reserved. import logging import tempfile from unittest.mock import MagicMock, patch import mmcv.runner import pytest import torch import torch.nn as nn from mmcv.runner import obj_from_dict from torch.utils.data import DataLoader, Dataset from mmseg.apis import single_gpu_test fr...
7,237
34.307317
79
py
RSP
RSP-main/Semantic Segmentation/tests/test_sampler.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmseg.core import OHEMPixelSampler from mmseg.models.decode_heads import FCNHead def _context_for_ohem(): return FCNHead(in_channels=32, channels=16, num_classes=19) def _context_for_ohem_multiple_loss(): return FCNHead( ...
2,957
36.443038
77
py