DingXiaoH / DiverseBranchBlock

Diverse Branch Block: Building a Convolution as an Inception-like Unit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plug-in version implementation

zjykzj opened this issue · comments

hi @DingXiaoH , nice work !!! According to borrows your implementation, I'm has realized a plug-in version of DiverseBranchBlock

This plug-in version has the following advantages:

  1. Do not modify original model
  2. After training, can fuse DBB to original architecture
  3. Support mixed insert/fuse operations for ACBlock/RepVGGBlock/DBBlock

How to insert

Use Config FIle

see rd50_dbb_cifar100_224_e100_sgd_calr.yaml

...
MODEL:
  CONV:
    TYPE: 'Conv2d'
    ADD_BLOCKS: ('DiverseBranchBlock',)
...

build resnet50_d with DDB

from zcls.config import cfg
from zcls.model.recognizers.build import build_recognizer

cfg.merge_from_file(args.config_file)
model = build_recognizer(cfg, device=torch.device('cpu'))

Test

see test_dbblock.py

How to fuse

see model_fuse.py

$ python tools/model_fuse.py --help
usage: model_fuse.py [-h] [--verbose] CONFIG_FILE OUTPUT_DIR

Fuse block for ACBlock/RepVGGBLock/DBBlock

positional arguments:
  CONFIG_FILE  path to config file
  OUTPUT_DIR   path to output

optional arguments:
  -h, --help   show this help message and exit
  --verbose    Print Model Info

Other

Structural Parameterization is really a nice idea !!! By using ACBlock, I improved model precision in a Dataset that is more bigger than ImageNet, hope DBB can make better precision

Last, thanks you again