Esempio n. 1
0
def FBNetV2FpnBackbone(cfg, _):
    backbone = FBNetV2FPN(
        bottom_up=build_fbnet_backbone(cfg),
        in_features=cfg.MODEL.FPN.IN_FEATURES,
        out_channels=cfg.MODEL.FPN.OUT_CHANNELS,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
    )

    return backbone
Esempio n. 2
0
def build_efficientnet_fpn_backbone(cfg, input_shape: ShapeSpec):
    bottom_up = build_efficientnet_backbone(cfg, input_shape)
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
Esempio n. 3
0
 def __init__(self, cfg, input_shape):
     bottom_up = build_resnet_backbone(cfg, input_shape)
     in_features = cfg.MODEL.FPN.IN_FEATURES
     out_channels = cfg.MODEL.FPN.OUT_CHANNELS
     super().__init__(
         bottom_up=bottom_up,
         in_features=in_features,
         out_channels=out_channels,
         norm=cfg.MODEL.FPN.NORM,
         top_block=LastLevelMaxPool(),
         fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
     )
     input_shapes = bottom_up.output_shape()
     self.quantizer = build_quantizer(cfg, input_shapes)
Esempio n. 4
0
def build_mnetv2_fpn_backbone(cfg, input_shape: ShapeSpec):
    bottom_up = build_mnetv2_backbone(cfg, input_shape)
    # ['res5', ...]
    in_features = cfg.MODEL.FPN.IN_FEATURES
    # scalar
    out_features = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
def build_mobilenetv2_flgc_fpn_backbone(cfg, input_shape: ShapeSpec):
    out_features = cfg.MODEL.MOBILENET.OUT_FEATURES
    bottom_up = MobileNetV2(cfg, groups_in_1x1=8)
    bottom_up._out_features = out_features
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
Esempio n. 6
0
def fPNBackBone(model_name="resnet34", pretrained=False, freeze_at=2):
    # ["res2", "res3", "res4", "res5"]
    in_features = ["res2", "res3", "res4", "res5"]
    out_channels = 256
    norm = ""  # "GN"
    fuse_type = "sum"  # "sum" or "avg"
    backbone = FPN(
        bottom_up=ResnetBone(model_name, pretrained, freeze_at),
        in_features=in_features,
        out_channels=out_channels,
        norm=norm,
        top_block=LastLevelMaxPool(),
        fuse_type=fuse_type,
    )

    return backbone
Esempio n. 7
0
def build_efficientnetv2_bifpn_backbone(cfg, input_shape: ShapeSpec):
    """
    Args:
        cfg: a detectron2 CfgNode

    Returns:
        modeling (Backbone): modeling module, must be a subclass of :class:`Backbone`.
    """
    bottom_up = build_efficientnetv2_backbone(cfg, input_shape)
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = BiFPN(
        bottom_up=bottom_up,
        out_channels=out_channels,
        top_block=LastLevelMaxPool(),
    )
    return backbone
def build_efficientnet_fpn_backbone(cfg, input_shape: ShapeSpec):
    """
    Args:
        cfg: a detectron2 CfgNode

    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
    """
    bottom_up = build_efficientnet_backbone(cfg, input_shape)
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(bottom_up=bottom_up,
                   in_features=in_features,
                   out_channels=out_channels,
                   norm=cfg.MODEL.FPN.NORM,
                   top_block=LastLevelMaxPool(),
                   fuse_type=cfg.MODEL.FPN.FUSE_TYPE)
    return backbone
Esempio n. 9
0
def build_fpn(cfg, input_shape: ShapeSpec):
    """Build feature pyramid network.

    Args:
        cfg: a detectron2 CfgNode
        bottom_up(Backbone): bottom_up backbone

    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
    """
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    fpn = FPN(
        input_shapes=input_shape,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return fpn
Esempio n. 10
0
def build_vovnet_fpn_backbone(cfg, input_shape: ShapeSpec):
    """Create a VoVNet + FPN instance from config. The type of network (mobilenet-like or deeper model) is defined by the CONV_BODY config entry.

    Args:
        cfg: a detectron2 CfgNode
        input_shape (ShapeSpec): this argument is needed by Detectron2 althought not used here
    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
    """
    bottom_up = build_vovnet_backbone(cfg, input_shape)
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
def build_mobilenetv2_quantization_fpn_backbone(cfg, input_shape: ShapeSpec):
    """
    Args:
        cfg: a detectron2 CfgNode
    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
    """
    _out_features = cfg.MODEL.MOBILENET.OUT_FEATURES
    bottom_up = mobilenet_v2(cfg)
    bottom_up._out_features = _out_features
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
def build_hrnet_fpn_backbone(cfg, input_shape: ShapeSpec):
    """
    Args:
        cfg: a detectron2 CfgNode

    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`.
    """
    bottom_up = HRNet(cfg)
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = HRFPN(
        cfg=cfg,
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    # import ipdb;ipdb.set_trace()
    return backbone
def build_mobilenet_fpn_backbone(cfg, input_shape: ShapeSpec):
    """Create a MobileNetV2 + FPN instance from config. 

    Args:
        cfg (cfgNode): Detectron2's cfg object
        input_shape (ShapeSpec): this argument is needed by Detectron2 althought not used here

    Returns:
        backbone (Backbone): backbone module, must be a subclass of :class:`Backbone`
    """

    bottom_up = build_mobilenet_backbone(cfg, input_shape)
    in_features = cfg.MODEL.FPN.IN_FEATURES
    out_channels = cfg.MODEL.FPN.OUT_CHANNELS
    backbone = FPN(
        bottom_up=bottom_up,
        in_features=in_features,
        out_channels=out_channels,
        norm=cfg.MODEL.FPN.NORM,
        top_block=LastLevelMaxPool(),
        fuse_type=cfg.MODEL.FPN.FUSE_TYPE,
    )
    return backbone
Esempio n. 14
0
        p4_out = self.p4_out(
            self.fuse_p4_out([p4, p4_tr, self.down_p3(p3_out)]))
        p5_out = self.p5_out(self.fuse_p5_out([p5, self.down_p4(p4_out)]))

        return {
            "p2": p2_out,
            "p3": p3_out,
            "p4": p4_out,
            "p5": p5_out,
            "p6": self.top_block(p5_out)[0]
        }

    def output_shape(self):
        return {
            name: ShapeSpec(channels=self._out_feature_channels[name],
                            stride=self._out_feature_strides[name])
            for name in self._out_features
        }


if __name__ == "__main__":
    m = timm.create_model('spnasnet_100',
                          pretrained=True,
                          features_only=True,
                          out_indices=(1, 2, 3, 4))
    x = torch.rand(1, 3, 224, 224)
    m2 = BiFPN(bottom_up=m, out_channels=112, top_block=LastLevelMaxPool())
    # torch.jit.trace(m2, x)
    m2 = torch.jit.script(m2)
    print(m2(x))