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
- install detectron2 and detectron2_backbone
- import detectron2,
import detectron2
. - import detectron2_backbone
import detectron2_backbone
- 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
# your_config.yaml
MODEL:
WEIGHTS: "your_path/resnet18_detectron2.pth"
BACKBONE:
NAME: "build_resnet18_fpn_backbone"
...
- build_resnet18_bacbkone
- build_resnet18_fpn_backbone
- build_fcos_resnet18_fpn_backbone
- 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"]
...
- build_dla_backbone
- build_dla_fpn_backbone
- build_fcos_dla_fpn_backbone
- build_resnest_backbone
- build_resnest_fpn_backbone
- build_fcos_resnest_fpn_backbone
- build_vovnet_backbone
- build_vovnet_fpn_backbone
- build_fcos_vovnet_fpn_backbone
- build_mnv2_backbone
- build_mnv2_fpn_backbone
- build_fcos_mnv2_fpn_backbone
- build_hrnet_backbone
- build_hrnet_fpn_backbone
- 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
...
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"