Git Product home page Git Product logo

detectron2_backbone's Introduction

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"

detectron2_backbone's People

Contributors

philgineer avatar sxhxliang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

detectron2_backbone's Issues

config for resnet18

Hi,

Thanks for this amazing work! Could you (or maybe someone who's got this working) share the config for resnet18 please?

Question mAP and FPS

Dir sxhxliang,

Could I ask you the mAP and FPS you obtain with detectron_efficientNet on COCO dataset?

Thank you

yaml for MobilenetV2

Hi! Just wanted to ask what is the recommended config.yaml for the MobilenetV2 model. Thanks!

efficientnet with FPN can not be run

efficient output shape are:

EEE:  0 torch.Size([4, 16, 512, 400])
EEE:  1 torch.Size([4, 24, 256, 200])
EEE:  2 torch.Size([4, 80, 64, 50])
EEE:  3 torch.Size([4, 112, 64, 50])

this is impossible to run on FPN......

config.yaml

Hi @sxhxliang ,

Could you give me your config.yaml with D0 and D1 please?

Thank you so much

Can dla be used?

I run dla be backbone, but model do not have load_pretrained_model function!

Is this repo really needed for RESNET18 ?

Hello,

I recently started using detectron2, if i want to train a custom dataset on resnet18, don't I just need to take RESNET50 model, set DEPTH to 18 and set RES2_OUT_CHANNELS to 64 ?

This way :

        data["MODEL"]["RESNETS"]["DEPTH"] = 18
        data["MODEL"]["RESNETS"]["RES2_OUT_CHANNELS"] = 64

And obviously, without any trained model to import weights from, set weights to "" and unfreeze first two layers

        cfg.MODEL.WEIGHTS = ""
        cfg.MODEL.BACKBONE.FREEZE_AT = 0

As only for RESNET18, what does this repository brings compared to what I just showed above ?

Apologies if it's a naive question, I'm new to this whole deeplearning stuff.

Thanks

Could you share your config file as a example?

Hi,

I'm impressed by your work.

Could you share your full EfficientDet config file as an example?

Recently, I also implemented bifpn with vovnet but the model result is not as good as the fpn-one.

I expect the reason that is related to the normalization in the bifpn (I tested GN, BN, and SyncBN).

Configs for EfficientNet B0x FPN

Hi there! First I have to say thank you for your amazing work and contribution 😁.

Here is the configuration file that I use for the Faster RCNN EfficientNet B0 FPN;

File faster_rcnn_EfficientNet_B0_FPN.yaml:

MODEL:
  META_ARCHITECTURE: "GeneralizedRCNN"
  MASK_ON: False
  WEIGHTS: "https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b0-355c32eb.pth"
  BACKBONE:
    NAME: "build_efficientnet_fpn_backbone"
    FREEZE_AT: 0
  EFFICIENTNET:
    NAME: "efficientnet_b0" # efficientnet_b1, efficientnet_2,  ..., efficientnet_b7
    FEATURE_INDICES: [1, 4, 10, 15]
    OUT_FEATURES: ["stride4", "stride8", "stride16", "stride32"]
  FPN:
    IN_FEATURES: ["stride4", "stride8", "stride16", "stride32"]
  ANCHOR_GENERATOR:
    SIZES: [[32], [64], [128], [256], [512]]  # One size for each in feature map
    ASPECT_RATIOS: [[0.5, 1.0, 2.0]]  # Three aspect ratios (same for all in feature maps)
  RPN:
    IN_FEATURES: ["p2", "p3", "p4", "p5", "p6"]
    PRE_NMS_TOPK_TRAIN: 2000  # Per FPN level
    PRE_NMS_TOPK_TEST: 1000  # Per FPN level
    # Detectron1 uses 2000 proposals per-batch,
    # (See "modeling/rpn/rpn_outputs.py" for details of this legacy issue)
    # which is approximately 1000 proposals per-image since the default batch size for FPN is 2.
    POST_NMS_TOPK_TRAIN: 1000
    POST_NMS_TOPK_TEST: 1000
  ROI_HEADS:
    NAME: "StandardROIHeads"
    IN_FEATURES: ["p2", "p3", "p4", "p5"]
  ROI_BOX_HEAD:
    NAME: "FastRCNNConvFCHead"
    NUM_FC: 2
    POOLER_RESOLUTION: 7
  ROI_MASK_HEAD:
    NAME: "MaskRCNNConvUpsampleHead"
    NUM_CONV: 4
    POOLER_RESOLUTION: 14
DATASETS:
  TRAIN: ("coco_2017_train",)
  TEST: ("coco_2017_val",)
SOLVER:
  IMS_PER_BATCH: 16
  BASE_LR: 0.02
  STEPS: (60000, 80000)
  MAX_ITER: 90000
INPUT:
  MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)
VERSION: 2

However, replacing the NAME with, for example, efficientnet_b1, It yields a mismatch on the dimensions during training, as the out features of the backbone does not much exactly those of the FPN.

I will really appreciate if you (or anyone!) can help me with that, thanks!

Error in bifpn.py

File "/home/user/detectron2_backbone/detectron2_backbone/backbone/bifpn.py", line 328
def init(self, in_channels, out_channels, norm=''):
^

It seems there are a lot of issues regarding indentation (3 chars instead of 3 etc.).

If I can find the time I will try to fix and make a PR for it.

Pretrained models problem

Appreciate your great work.

In terms of your README, I can only find the pretrained efficientnet model. So where can I download other pretrained models. For example, resnet18, and use the convert_weight.py to convert it for training?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.