Example #1
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
NECKS = Registry()
ONE_STAGE_HEADS = Registry()
PANOPTIC_HEADS = Registry()
RPN_HEADS = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()
Example #2
0
                             num_groups=num_groups,
                             stride_in_1x1=stride_in_1x1,
                             stride=stride,
                             dilation=dilation,
                             norm_func=group_norm)


class StemWithGN(BaseStem):
    def __init__(self, cfg):
        super(StemWithGN, self).__init__(cfg, norm_func=group_norm)


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm":
    BottleneckWithFixedBatchNorm,
    "BottleneckWithGN":
    BottleneckWithGN,
    "BottleneckFixedBN_Mish":
    BottleneckFixedBN_Mish
})

_STEM_MODULES = Registry({
    "StemWithFixedBatchNorm": StemWithFixedBatchNorm,
    "RootStemWithFixedBatchNorm": RootStemWithFixedBatchNorm,
    "StemWithGN": StemWithGN,
    "RootStemWithGN": RootStemWithGN,
})

_STAGE_SPECS = Registry({
    "R-50-C4": ResNet50StagesTo4,
    "R-50-C5": ResNet50StagesTo5,
    "R-101-C4": ResNet101StagesTo4,
Example #3
0
import sys

import torch
import torch.nn as nn
from torch import Tensor
from torch.nn import Module

from maskrcnn_benchmark.utils.registry import Registry

sys.setrecursionlimit(10000)


MODULE_FLOPS_COMP = Registry()


@MODULE_FLOPS_COMP.register("Conv2d")
def build_conv2d_flops(module: Module, oup: Tensor):
    kh, kw = module.kernel_size
    in_channels = module.in_channels
    out_channels = module.out_channels
    groups = module.groups
    h, w = oup.shape[-2:]
    return in_channels * out_channels * w * h * kh * kw // groups


@MODULE_FLOPS_COMP.register("Linear")
def build_linear_flops(module: Module, oup: Tensor):
    in_features = module.in_features
    out_features = module.out_features
    return in_features * out_features
Example #4
0
    'eSE': True
}

VoVNet99_eSE_FPNStagesTo5 = {
    'config_stage_ch': [128, 160, 192, 224],
    'config_concat_ch': [256, 512, 768, 1024],
    'layer_per_block': 5,
    'block_per_stage': [1, 3, 9, 3],
    'eSE': True
}

_STAGE_SPECS = Registry({
    "V-19-eSE-FPN-RETINANET": VoVNet19_eSE_FPNStagesTo5,
    "V-39-eSE-FPN-RETINANET": VoVNet39_eSE_FPNStagesTo5,
    "V-57-eSE-FPN-RETINANET": VoVNet57_eSE_FPNStagesTo5,
    "V-99-eSE-FPN-RETINANET": VoVNet99_eSE_FPNStagesTo5,
    "V-19-eSE-FPN": VoVNet19_eSE_FPNStagesTo5,
    "V-39-eSE-FPN": VoVNet39_eSE_FPNStagesTo5,
    "V-57-eSE-FPN": VoVNet57_eSE_FPNStagesTo5,
    "V-99-eSE-FPN": VoVNet99_eSE_FPNStagesTo5
})


def freeze_bn_params(m):
    """Freeze all the weights by setting requires_grad to False
    """
    m.eval()
    for p in m.parameters():
        p.requires_grad = False


def conv3x3(in_channels,
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
RPN_HEADS = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()

CLASSIFIER_ENCODER = Registry()
CLASSIFIER_DECODER = Registry()
Example #6
0
from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
RPN_HEADS = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()
Example #7
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
RPN_HEADS = Registry()
Example #8
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
RPN_HEADS = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()
SEG_BRANCH = Registry()
INTER_MODULE = Registry()
Example #9
0
# Copyright (c) 2021 Microsoft Corporation. Licensed under the MIT license.
from maskrcnn_benchmark.utils.registry import Registry

ROI_ATTRIBUTE_FEATURE_EXTRACTORS = Registry()
ROI_ATTRIBUTE_PREDICTOR = Registry()
ROI_RELATION_FEATURE_EXTRACTORS = Registry()
ROI_RELATION_PREDICTOR = Registry()
ROI_RELATION_BOX_FEATURE_EXTRACTORS = Registry()
ROI_RELATION_BOX_PREDICTOR = Registry()
Example #10
0
from maskrcnn_benchmark.utils.registry import Registry

SIAMESE_TRACKER = Registry()
TRACKER_SAMPLER = Registry()
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
RPN_HEADS = Registry()
SEMANTIC_HEADS = Registry()
UPSAMPLE_MODULES = Registry()
Example #12
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()

RPN_HEADS = Registry()
STEREO_RPN_V1_HEADS = Registry()

ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()

ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()

ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()

ROI_BOX_STEREO_V1_FEATURE_EXTRACTORS = Registry()
ROI_BOX_STEREO_V1_PREDICTOR = Registry()

ROI_BOX_STEREO_V2_FEATURE_EXTRACTORS = Registry()
ROI_BOX_STEREO_V2_PREDICTOR = Registry()

ROI_BOX_TD_V1_FEATURE_EXTRACTORS = Registry()
ROI_BOX_TD_V1_PREDICTOR = Registry()

ROI_BOX_TD_V2_FEATURE_EXTRACTORS = Registry()
ROI_BOX_TD_V2_PREDICTOR = Registry()

ROI_BOX_TD_V3_FEATURE_EXTRACTORS = Registry()
Example #13
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
RPN_HEADS = Registry()

ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()

ROI_PRED_FEATURE_EXTRACTORS = Registry()
ROI_PRED_PREDICTOR = Registry()

DECODER_CLS_FEATURE_EXTRACTORS = Registry()
DECODER_CLS_PREDICTOR = Registry()

ATTENTION_MECHANISM = Registry()

POOLER = Registry()
Example #14
0
"""darknet19 from https://pjreddie.com/darknet/imagenet/"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import torch
import torch.nn as nn
import torch.nn.functional as F
from maskrcnn_benchmark.layers import FrozenBatchNorm2d
from maskrcnn_benchmark.utils.registry import Registry

_NORMALIZATION_MODULES = Registry({
    "FrozenBatchNorm2d": FrozenBatchNorm2d,
    "BatchNorm2d": nn.BatchNorm2d,
})

def add_stage(
    n,
    dim_in,
    dim_out1,
    dim_inner,
    normalization
):
    """Add a ResNet stage to the model by stacking n residual blocks."""
    blocks = []
    for i in range(n):
        blocks.append(Xception_block(
            dim_in,
            dim_out1,
        else:
            data = pickle.load(f)
    if "blobs" in data:
        weights = data["blobs"]
    else:
        weights = data
    return weights


_C2_STAGE_NAMES = {
    "R-50": ["1.2", "2.3", "3.5", "4.2"],
    "R-101": ["1.2", "2.3", "3.22", "4.2"],
    "R-152": ["1.2", "2.7", "3.35", "4.2"],
}

C2_FORMAT_LOADER = Registry()


@C2_FORMAT_LOADER.register("R-50-C4")
@C2_FORMAT_LOADER.register("R-50-C5")
@C2_FORMAT_LOADER.register("R-101-C4")
@C2_FORMAT_LOADER.register("R-101-C5")
@C2_FORMAT_LOADER.register("R-50-FPN")
@C2_FORMAT_LOADER.register("R-50-FPN-RETINANET")
@C2_FORMAT_LOADER.register("R-101-FPN")
@C2_FORMAT_LOADER.register("R-101-FPN-RETINANET")
@C2_FORMAT_LOADER.register("R-152-FPN")
def load_resnet_c2_format(cfg, f):
    state_dict = _load_c2_pickled_weights(f)
    conv_body = cfg.MODEL.BACKBONE.CONV_BODY
    arch = conv_body.replace("-C4", "").replace("-C5", "").replace("-FPN", "")
Example #16
0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

from maskrcnn_benchmark.utils.registry import Registry

BACKBONES = Registry()
RPN_HEADS = Registry()
ROI_BOX_FEATURE_EXTRACTORS = Registry()
ROI_BOX_PREDICTOR = Registry()
ROI_ATTRIBUTE_FEATURE_EXTRACTORS = Registry()
ROI_ATTRIBUTE_PREDICTOR = Registry()
ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry()
ROI_KEYPOINT_PREDICTOR = Registry()
ROI_MASK_FEATURE_EXTRACTORS = Registry()
ROI_MASK_PREDICTOR = Registry()
ROI_RELATION_FEATURE_EXTRACTORS = Registry()
ROI_RELATION_PREDICTOR = Registry()
Example #17
0
def dla_169(dcn_config, feature_only=True, batch_norm=FrozenBatchNorm2d):
    model = DLA([1, 1, 2, 3, 5, 1], [16, 32, 128, 256, 512, 1024],
                block=DlaBottleneck,
                residual_root=True,
                batch_norm=batch_norm,
                feature_only=feature_only,
                dcn_config=dcn_config)
    return model


BACKBONE = Registry({
    "DLA-34-FPN": dla_34,
    "DLA-46-C-FPN": dla_46_c,
    "DLA-46-XC-FPN": dla_46_xc,
    "DLA-60-FPN": dla_60,
    "DLA-60-RES2NET-FPN": dla60_res2net,
    "DLA-102-FPN": dla_102,
    "DLA-169-FPN": dla_169
})

BACKBONE_ARCH = {
    "DLA-34-FPN": "dla34",
    "DLA-46-C-FPN": "dla_46_c",
    "DLA-46-XC-FPN": "dla_46_xc",
    "DLA-60-FPN": "dla_60",
    "DLA-60-RES2NET-FPN": "dla60_res2net",
    "DLA-102-FPN": "dla_102",
    "DLA-169-FPN": "dla_169"
}
    ):
        super(TridentBottleneckWithFixedBatchNorm, self).__init__(
            in_channels=in_channels,
            bottleneck_channels=bottleneck_channels,
            out_channels=out_channels,
            num_groups=num_groups,
            stride_in_1x1=stride_in_1x1,
            stride=stride,
            dilation=dilation,
            norm_func=TridentFrozenBatchNorm2d,
        )


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm,
    "BottleneckWithGN": BottleneckWithGN,
    "TridentBottleneckWithFixedBatchNorm": TridentBottleneckWithFixedBatchNorm,
})

_STEM_MODULES = Registry({
    "StemWithFixedBatchNorm": StemWithFixedBatchNorm,
    "StemWithGN": StemWithGN,
})

_STAGE_SPECS = Registry({
    "T-R-50-C5": TridentResNet50StagesTo5,
    "T-R-101-C5": TridentResNet101StagesTo5,
    "T-R-50-FPN": TridentResNet50FPNStagesTo5,
    "T-R-101-FPN": TridentResNet101FPNStagesTo5,
    "T-R-152-FPN": TridentResNet152FPNStagesTo5,
})
Example #19
0
    def __init__(self, cfg):
        super(StemWithFixedBatchNorm, self).__init__()

        out_channels = cfg.MODEL.SENET.STEM_OUT_CHANNELS

        self.conv1 = Conv2d(
            3, out_channels, kernel_size=7, stride=2, padding=3, bias=False
        )
        self.bn1 = FrozenBatchNorm2d(out_channels)

    def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = F.relu_(x)
        x = F.max_pool2d(x, kernel_size=3, stride=2, padding=1)
        return x


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm
})

_STEM_MODULES = Registry({"StemWithFixedBatchNorm": StemWithFixedBatchNorm})

_STAGE_SPECS = Registry({
    "SE-50-C4": SENet50StagesTo4,
    "SE-50-C5": SENet50StagesTo5,
    "SE-50-FPN": SENet50FPNStagesTo5,
    "SE-101-FPN": SENet101FPNStagesTo5,
})
Example #20
0
from maskrcnn_benchmark.utils.registry import Registry

ROI_GRAPH_FEATURE_EXTRACTORS = Registry()
ROI_GRAPH_PREDICTOR = Registry()
Example #21
0
                             num_groups=num_groups,
                             stride_in_1x1=stride_in_1x1,
                             stride=stride,
                             dilation=dilation,
                             norm_func=group_norm,
                             dcn_config=dcn_config)


class StemWithGN(BaseStem):
    def __init__(self, cfg):
        super(StemWithGN, self).__init__(cfg, norm_func=group_norm)


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm,
    "BottleneckWithBatchNorm": BottleneckWithBatchNorm,
    "BottleneckWithGN": BottleneckWithGN,
})

_STEM_MODULES = Registry({
    "StemWithFixedBatchNorm": StemWithFixedBatchNorm,
    "StemWithBatchNorm": StemWithBatchNorm,
    "StemWithGN": StemWithGN,
})

_STAGE_SPECS = Registry({
    "R-50-C4": ResNet50StagesTo4,
    "R-50-C5": ResNet50StagesTo5,
    "R-101-C4": ResNet101StagesTo4,
    "R-101-C5": ResNet101StagesTo5,
    "R-50-FPN": ResNet50FPNStagesTo5,
Example #22
0
        super(BottleneckWithGN,
              self).__init__(in_channels=in_channels,
                             bottleneck_channels=bottleneck_channels,
                             out_channels=out_channels,
                             num_groups=num_groups,
                             stride_in_1x1=stride_in_1x1,
                             stride=stride,
                             dilation=dilation,
                             norm_func=group_norm)


class StemWithGN(BaseStem):
    def __init__(self, cfg):
        super(StemWithGN, self).__init__(cfg, norm_func=group_norm)


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm,
    "BottleneckWithGN": BottleneckWithGN,
})

_STEM_MODULES = Registry({
    "StemWithFixedBatchNorm": StemWithFixedBatchNorm,
    "StemWithGN": StemWithGN,
})

_STAGE_SPECS = Registry({
    "OR-50-FPN": OR_ResNet50FPNStagesTo5,
    "OR-101-FPN": OR_ResNet101FPNStagesTo5,
})
Example #23
0
    'block_per_stage': [1, 2, 6, 3]
}

VoVNet93FPNStagesTo5 = {
    'config_stage_ch': [128, 160, 192, 224],
    'config_concat_ch': [256, 512, 768, 1024],
    'layer_per_block': 5,
    'block_per_stage': [1, 3, 8, 3]
}

_STAGE_SPECS = Registry({
    "V-27-FPN": VoVNet27FPNStagesTo5,
    "V-39-FPN": VoVNet39FPNStagesTo5,
    "V-57-FPN": VoVNet57FPNStagesTo5,
    "V-75-FPN": VoVNet75FPNStagesTo5,
    "V-93-FPN": VoVNet93FPNStagesTo5,
    "V-27-FPN-RETINANET": VoVNet27FPNStagesTo5,
    "V-39-FPN-RETINANET": VoVNet39FPNStagesTo5,
    "V-57-FPN-RETINANET": VoVNet57FPNStagesTo5,
    "V-75-FPN-RETINANET": VoVNet75FPNStagesTo5,
    "V-93-FPN-RETINANET": VoVNet93FPNStagesTo5
})

def freeze_bn_params(m):
    """Freeze all the weights by setting requires_grad to False
    """
    m.eval()
    for p in m.parameters():
        p.requires_grad = False

def conv3x3(in_channels, out_channels, module_name, postfix, stride=1, groups=1, kernel_size=3, padding=1):
    """3x3 convolution with padding"""
Example #24
0
                bottleneck_channels,
                out_channels,
                num_groups,
                stride_in_1x1,
                stride,
                dilation=dilation,
                norm_func=FrozenBatchNorm2d,
                deform=deform,
            )
        )
        stride = 1
        in_channels = out_channels
    return nn.Sequential(*blocks)


_TRANSFORMATION_MODULES = Registry({
    "BottleneckWithFixedBatchNorm": BottleneckWithFixedBatchNorm,
    "BottleneckWithGN": BottleneckWithGN,
})

_STEM_MODULES = Registry({
    "StemWithFixedBatchNorm": StemWithFixedBatchNorm,
    "StemWithGN": StemWithGN,
})

_STAGE_SPECS = Registry({
    "D-59-C6": DetNet59StagesTo6,
    "D-59-FPN": DetNet59FPNStagesTo6,
    "D-59-D-FPN": DetNet59DeformFPNStagesTo6,
})