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/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... | 3,049 | 33.269663 | 79 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/decode_heads/ham_head.py | # Copyright (c) OpenMMLab. All rights reserved.
# Originally from https://github.com/visual-attention-network/segnext
# Licensed under the Apache License, Version 2.0 (the "License")
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import ConvModule
from mmseg.ops import resize
from ..b... | 8,327 | 31.15444 | 76 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/decode_heads/isa_head.py | # Copyright (c) OpenMMLab. All rights reserved.
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):
... | 4,977 | 33.569444 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/decode_heads/knet_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 mmcv.cnn.bricks.transformer import (FFN, TRANSFORMER_LAYER,
MultiheadAttention,
... | 19,069 | 40.637555 | 79 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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
try:
from mmcv.ops import point_sample
except ModuleNotFoundError:
p... | 15,280 | 40.865753 | 126 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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,884 | 31.923729 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/decode_heads/segformer_head.py | # Modified from
# https://github.com/NVlabs/SegFormer/blob/master/mmseg/models/decode_heads/segformer_head.py
#
# This work is licensed under the NVIDIA Source Code License.
#
# Copyright (c) 2021, NVIDIA Corporation. All rights reserved.
# NVIDIA Source Code License for StyleGAN2 with Adaptive Discriminator
# Augmenta... | 6,587 | 44.434483 | 93 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/decode_heads/sep_fcn_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.cnn import DepthwiseSeparableConvModule
from ..builder import HEADS
from .fcn_head import FCNHead
@HEADS.register_module()
class DepthwiseSeparableFCNHead(FCNHead):
"""Depthwise-Separable Fully Convolutional Network for Semantic
Segmentation.
Thi... | 2,406 | 38.459016 | 77 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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,584 | 40.686047 | 79 | py |
mmsegmentation | mmsegmentation-master/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,516 | 31.035461 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/losses/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .accuracy import Accuracy, accuracy
from .cross_entropy_loss import (CrossEntropyLoss, binary_cross_entropy,
cross_entropy, mask_cross_entropy)
from .dice_loss import DiceLoss
from .focal_loss import FocalLoss
from .lovasz_loss import... | 681 | 39.117647 | 72 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/losses/accuracy.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
def accuracy(pred, target, topk=1, thresh=None, ignore_index=None):
"""Calculate accuracy according to the prediction and target.
Args:
pred (torch.Tensor): The model prediction, shape (N, num_class, ...)
targe... | 3,618 | 37.913978 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/losses/cross_entropy_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
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,
cl... | 11,998 | 39.400673 | 132 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/losses/tversky_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Modified from
https://github.com/JunMa11/SegLoss/blob/master/losses_pytorch/dice_loss.py#L333
(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
@... | 5,419 | 34.657895 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/losses/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import functools
import mmcv
import numpy as np
import torch
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,
... | 3,945 | 30.070866 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/necks/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .featurepyramid import Feature2Pyramid
from .fpn import FPN
from .ic_neck import ICNeck
from .jpu import JPU
from .mla_neck import MLANeck
from .multilevel_neck import MultiLevelNeck
__all__ = [
'FPN', 'MultiLevelNeck', 'MLANeck', 'ICNeck', 'JPU', 'Feature2Pyram... | 326 | 26.25 | 74 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/necks/featurepyramid.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import build_norm_layer
from ..builder import NECKS
@NECKS.register_module()
class Feature2Pyramid(nn.Module):
"""Feature2Pyramid.
A neck structure connect ViT backbone and decoder_heads.
Args:
embed_dims (int):... | 2,417 | 34.558824 | 74 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/necks/ic_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
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_chann... | 5,360 | 34.979866 | 76 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/segmentors/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .base import BaseSegmentor
from .cascade_encoder_decoder import CascadeEncoderDecoder
from .encoder_decoder import EncoderDecoder
__all__ = ['BaseSegmentor', 'EncoderDecoder', 'CascadeEncoderDecoder']
| 255 | 35.571429 | 70 | py |
mmsegmentation | mmsegmentation-master/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,489 | 38.349315 | 79 | py |
mmsegmentation | mmsegmentation-master/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,373 | 36.488889 | 78 | py |
mmsegmentation | mmsegmentation-master/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(... | 12,600 | 37.184848 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/models/utils/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .embed import PatchEmbed
from .inverted_residual import InvertedResidual, InvertedResidualV3
from .make_divisible import make_divisible
from .res_layer import ResLayer
from .se_layer import SELayer
from .self_attention_block import SelfAttentionBlock
from .shape_conv... | 677 | 38.882353 | 75 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/utils/make_divisible.py | # Copyright (c) OpenMMLab. All rights reserved.
def make_divisible(value, divisor, min_value=None, min_ratio=0.9):
"""Make divisible function.
This function rounds the channel number to the nearest value that can be
divisible by the divisor. It is taken from the original tf repo. It ensures
that all la... | 1,279 | 43.137931 | 116 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/models/utils/shape_convert.py | # Copyright (c) OpenMMLab. All rights reserved.
def nlc_to_nchw(x, hw_shape):
"""Convert [N, L, C] shape tensor to [N, C, H, W] shape tensor.
Args:
x (Tensor): The input tensor of shape [N, L, C] before conversion.
hw_shape (Sequence[int]): The height and width of output feature map.
Retur... | 3,589 | 32.240741 | 79 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/mmseg/ops/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .encoding import Encoding
from .wrappers import Upsample, resize
__all__ = ['Upsample', 'resize', 'Encoding']
| 164 | 26.5 | 47 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/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,874 | 35.057692 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/utils/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .collect_env import collect_env
from .logger import get_root_logger
from .misc import find_latest_checkpoint
from .set_env import setup_multi_processes
from .util_distribution import build_ddp, build_dp, get_device
__all__ = [
'get_root_logger', 'collect_env', '... | 414 | 33.583333 | 66 | py |
mmsegmentation | mmsegmentation-master/mmseg/utils/collect_env.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmcv.utils import collect_env as collect_base_env
from mmcv.utils import get_git_hash
import mmseg
def collect_env():
"""Collect the information of the running environments."""
env_info = collect_base_env()
env_info['MMSegmentation'] = f'{mmseg.__versi... | 484 | 24.526316 | 76 | py |
mmsegmentation | mmsegmentation-master/mmseg/utils/logger.py | # Copyright (c) OpenMMLab. All rights reserved.
import logging
from mmcv.utils import get_logger
def get_root_logger(log_file=None, log_level=logging.INFO):
"""Get the root logger.
The logger will be initialized if it has not been initialized. By default a
StreamHandler will be added. If `log_file` is s... | 947 | 31.689655 | 79 | py |
mmsegmentation | mmsegmentation-master/mmseg/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import glob
import os.path as osp
import warnings
def find_latest_checkpoint(path, suffix='pth'):
"""This function is for finding the latest checkpoint.
It will be used when automatically resume, modified from
https://github.com/open-mmlab/mmdetection/blob/... | 1,436 | 33.214286 | 82 | py |
mmsegmentation | mmsegmentation-master/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,311 | 40.285714 | 116 | py |
mmsegmentation | mmsegmentation-master/mmseg/utils/util_distribution.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import torch
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmseg import digit_version
dp_factory = {'cuda': MMDataParallel, 'cpu': MMDataParallel}
ddp_factory = {'cuda': MMDistributedDataParallel}
def build_dp(model, device='cud... | 3,725 | 34.485714 | 75 | py |
mmsegmentation | mmsegmentation-master/projects/README.md | # Projects
Implementing new models and features into OpenMMLab's algorithm libraries could be troublesome due to the rigorous requirements on code quality, which could hinder the fast iteration of SOTA models and might discourage our members from sharing their latest outcomes here.
And that's why we have this `Projec... | 1,169 | 116 | 381 | md |
mmsegmentation | mmsegmentation-master/projects/dest/README.md | # DEST
[DEST: Depth Estimation with Simplified Transformer](https://arxiv.org/abs/2204.13791)
## Description
Transformer and its variants have shown state-of-the-art results in many vision tasks recently, ranging from image classification to dense prediction. Despite of their success, limited work has been reported ... | 8,001 | 79.02 | 971 | md |
mmsegmentation | mmsegmentation-master/projects/dest/configs/README.md | # DEST
[DEST: Depth Estimation with Simplified Transformer](https://arxiv.org/abs/2204.13791)
## Introduction
<!-- [ALGORITHM] -->
<a href="https://github.com/NVIDIA/DL4AGX/tree/master/DEST">Official Repo</a>
## Abstract
<!-- [ABSTRACT] -->
Transformer and its variants have shown state-of-the-art results in many... | 4,792 | 92.980392 | 971 | md |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b0.py | # model settings
embed_dims = [32, 64, 160, 256]
norm_cfg = dict(type='SyncBN', requires_grad=True)
model = dict(
type='EncoderDecoder',
pretrained=None,
backbone=dict(
type='SimplifiedMixTransformer',
in_channels=3,
embed_dims=embed_dims,
num_stages=4,
num_layers=[2,... | 1,143 | 29.105263 | 75 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b0_1024x1024_160k_cityscapes.py | _base_ = [
'./dest_simpatt-b0.py',
'../../../configs/_base_/datasets/cityscapes_1024x1024.py',
'../../../configs/_base_/default_runtime.py',
'../../../configs/_base_/schedules/schedule_160k.py'
]
custom_imports = dict(imports=['projects.dest.models'])
optimizer = dict(
_delete_=True,
type='Ada... | 797 | 22.470588 | 63 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b1_1024x1024_160k_cityscapes.py | _base_ = ['./dest_simpatt-b0_1024x1024_160k_cityscapes.py']
embed_dims = [64, 128, 250, 320]
model = dict(
type='EncoderDecoder',
pretrained=None,
backbone=dict(embed_dims=embed_dims),
decode_head=dict(in_channels=embed_dims, channels=64))
| 258 | 24.9 | 59 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b2_1024x1024_160k_cityscapes.py | _base_ = ['./dest_simpatt-b0_1024x1024_160k_cityscapes.py']
embed_dims = [64, 128, 250, 320]
model = dict(
type='EncoderDecoder',
pretrained=None,
backbone=dict(embed_dims=embed_dims, num_layers=[3, 3, 6, 3]),
decode_head=dict(in_channels=embed_dims, channels=64))
| 283 | 27.4 | 66 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b3_1024x1024_160k_cityscapes.py | _base_ = ['./dest_simpatt-b0_1024x1024_160k_cityscapes.py']
embed_dims = [64, 128, 250, 320]
optimizer = dict(
_delete_=True,
type='AdamW',
lr=0.00006,
betas=(0.9, 0.999),
weight_decay=0.01,
paramwise_cfg=dict(
custom_keys={
'pos_block': dict(decay_mult=0.),
'no... | 584 | 24.434783 | 66 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b4_1024x1024_160k_cityscapes.py | _base_ = ['./dest_simpatt-b0_1024x1024_160k_cityscapes.py']
embed_dims = [64, 128, 250, 320]
optimizer = dict(
_delete_=True,
type='AdamW',
lr=0.00006,
betas=(0.9, 0.999),
weight_decay=0.01,
paramwise_cfg=dict(
custom_keys={
'pos_block': dict(decay_mult=0.),
'no... | 585 | 24.478261 | 67 | py |
mmsegmentation | mmsegmentation-master/projects/dest/configs/dest_simpatt-b5_1024x1024_160k_cityscapes.py | _base_ = ['./dest_simpatt-b0_1024x1024_160k_cityscapes.py']
embed_dims = [64, 128, 250, 320]
optimizer = dict(
_delete_=True,
type='AdamW',
lr=0.00006,
betas=(0.9, 0.999),
weight_decay=0.01,
paramwise_cfg=dict(
custom_keys={
'pos_block': dict(decay_mult=0.),
'no... | 586 | 24.521739 | 68 | py |
mmsegmentation | mmsegmentation-master/projects/dest/models/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .dest_head import DESTHead
from .smit import SimplifiedMixTransformer
__all__ = ['SimplifiedMixTransformer', 'DESTHead']
| 175 | 28.333333 | 50 | py |
mmsegmentation | mmsegmentation-master/projects/dest/models/dest_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmseg.models import HEADS
from mmseg.models.decode_heads.decode_head import BaseDecodeHead
@HEADS.register_module()
class DESTHead(BaseDecodeHead):
def __init__(self, interpolate_mode='bilinea... | 1,956 | 34.581818 | 77 | py |
mmsegmentation | mmsegmentation-master/projects/dest/models/smit.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import warnings
import torch
import torch.nn as nn
from mmcv.cnn import build_activation_layer, build_conv_layer, build_norm_layer
from mmcv.cnn.bricks.drop import build_dropout
from mmcv.cnn.utils.weight_init import trunc_normal_init
from mmcv.runner import ... | 21,741 | 37.964158 | 79 | py |
mmsegmentation | mmsegmentation-master/projects/example_project/README.md | # Dummy ResNet Wrapper
This is an example README for community `projects/`. We have provided detailed explanations for each field in the form of html comments, which are visible when you read the source of this README file. If you wish to submit your project to our main repository, then all the fields in this README a... | 8,356 | 63.284615 | 601 | md |
mmsegmentation | mmsegmentation-master/projects/example_project/configs/fcn_dummy-r50-d8_4xb2-40k_cityscapes-512x1024.py | # Copyright (c) OpenMMLab. All rights reserved.
_base_ = ['../../../configs/fcn/fcn_r50-d8_512x1024_40k_cityscapes.py']
custom_imports = dict(imports=['projects.example_project.dummy'])
model = dict(backbone=dict(type='DummyResNet'))
| 236 | 32.857143 | 71 | py |
mmsegmentation | mmsegmentation-master/projects/example_project/dummy/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .dummy_resnet import DummyResNet
__all__ = ['DummyResNet']
| 113 | 21.8 | 47 | py |
mmsegmentation | mmsegmentation-master/projects/example_project/dummy/dummy_resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmseg.models import BACKBONES
from mmseg.models.backbones import ResNetV1c
@BACKBONES.register_module()
class DummyResNet(ResNetV1c):
"""Implements a dummy ResNet wrapper for demonstration purpose.
Args:
**kwargs: All the arguments are passed to the... | 451 | 27.25 | 67 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/README.md | # KITTI STEP Dataset
Support **`KITTI STEP Dataset`**
## Description
Author: TimoK93
This project implements **`KITTI STEP Dataset`**
### Dataset preparing
After registration, the data images could be download from [KITTI-STEP](http://www.cvlibs.net/datasets/kitti/eval_step.php)
You may need to follow the follow... | 3,703 | 36.795918 | 527 | md |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/configs/_base_/datasets/kittistep.py | # dataset settings
dataset_type = 'KITTISTEPDataset'
data_root = 'data/kitti_step/'
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
crop_size = (368, 368)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(type='Resize', i... | 1,845 | 32.563636 | 77 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/configs/deeplabv3plus/deeplabv3plus_r50-d8_368x368_80k_kittistep.py | _base_ = [
'../../../../configs/_base_/models/deeplabv3plus_r50-d8.py',
'../_base_/datasets/kittistep.py',
'../../../../configs/_base_/default_runtime.py',
'../../../../configs/_base_/schedules/schedule_80k.py'
]
model = dict(
decode_head=dict(align_corners=True),
auxiliary_head=dict(align_corne... | 404 | 35.818182 | 73 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/configs/segformer/segformer_mit-b0_368x368_160k_kittistep.py | _base_ = [
'../../../../configs/_base_/models/segformer_mit-b0.py',
'../_base_/datasets/kittistep.py',
'../../../../configs/_base_/default_runtime.py',
'../../../../configs/_base_/schedules/schedule_160k.py'
]
checkpoint = 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/segformer/mit_b0_20... | 1,056 | 26.102564 | 121 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/configs/segformer/segformer_mit-b5_368x368_160k_kittistep.py | _base_ = ['./segformer_mit-b0_368x368_160k_kittistep.py']
checkpoint = 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/segformer/mit_b5_20220624-658746d9.pth' # noqa
model = dict(
backbone=dict(
init_cfg=dict(type='Pretrained', checkpoint=checkpoint),
embed_dims=64,
num_layers... | 392 | 38.3 | 121 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/mmseg/datasets/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .kitti_step import KITTISTEPDataset
__all__ = [
'KITTISTEPDataset',
]
| 128 | 17.428571 | 47 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/mmseg/datasets/kitti_step.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmseg.datasets.builder import DATASETS
from mmseg.datasets.cityscapes import CityscapesDataset
@DATASETS.register_module()
class KITTISTEPDataset(CityscapesDataset):
"""KITTI-STEP dataset."""
def __init__(self,
img_suffix='.png',
... | 517 | 31.375 | 75 | py |
mmsegmentation | mmsegmentation-master/projects/kitti_step_dataset/tools/convert_datasets/kitti_step.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import shutil
import cv2
import mmcv
def kitti_to_train_ids(input):
src, gt_dir, new_gt_dir = input
label_file = src.replace('.png',
'_labelTrainIds.png').replace(gt_dir, new_gt_dir)
... | 2,498 | 31.038462 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/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,068 | 36.233129 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_digit_version.py | # Copyright (c) OpenMMLab. All rights reserved.
from mmseg import digit_version
def test_digit_version():
assert digit_version('0.2.16') == (0, 2, 16, 0, 0, 0)
assert digit_version('1.2.3') == (1, 2, 3, 0, 0, 0)
assert digit_version('1.2.3rc0') == (1, 2, 3, 0, -1, 0)
assert digit_version('1.2.3rc1') =... | 1,089 | 48.545455 | 79 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/tests/test_inference.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import mmcv
from mmseg.apis import inference_segmentor, init_segmentor
def test_test_time_augmentation_on_cpu():
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
config = mmcv.Config.fromfile(config_file)
# Rem... | 996 | 31.16129 | 75 | py |
mmsegmentation | mmsegmentation-master/tests/test_metrics.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
from mmseg.core.evaluation import (eval_metrics, mean_dice, mean_fscore,
mean_iou)
from mmseg.core.evaluation.metrics import f_score
def get_confusion_matrix(pred_label, label, num_classes, ignore_index):
"""Int... | 13,345 | 36.914773 | 79 | py |
mmsegmentation | mmsegmentation-master/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 |
mmsegmentation | mmsegmentation-master/tests/test_apis/test_single_gpu.py | # Copyright (c) OpenMMLab. All rights reserved.
import shutil
from unittest.mock import MagicMock
import numpy as np
import pytest
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, Dataset, dataloader
from mmseg.apis import single_gpu_test
class ExampleDataset(Dataset):
def __getitem_... | 1,932 | 25.121622 | 70 | py |
mmsegmentation | mmsegmentation-master/tests/test_core/test_layer_decay_optimizer_constructor.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule
from mmseg.core.optimizers.layer_decay_optimizer_constructor import (
LayerDecayOptimizerConstructor, LearningRateDecayOptimizerConstructor)
base_lr = 1
decay_rate = 2
base_wd = 0.05
we... | 7,796 | 27.25 | 77 | py |
mmsegmentation | mmsegmentation-master/tests/test_core/test_optimizer.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
import torch.nn as nn
from mmcv.runner import DefaultOptimizerConstructor
from mmseg.core.builder import (OPTIMIZER_BUILDERS, build_optimizer,
build_optimizer_constructor)
class ExampleModel(nn.Module):
de... | 2,004 | 32.416667 | 74 | py |
mmsegmentation | mmsegmentation-master/tests/test_data/test_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import os.path as osp
import shutil
import tempfile
from typing import Generator
from unittest.mock import MagicMock, patch
import numpy as np
import pytest
import torch
from PIL import Image
from mmseg.core.evaluation import get_classes, get_palette
from mmse... | 33,787 | 35.926776 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_data/test_dataset_builder.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import os.path as osp
import pytest
from torch.utils.data import (DistributedSampler, RandomSampler,
SequentialSampler)
from mmseg.datasets import (DATASETS, ConcatDataset, MultiImageMixDataset,
build... | 6,416 | 30.925373 | 78 | py |
mmsegmentation | mmsegmentation-master/tests/test_data/test_loading.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
import tempfile
import mmcv
import numpy as np
from mmseg.datasets.pipelines import LoadAnnotations, LoadImageFromFile
class TestLoading(object):
@classmethod
def setup_class(cls):
cls.data_prefix = osp.join(osp.dirna... | 9,151 | 34.890196 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_data/test_transform.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
import mmcv
import numpy as np
import pytest
from mmcv.utils import build_from_cfg
from PIL import Image
from mmseg.datasets.builder import PIPELINES
def test_resize_to_multiple():
transform = dict(type='ResizeToMultiple', size_di... | 26,888 | 34.804261 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_data/test_tta.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import mmcv
import pytest
from mmcv.utils import build_from_cfg
from mmseg.datasets.builder import PIPELINES
def test_multi_scale_flip_aug():
# test assertion if img_scale=None, img_ratios=1 (not float).
with pytest.raises(AssertionError)... | 7,146 | 36.615789 | 75 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
| 48 | 23.5 | 47 | py |
mmsegmentation | mmsegmentation-master/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
from unittest.mock import patch
import numpy as np
import pytest
import torch
import torch.nn as nn
from mmcv.cnn.utils import revert_sync_batchnorm
def _demo_mm_inputs(input_shap... | 6,534 | 26.690678 | 79 | py |
mmsegmentation | mmsegmentation-master/tests/test_models/test_backbones/__init__.py | # Copyright (c) OpenMMLab. All rights reserved.
from .utils import all_zeros, check_norm_state, is_block, is_norm
__all__ = ['is_norm', 'is_block', 'all_zeros', 'check_norm_state']
| 182 | 35.6 | 66 | py |