#coding=utf-8 import tensorflow as tf from thirdparty.registry import Registry import wmodule _TOTAL_SKIPPED = 0 ROI_KEYPOINT_HEAD_REGISTRY = Registry("ROI_KEYPOINT_HEAD") ROI_KEYPOINT_HEAD_REGISTRY.__doc__ = """ Registry for keypoint heads, which make keypoint predictions from per-region features. The registered object will be called with `obj(cfg, input_shape)`. """ def build_keypoint_head(cfg, *args, **kwargs): """ Build a keypoint head from `cfg.MODEL.ROI_KEYPOINT_HEAD.NAME`. """ name = cfg.MODEL.ROI_KEYPOINT_HEAD.NAME return ROI_KEYPOINT_HEAD_REGISTRY.get(name)(cfg, *args, **kwargs) def keypoint_rcnn_loss(pred_keypoint_logits, instances, normalizer): """ Arguments: pred_keypoint_logits (Tensor): A tensor of shape (N, K, S, S) where N is the total number of instances in the batch, K is the number of keypoints, and S is the side length of the keypoint heatmap. The values are spatial logits. instances (list[Instances]): A list of M Instances, where M is the batch size. These instances are predictions from the model
from thirdparty.registry import Registry REINFORCE_REGISTRY = Registry("REINFORCE_REGISTRY")
from thirdparty.registry import Registry SEMANTIC_HEAD = Registry("SEMANTIC_HEAD") def build_semantic_head(name, *args, **kwargs): head = SEMANTIC_HEAD.get(name)(*args, **kwargs) return head
from thirdparty.registry import Registry import wmodule from .build import PROPOSAL_GENERATOR_REGISTRY from object_detection2.modeling.anchor_generator import * from object_detection2.modeling.box_regression import * from .rpn_outputs import find_top_rpn_proposals from object_detection2.datadef import * import wsummary from object_detection2.modeling.build import build_outputs from object_detection2.modeling.build_matcher import build_matcher import object_detection2.od_toolkit as odtk from object_detection2.modeling.backbone.build import build_hook_by_name slim = tf.contrib.slim RPN_HEAD_REGISTRY = Registry("RPN_HEAD") def build_rpn_head(cfg, *args, **kwargs): """ Build an RPN head defined by `cfg.MODEL.RPN.HEAD_NAME`. """ name = cfg.MODEL.RPN.HEAD_NAME return RPN_HEAD_REGISTRY.get(name)(cfg, *args, **kwargs) @RPN_HEAD_REGISTRY.register() class StandardRPNHead(wmodule.WChildModule): def __init__(self, cfg, parent, *args, **kwargs): super().__init__(cfg, parent, *args, **kwargs) self.anchor_generator = build_anchor_generator(cfg,
from thirdparty.registry import Registry KEYPOINTS_HEAD = Registry("KeyPointsHead") def build_keypoints_head(name, *args, **kwargs): return KEYPOINTS_HEAD.get(name)(*args, **kwargs)
from thirdparty.registry import Registry MATCHER = Registry("MATCHER") # noqa F401 isort:skip def build_matcher(name, *args, **kwargs): return MATCHER.get(name)(*args, **kwargs)
from thirdparty.registry import Registry HEAD_OUTPUTS = Registry("HEAD_OUTPUTS") def build_outputs(name, *args, **kwargs): outputs = HEAD_OUTPUTS.get(name)(*args, **kwargs) return outputs
from thirdparty.registry import Registry from object_detection2.modeling.build import HEAD_OUTPUTS as _HEAD_OUTPUTS from object_detection2.modeling.build import build_outputs as _build_outputs from wmodule import WModelList HEAD_OUTPUTS = _HEAD_OUTPUTS ROI_HEADS_HOOK = Registry("ROI_HEADS_HOOK") ROI_HEADS_REGISTRY = Registry("ROI_HEADS") ROI_HEADS_REGISTRY.__doc__ = """ Registry for ROI heads in a generalized R-CNN model. ROIHeads take feature maps and region proposals, and perform per-region computation. The registered object will be called with `obj(cfg, input_shape)`. The call is expected to return an :class:`ROIHeads`. """ ROI_BOX_HEAD_REGISTRY = Registry("ROI_BOX_HEAD") ROI_BOX_HEAD_REGISTRY.__doc__ = """ Registry for box heads, which make box predictions from per-region features. The registered object will be called with `obj(cfg, input_shape)`. """ ROI_BOX_HEAD_OUTPUTS_LAYER_REGISTRY = Registry("ROI_BOX_HEAD_OUTPUTS_LAYER") def build_roi_heads_hook(cfg, *args, **kwargs): name = cfg.MODEL.ROI_HEADS.HOOK if len(name) > 0: if ";" in name: names = name.split(';') models = []
#coding=utf-8 from thirdparty.registry import Registry PROPOSAL_GENERATOR_REGISTRY = Registry("PROPOSAL_GENERATOR") ''' Proposal的输入为backborn的输出,输出为outdata(key:PD_BOXES [B,N,4], key:PD_PROBABILITY可选[B,N]), loss ''' def build_proposal_generator(cfg, *args, **kwargs): """ Build a proposal generator from `cfg.MODEL.PROPOSAL_GENERATOR.NAME`. The name can be "PrecomputedProposals" to use no proposal generator. """ name = cfg.MODEL.PROPOSAL_GENERATOR.NAME if name == "PrecomputedProposals": return None return PROPOSAL_GENERATOR_REGISTRY.get(name)(cfg, *args, **kwargs) def build_proposal_generator_by_name(name, cfg, *args, **kwargs): """ Build a proposal generator from `cfg.MODEL.PROPOSAL_GENERATOR.NAME`. The name can be "PrecomputedProposals" to use no proposal generator. """ if name == "PrecomputedProposals": return None return PROPOSAL_GENERATOR_REGISTRY.get(name)(cfg, *args, **kwargs)
#coding=utf-8 from thirdparty.registry import Registry import wmodule import wml_tfutils as wmlt import tensorflow as tf import wsummary from object_detection2.datadef import * from collections import Iterable import math import numpy as np ANCHOR_GENERATOR_REGISTRY = Registry("ANCHOR_GENERATOR") def build_anchor_generator(cfg, *args, **kwargs): """ Built an anchor generator from `cfg.MODEL.ANCHOR_GENERATOR.NAME`. """ anchor_generator = cfg.MODEL.ANCHOR_GENERATOR.NAME return ANCHOR_GENERATOR_REGISTRY.get(anchor_generator)(*args, cfg=cfg, **kwargs) class AnchorGeneratorF(object): def __init__(self, scales, aspect_ratios): self.scales = scales self.aspect_ratios = aspect_ratios self.cell_anchors = self.get_cell_anchors() def get_cell_anchors(self):
from thirdparty.registry import Registry import numpy as np from iotoolkit.coco_toolkit import * from object_detection2.standard_names import * FILTER_REGISTRY = Registry("Filter") def build_filter(name): return FILTER_REGISTRY.get(name) @FILTER_REGISTRY.register() def coco2017_balance_sample(x): threshold = 1.0 labels = x[GT_LABELS] freq = tf.gather(COMPRESSED_ID_TO_FREQ, labels) print(COMPRESSED_ID_TO_FREQ) freq = tf.reduce_min(freq) v = threshold / (freq + 1e-8) p = tf.random_uniform(shape=(), minval=0, maxval=1) return tf.less_equal(p, v) @FILTER_REGISTRY.register() def coco2014_balance_sample(x): threshold = 1.0 labels = x[GT_LABELS] freq = tf.gather(ID_TO_FREQ, labels) print(ID_TO_FREQ) freq = tf.reduce_min(freq)
from thirdparty.registry import Registry from .backbone import Backbone BACKBONE_REGISTRY = Registry("BACKBONE") BACKBONE_HOOK_REGISTRY = Registry("BACKBONE_HOOK") BACKBONE_REGISTRY.__doc__ = """ Registry for backbones, which extract feature maps from images The registered object must be a callable that accepts two arguments: 1. A :class:`config.CfgNode` 2. A :class:`layers.ShapeSpec`, which contains the input shape specification. It must returns an instance of :class:`Backbone`. """ def build_backbone(cfg, *args,**kwargs): """ Build a backbone from `cfg.MODEL.BACKBONE.NAME`. Returns: an instance of :class:`Backbone` """ backbone_name = cfg.MODEL.BACKBONE.NAME backbone = BACKBONE_REGISTRY.get(backbone_name)(cfg,*args,**kwargs) assert isinstance(backbone, Backbone) return backbone def build_backbone_by_name(backbone_name,cfg,*args,**kwargs): """
from thirdparty.registry import Registry RETINANET_HEAD = Registry("RetinaNetHead") ONESTAGE_HEAD = Registry("OneStageHead") def build_retinanet_head(name, *args, **kwargs): return RETINANET_HEAD.get(name)(*args, **kwargs) def build_onestage_head(name, *args, **kwargs): return ONESTAGE_HEAD.get(name)(*args, **kwargs)
from thirdparty.registry import Registry DATAPROCESS_REGISTRY = Registry("DATAPROCESS")
from thirdparty.registry import Registry import wmodule import tensorflow as tf import wml_tfutils as wmlt from object_detection2.datadef import * import object_detection2.config.config as config import image_visualization as ivis import wsummary import img_utils as wmli import object_detection2.od_toolkit as odt import basic_tftools as btf from basic_tftools import channel as get_channel slim = tf.contrib.slim ROI_MASK_HEAD_REGISTRY = Registry("ROI_MASK_HEAD") ROI_MASK_HEAD_REGISTRY.__doc__ = """ Registry for mask heads, which predicts instance masks given per-region features. The registered object will be called with `obj(cfg, input_shape)`. """ @wmlt.add_name_scope def mask_rcnn_loss(inputs, pred_mask_logits, proposals: EncodedData, fg_selection_mask, log=True): '''
from thirdparty.registry import Registry MOT_REGISTRY = Registry("MOT") def build_mot(cfg, model, *args, **kwargs): name = cfg.MODEL.MOT.NAME mot = MOT_REGISTRY.get(name)(model, *args, **kwargs) return mot
from thirdparty.registry import Registry MOT_HEAD = Registry("MOTHEADS") def build_MOT_head(name, *args, **kwargs): return MOT_HEAD.get(name)(*args, **kwargs)
from thirdparty.registry import Registry META_ARCH_REGISTRY = Registry("META_ARCH") # noqa F401 isort:skip def build_model(cfg, **kwargs): """ 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 return META_ARCH_REGISTRY.get(meta_arch)(cfg, **kwargs)