# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. from core.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()
from copy import deepcopy from core.utils.registry import Registry from pycocotools.coco import COCO BOXES_FILTERS = Registry() @BOXES_FILTERS.register('all') def filter_all(box, im_w, im_h): return True @BOXES_FILTERS.register('center') def filter_center(box, im_w, im_h): x, y, w, h = box cx, cy = x + w/2.0, y + h/2.0 return im_w*0.25 <= cx <= im_w*0.75 and im_h*0.25 <= cy <= im_h*0.75 @BOXES_FILTERS.register('border') def filter_border(box, im_w, im_h): x, y, w, h = box cx, cy = x + w / 2.0, y + h / 2.0 return cx <= im_w*0.25 or cx >= im_w*0.75 or cy <= im_h*0.25 or cy >= im_h*0.75 @BOXES_FILTERS.register('left') def filter_left(box, im_w, im_h): x, y, w, h = box cx, cy = x + w / 2.0, y + h / 2.0 return cx <= im_w*0.25
import itertools import torch import torch.nn.functional as F from torch import nn from core.layers import ConvBlock, NoopLayer from core.utils.registry import Registry from core.modeling.rpn.utils import meshgrid MONTAGE_BOXES = Registry() # register levels MONTAGE_LEVELS = { 'type-1': [0, 1, 2, 3, 4], 'type-2': [0, 1, 2, 3, 4, 2, 3, 4], 'type-3': [0, 1, 2, 3, 4], 'type-4': [0, 1, 2, 3, 4, 2, 3, 4], 'type-5': [0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4], 'type-6': [0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4], 'type-7': [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4], 'type-8': [0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4], 'type-9': [0, 1, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4], 'type-stair1': [1, 1, 1, 1], 'type-stair2': [2, 2, 2, 2], 'type-stair3': [3, 3, 3, 3], 'type-stair4': [4, 4, 4, 4], 'type-sbs1': [1, 1, 1, 1], 'type-sbs2': [2, 2, 2, 2], 'type-sbs3': [3, 3, 3, 3], 'type-sbs4': [4, 4, 4, 4], 'type-grid1': [1, 1, 1, 1], 'type-grid2': [2, 2, 2, 2],
import torch import torch.nn.functional as F from torch import nn from core.layers import ConvBlock, CollectionConvBlock from core.utils.registry import Registry # ATTENTION: all FE modules should provide attribute: `out_channels` FE_MODULES = Registry() class FEModule(torch.nn.Module): """ Feature embedding module """ def __init__(self, cfg, in_channels): super(FEModule, self).__init__() num_convs = cfg.MODEL.RETINAPACK.FE.NUM_CONVS self.out_channels = cfg.MODEL.RETINAPACK.FE.OUT_CHANNELS self.reduction = ConvBlock(in_channels, self.out_channels, kernel_size=1, stride=1, padding=0) self.conv_blocks = nn.ModuleList([ ConvBlock(self.out_channels, self.out_channels, kernel_size=3, use_dcn=False, use_gn=True,
from core.backbone import ResNet from core.utils.registry import Registry BACKBONES = Registry() @BACKBONES.register("ResNet50") @BACKBONES.register("ResNet101") def build_resnet_backbone(cfg): return ResNet(*cfg.backbone.args) @BACKBONES.register("DarkNet53") def build_darknet_backbone(cfg): print("DarkNet53 hasn't been implemented yet, using ResNet instead") return ResNet(*cfg.backbone.args) def build_backbone(cfg): return BACKBONES[cfg.backbone.name](cfg)
out_channels=out_channels, 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, "BottleneckWithGN": BottleneckWithGN, }) _STEM_MODULES = Registry({ "StemWithFixedBatchNorm": StemWithFixedBatchNorm, "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, "R-50-FPN-RETINANET": ResNet50FPNStagesTo5, "R-101-FPN": ResNet101FPNStagesTo5,
# encoding: utf-8 """ @author: liaoxingyu @contact: [email protected] """ import torch from core.utils.registry import Registry META_ARCH_REGISTRY = Registry("META_ARCH") # noqa F401 isort:skip META_ARCH_REGISTRY.__doc__ = """ Registry for meta-architectures, i.e. the whole model. The registered object will be called with `obj(cfg)` and expected to return a `nn.Module` object. """ def build_model(cfg): """ Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``. Note that it does not load any weights from ``cfg``. """ meta_arch = cfg.MODEL.META_ARCHITECTURE model = META_ARCH_REGISTRY.get(meta_arch)(cfg) model.to(torch.device(cfg.MODEL.DEVICE)) return model
* Single-Path NAS Pixel1 - Single-Path NAS: Designing Hardware-Efficient ConvNets - https://arxiv.org/abs/1904.02877 * And likely more... Hacked together by Ross Wightman """ from .efficientnets.efficientnet_builder import * from .efficientnets.conv2d_layers import select_conv2d from .efficientnets.constants import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, \ IMAGENET_INCEPTION_MEAN, IMAGENET_INCEPTION_STD from core.utils.registry import Registry from core.layers import FrozenBatchNorm2d EFN = Registry() _DEBUG = False def _cfg(url='', **kwargs): return { 'url': url, 'num_classes': 1000, 'input_size': (3, 224, 224), 'pool_size': (7, 7), 'crop_pct': 0.875, 'interpolation': 'bicubic', 'mean': IMAGENET_DEFAULT_MEAN, 'std': IMAGENET_DEFAULT_STD, 'first_conv': 'conv_stem', 'classifier': 'classifier',
) logger.info("pattern: {}, old_key: {}, new_key: {}".format( pattern, old_key, new_key )) state_dict[new_key] = state_dict[old_key] del state_dict[old_key] return state_dict _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("-SFPN", "").replace("-FPN", "")