Skip to content

Latest commit

 

History

History
144 lines (116 loc) · 3.24 KB

README.md

File metadata and controls

144 lines (116 loc) · 3.24 KB

Detectron2_Backbone

Installation

First install Detectron2 following the official guide: INSTALL.md. Then build detectron2_backbone with:

git clone https://github.com/sxhxliang/detectron2_backbone.git
cd detectron2_backbone
python setup.py build develop

Quick Start

  1. install detectron2 and detectron2_backbone
  2. import detectron2, import detectron2.
  3. import detectron2_backbone import detectron2_backbone
  4. add config to detectron2
# for example
# import detectron2
import detectron2 
from detectron2.config import get_cfg
# import detectron2_backbone
from detectron2_backbone import backbone
from detectron2_backbone.config import add_backbone_config

def setup(args):
    """
    Create configs and perform basic setups.
    """
    cfg = get_cfg()
    # add config to detectron2
    add_backbone_config(cfg)
    cfg.merge_from_file(args.config_file)
    cfg.merge_from_list(args.opts)
    cfg.freeze()
    default_setup(cfg, args)
    return cfg

Build Your Own Models

# your_config.yaml
MODEL:
  WEIGHTS: "your_path/resnet18_detectron2.pth"
  BACKBONE:
    NAME: "build_resnet18_fpn_backbone"
  ...

Backbones for Detectron2

resnet18:

  • build_resnet18_bacbkone
  • build_resnet18_fpn_backbone
  • build_fcos_resnet18_fpn_backbone

efficientnet:

  • build_efficientnet_backbone
  • build_efficientnet_fpn_backbone
  • build_fcos_efficientnet_fpn_backbone
# your_config.yaml
MODEL:
  WEIGHTS: "your_path/efficientnet_b0_detectron2.pth"
  BACKBONE:
    NAME: "build_efficientnet_fpn_backbone"
  EFFICIENTNET:
    NAME: "efficientnet_b0" # efficientnet_b1, efficientnet_2,  ..., efficientnet_b7
    OUT_FEATURES: ["stride4", "stride8", "stride16", "stride32"]
  FPN:
    IN_FEATURES: ["stride4", "stride8", "stride16", "stride32"]
  ...

dla:

  • build_dla_backbone
  • build_dla_fpn_backbone
  • build_fcos_dla_fpn_backbone

resnest:

  • build_resnest_backbone
  • build_resnest_fpn_backbone
  • build_fcos_resnest_fpn_backbone

vovnet:

  • build_vovnet_backbone
  • build_vovnet_fpn_backbone
  • build_fcos_vovnet_fpn_backbone

mobilenet v2:

  • build_mnv2_backbone
  • build_mnv2_fpn_backbone
  • build_fcos_mnv2_fpn_backbone

hrnet:

  • build_hrnet_backbone
  • build_hrnet_fpn_backbone

bifpn:

  • build_efficientnet_bifpn_backbone
# your_config.yaml
MODEL:
  WEIGHTS: "your_path/efficientnet_b0_detectron2.pth"
  BACKBONE:
    NAME: "build_efficientnet_bifpn_backbone"
  EFFICIENTNET:
    NAME: "efficientnet_b0" # efficientnet_b1, efficientnet_2,  ..., efficientnet_b7
    OUT_FEATURES: ["stride8", "stride16", "stride32"]
  FPN:
    IN_FEATURES: ["stride8", "stride16", "stride32"]
    OUT_CHANNELS: 64
    REPEAT: 3
  ...

Convert Model for Detectron2

python3 -m detectron2_backbone.tools.convert_weight --help
# download model
wget https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b0-355c32eb.pth -P your_path
# convert weight
python3 -m detectron2_backbone.tools.convert_weight --model your_path/efficientnet-b0-355c32eb.pth --output your_path/efficientnet_b0_detectron2.pth
your_config.yaml
MODEL:
  WEIGHTS: "your_path/efficientnet_b0_detectron2.pth"