sxhxliang / detectron2_backbone

detectron2 backbone: resnet18, efficientnet, hrnet, mobilenet v2, resnest, bifpn
212 stars 41 forks source link
backbone detectron2 efficientnet hrnet pytorch resnet18

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:

efficientnet:

dla:

resnest:

vovnet:

mobilenet v2:

hrnet:

bifpn:

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"