Commit 495d9ed9 authored by limm's avatar limm
Browse files

add part code

parent 59b09903
Pipeline #2799 canceled with stages
_base_ = ['./regnetx-400mf_8xb128_in1k.py']
# model settings
model = dict(
backbone=dict(type='RegNet', arch='regnetx_800mf'),
head=dict(in_channels=672, ))
# RepLKNet
> [Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs](https://arxiv.org/abs/2203.06717)
<!-- [ALGORITHM] -->
## Abstract
We revisit large kernel design in modern convolutional neural networks (CNNs). Inspired by recent advances in vision transformers (ViTs), in this paper, we demonstrate that using a few large convolutional kernels instead of a stack of small kernels could be a more powerful paradigm. We suggested five guidelines, e.g., applying re-parameterized large depth-wise convolutions, to design efficient highperformance large-kernel CNNs. Following the guidelines, we propose RepLKNet, a pure CNN architecture whose kernel size is as large as 31×31, in contrast to commonly used 3×3. RepLKNet greatly closes the performance gap between CNNs and ViTs, e.g., achieving comparable or superior results than Swin Transformer on ImageNet and a few typical downstream tasks, with lower latency. RepLKNet also shows nice scalability to big data and large models, obtaining 87.8% top-1 accuracy on ImageNet and 56.0% mIoU on ADE20K, which is very competitive among the state-of-the-arts with similar model sizes. Our study further reveals that, in contrast to small-kernel CNNs, large kernel CNNs have much larger effective receptive fields and higher shape bias rather than texture bias.
<div align=center>
<img src="https://user-images.githubusercontent.com/48375204/197546040-cdf078c3-7fbd-400f-8b27-01668c8dfebf.png" width="60%"/>
</div>
## How to use it?
<!-- [TABS-BEGIN] -->
**Predict image**
```python
from mmpretrain import inference_model, get_model
model = get_model('replknet-31B_3rdparty_in1k', pretrained=True)
model.backbone.switch_to_deploy()
predict = inference_model(model, 'demo/bird.JPEG')
print(predict['pred_class'])
print(predict['pred_score'])
```
**Use the model**
```python
import torch
from mmpretrain import get_model
model = get_model('replknet-31B_3rdparty_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))
```
**Test Command**
Prepare your dataset according to the [docs](https://mmpretrain.readthedocs.io/en/latest/user_guides/dataset_prepare.html#prepare-dataset).
Test:
```shell
python tools/test.py configs/replknet/replknet-31B_32xb64_in1k.py https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_3rdparty_in1k_20221118-fd08e268.pth
```
**Reparameterization**
The checkpoints provided are all `training-time` models. Use the reparameterize tool to switch them to more efficient `inference-time` architecture, which not only has fewer parameters but also less calculations.
```bash
python tools/convert_models/reparameterize_model.py ${CFG_PATH} ${SRC_CKPT_PATH} ${TARGET_CKPT_PATH}
```
`${CFG_PATH}` is the config file, `${SRC_CKPT_PATH}` is the source chenpoint file, `${TARGET_CKPT_PATH}` is the target deploy weight file path.
To use reparameterized weights, the config file must switch to the deploy config files.
```bash
python tools/test.py ${deploy_cfg} ${deploy_checkpoint} --metrics accuracy
```
You can also use `backbone.switch_to_deploy()` to switch to the deploy mode in Python code. For example:
```python
from mmpretrain.models import RepLKNet
backbone = RepLKNet(arch='31B')
backbone.switch_to_deploy()
```
<!-- [TABS-END] -->
## Models and results
### Image Classification on ImageNet-1k
| Model | Pretrain | Params (M) | Flops (G) | Top-1 (%) | Top-5 (%) | Config | Download |
| :--------------------------------------------- | :----------: | :--------: | :-------: | :-------: | :-------: | :-----------------------------------------: | :------------------------------------------------------------: |
| `replknet-31B_3rdparty_in1k`\* | From scratch | 79.86 | 15.64 | 83.48 | 96.57 | [config](replknet-31B_32xb64_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_3rdparty_in1k_20221118-fd08e268.pth) |
| `replknet-31B_3rdparty_in1k-384px`\* | From scratch | 79.86 | 45.95 | 84.84 | 97.34 | [config](replknet-31B_32xb64_in1k-384px.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_3rdparty_in1k-384px_20221118-03a170ce.pth) |
| `replknet-31B_in21k-pre_3rdparty_in1k`\* | ImageNet-21k | 79.86 | 15.64 | 85.20 | 97.56 | [config](replknet-31B_32xb64_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_in21k-pre_3rdparty_in1k_20221118-54ed5c46.pth) |
| `replknet-31B_in21k-pre_3rdparty_in1k-384px`\* | ImageNet-21k | 79.86 | 45.95 | 85.99 | 97.75 | [config](replknet-31B_32xb64_in1k-384px.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_in21k-pre_3rdparty_in1k-384px_20221118-76c92b24.pth) |
| `replknet-31L_in21k-pre_3rdparty_in1k-384px`\* | ImageNet-21k | 172.67 | 97.24 | 86.63 | 98.00 | [config](replknet-31L_32xb64_in1k-384px.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31L_in21k-pre_3rdparty_in1k-384px_20221118-dc3fc07c.pth) |
| `replknet-XL_meg73m-pre_3rdparty_in1k-320px`\* | MEG73M | 335.44 | 129.57 | 87.57 | 98.39 | [config](replknet-XL_32xb64_in1k-320px.py) | [model](https://download.openmmlab.com/mmclassification/v0/replknet/replknet-XL_meg73m-pre_3rdparty_in1k-320px_20221118-88259b1d.pth) |
*Models with * are converted from the [official repo](https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py). The config files of these models are only for inference. We haven't reproduce the training results.*
## Citation
```bibtex
@inproceedings{ding2022scaling,
title={Scaling up your kernels to 31x31: Revisiting large kernel design in cnns},
author={Ding, Xiaohan and Zhang, Xiangyu and Han, Jungong and Ding, Guiguang},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={11963--11975},
year={2022}
}
```
_base_ = '../replknet-31B_32xb64_in1k-384px.py'
model = dict(backbone=dict(small_kernel_merged=True))
_base_ = '../replknet-31B_32xb64_in1k.py'
model = dict(backbone=dict(small_kernel_merged=True))
_base_ = '../replknet-31L_32xb64_in1k-384px.py'
model = dict(backbone=dict(small_kernel_merged=True))
_base_ = '../replknet-XL_32xb64_in1k-320px.py'
model = dict(backbone=dict(small_kernel_merged=True))
Collections:
- Name: RepLKNet
Metadata:
Training Data: ImageNet-1k
Architecture:
- Large-Kernel Convolution
- VGG-style Neural Network
Paper:
URL: https://arxiv.org/abs/2203.06717
Title: 'Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs'
README: configs/replknet/README.md
Code:
URL: https://github.com/open-mmlab/mmpretrain/blob/v1.0.0rc3/mmcls/models/backbones/replknet.py
Version: v1.0.0rc3
Models:
- Name: replknet-31B_3rdparty_in1k
In Collection: RepLKNet
Config: configs/replknet/replknet-31B_32xb64_in1k.py
Metadata:
FLOPs: 15636547584
Parameters: 79864168
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 83.48
Top 5 Accuracy: 96.57
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_3rdparty_in1k_20221118-fd08e268.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1azQUiCxK9feYVkkrPqwVPBtNsTzDrX7S&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
- Name: replknet-31B_3rdparty_in1k-384px
In Collection: RepLKNet
Config: configs/replknet/replknet-31B_32xb64_in1k-384px.py
Metadata:
FLOPs: 45952303104
Parameters: 79864168
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 84.84
Top 5 Accuracy: 97.34
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_3rdparty_in1k-384px_20221118-03a170ce.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1vo-P3XB6mRLUeDzmgv90dOu73uCeLfZN&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
- Name: replknet-31B_in21k-pre_3rdparty_in1k
In Collection: RepLKNet
Config: configs/replknet/replknet-31B_32xb64_in1k.py
Metadata:
Training Data:
- ImageNet-21k
- ImageNet-1k
FLOPs: 15636547584
Parameters: 79864168
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 85.20
Top 5 Accuracy: 97.56
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_in21k-pre_3rdparty_in1k_20221118-54ed5c46.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1DslZ2voXZQR1QoFY9KnbsHAeF84hzS0s&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
- Name: replknet-31B_in21k-pre_3rdparty_in1k-384px
In Collection: RepLKNet
Config: configs/replknet/replknet-31B_32xb64_in1k-384px.py
Metadata:
Training Data:
- ImageNet-21k
- ImageNet-1k
FLOPs: 45952303104
Parameters: 79864168
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 85.99
Top 5 Accuracy: 97.75
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31B_in21k-pre_3rdparty_in1k-384px_20221118-76c92b24.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1Sc46BWdXXm2fVP-K_hKKU_W8vAB-0duX&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
- Name: replknet-31L_in21k-pre_3rdparty_in1k-384px
In Collection: RepLKNet
Config: configs/replknet/replknet-31L_32xb64_in1k-384px.py
Metadata:
Training Data:
- ImageNet-21k
- ImageNet-1k
FLOPs: 97240006656
Parameters: 172671016
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 86.63
Top 5 Accuracy: 98.00
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-31L_in21k-pre_3rdparty_in1k-384px_20221118-dc3fc07c.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1JYXoNHuRvC33QV1pmpzMTKEni1hpWfBl&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
- Name: replknet-XL_meg73m-pre_3rdparty_in1k-320px
In Collection: RepLKNet
Config: configs/replknet/replknet-XL_32xb64_in1k-320px.py
Metadata:
Training Data:
- MegData-73M
- ImageNet-1k
FLOPs: 129570201600
Parameters: 335435752
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 87.57
Top 5 Accuracy: 98.39
Weights: https://download.openmmlab.com/mmclassification/v0/replknet/replknet-XL_meg73m-pre_3rdparty_in1k-320px_20221118-88259b1d.pth
Converted From:
Weights: https://drive.google.com/u/0/uc?id=1tPC60El34GntXByIRHb-z-Apm4Y5LX1T&export=download
Code: https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/replknet.py
_base_ = [
'../_base_/models/replknet-31B_in1k.py',
'../_base_/datasets/imagenet_bs16_pil_bicubic_384.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
# schedule settings
param_scheduler = dict(
type='CosineAnnealingLR', T_max=300, by_epoch=True, begin=0, end=300)
train_cfg = dict(by_epoch=True, max_epochs=300)
_base_ = [
'../_base_/models/replknet-31B_in1k.py',
'../_base_/datasets/imagenet_bs32_pil_bicubic.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
# schedule settings
param_scheduler = dict(
type='CosineAnnealingLR', T_max=300, by_epoch=True, begin=0, end=300)
train_cfg = dict(by_epoch=True, max_epochs=300)
_base_ = [
'../_base_/models/replknet-31L_in1k.py',
'../_base_/datasets/imagenet_bs16_pil_bicubic_384.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
# schedule settings
param_scheduler = dict(
type='CosineAnnealingLR', T_max=300, by_epoch=True, begin=0, end=300)
train_cfg = dict(by_epoch=True, max_epochs=300)
_base_ = [
'../_base_/models/replknet-XL_in1k.py',
'../_base_/datasets/imagenet_bs8_pil_bicubic_320.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
# schedule settings
param_scheduler = dict(
type='CosineAnnealingLR', T_max=300, by_epoch=True, begin=0, end=300)
train_cfg = dict(by_epoch=True, max_epochs=300)
# RepMLP
> [RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition](https://arxiv.org/abs/2105.01883)
<!-- [ALGORITHM] -->
## Abstract
We propose RepMLP, a multi-layer-perceptron-style neural network building block for image recognition, which is composed of a series of fully-connected (FC) layers. Compared to convolutional layers, FC layers are more efficient, better at modeling the long-range dependencies and positional patterns, but worse at capturing the local structures, hence usually less favored for image recognition. We propose a structural re-parameterization technique that adds local prior into an FC to make it powerful for image recognition. Specifically, we construct convolutional layers inside a RepMLP during training and merge them into the FC for inference. On CIFAR, a simple pure-MLP model shows performance very close to CNN. By inserting RepMLP in traditional CNN, we improve ResNets by 1.8% accuracy on ImageNet, 2.9% for face recognition, and 2.3% mIoU on Cityscapes with lower FLOPs. Our intriguing findings highlight that combining the global representational capacity and positional perception of FC with the local prior of convolution can improve the performance of neural network with faster speed on both the tasks with translation invariance (e.g., semantic segmentation) and those with aligned images and positional patterns (e.g., face recognition).
<div align=center>
<img src="https://user-images.githubusercontent.com/18586273/155455288-a17a5c48-11af-4b74-995a-cf7183f0e2d2.png" width="80%"/>
</div>
## How to use it?
<!-- [TABS-BEGIN] -->
**Predict image**
```python
from mmpretrain import inference_model, get_model
model = get_model('repmlp-base_3rdparty_8xb64_in1k', pretrained=True)
model.backbone.switch_to_deploy()
predict = inference_model(model, 'demo/bird.JPEG')
print(predict['pred_class'])
print(predict['pred_score'])
```
**Use the model**
```python
import torch
from mmpretrain import get_model
model = get_model('repmlp-base_3rdparty_8xb64_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))
```
**Test Command**
Prepare your dataset according to the [docs](https://mmpretrain.readthedocs.io/en/latest/user_guides/dataset_prepare.html#prepare-dataset).
Test:
```shell
python tools/test.py configs/repmlp/repmlp-base_8xb64_in1k.py https://download.openmmlab.com/mmclassification/v0/repmlp/repmlp-base_3rdparty_8xb64_in1k_20220330-1cb1f11b.pth
```
**Reparameterization**
The checkpoints provided are all `training-time` models. Use the reparameterize tool to switch them to more efficient `inference-time` architecture, which not only has fewer parameters but also less calculations.
```bash
python tools/convert_models/reparameterize_model.py ${CFG_PATH} ${SRC_CKPT_PATH} ${TARGET_CKPT_PATH}
```
`${CFG_PATH}` is the config file, `${SRC_CKPT_PATH}` is the source chenpoint file, `${TARGET_CKPT_PATH}` is the target deploy weight file path.
To use reparameterized weights, the config file must switch to the deploy config files.
```bash
python tools/test.py ${deploy_cfg} ${deploy_checkpoint} --metrics accuracy
```
You can also use `backbone.switch_to_deploy()` to switch to the deploy mode in Python code. For example:
```python
from mmpretrain.models import RepMLPNet
backbone = RepMLPNet(arch='B', img_size=224, reparam_conv_kernels=(1, 3))
backbone.switch_to_deploy()
```
<!-- [TABS-END] -->
## Models and results
### Image Classification on ImageNet-1k
| Model | Pretrain | Params (M) | Flops (G) | Top-1 (%) | Top-5 (%) | Config | Download |
| :---------------------------------------- | :----------: | :--------: | :-------: | :-------: | :-------: | :---------------------------------------: | :-------------------------------------------------------------------: |
| `repmlp-base_3rdparty_8xb64_in1k`\* | From scratch | 68.24 | 6.71 | 80.41 | 95.14 | [config](repmlp-base_8xb64_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repmlp/repmlp-base_3rdparty_8xb64_in1k_20220330-1cb1f11b.pth) |
| `repmlp-base_3rdparty_8xb64_in1k-256px`\* | From scratch | 96.45 | 9.69 | 81.11 | 95.50 | [config](repmlp-base_8xb64_in1k-256px.py) | [model](https://download.openmmlab.com/mmclassification/v0/repmlp/repmlp-base_3rdparty_8xb64_in1k-256px_20220330-7c5a91ce.pth) |
*Models with * are converted from the [official repo](https://github.com/DingXiaoH/RepMLP/blob/072d8516beba83d75dfe6ebb12f625abad4b53d5/repmlpnet.py#L278). The config files of these models are only for inference. We haven't reproduce the training results.*
## Citation
```bibtex
@article{ding2021repmlp,
title={Repmlp: Re-parameterizing convolutions into fully-connected layers for image recognition},
author={Ding, Xiaohan and Xia, Chunlong and Zhang, Xiangyu and Chu, Xiaojie and Han, Jungong and Ding, Guiguang},
journal={arXiv preprint arXiv:2105.01883},
year={2021}
}
```
Collections:
- Name: RepMLP
Metadata:
Training Data: ImageNet-1k
Architecture:
- Multi-layer Perceptron
- Re-parameterization Convolution
Paper:
URL: https://arxiv.org/abs/2105.01883
Title: 'RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition'
README: configs/repmlp/README.md
Code:
URL: https://github.com/open-mmlab/mmpretrain/blob/v0.21.0/mmcls/models/backbones/repmlp.py
Version: v0.21.0
Models:
- Name: repmlp-base_3rdparty_8xb64_in1k
In Collection: RepMLP
Config: configs/repmlp/repmlp-base_8xb64_in1k.py
Metadata:
FLOPs: 6710000000 # 6.71 G
Parameters: 68240000 # 68.24 M
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 80.41
Top 5 Accuracy: 95.14
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/repmlp/repmlp-base_3rdparty_8xb64_in1k_20220330-1cb1f11b.pth
Converted From:
Weights: https://github.com/DingXiaoH/RepMLP
Code: https://github.com/DingXiaoH/RepMLP/blob/072d8516beba83d75dfe6ebb12f625abad4b53d5/repmlpnet.py#L274
- Name: repmlp-base_3rdparty_8xb64_in1k-256px
In Collection: RepMLP
Config: configs/repmlp/repmlp-base_8xb64_in1k-256px.py
Metadata:
FLOPs: 9690000000 # 9.69 G
Parameters: 96450000 # 96.45M
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 81.11
Top 5 Accuracy: 95.50
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/repmlp/repmlp-base_3rdparty_8xb64_in1k-256px_20220330-7c5a91ce.pth
Converted From:
Weights: https://github.com/DingXiaoH/RepMLP
Code: https://github.com/DingXiaoH/RepMLP/blob/072d8516beba83d75dfe6ebb12f625abad4b53d5/repmlpnet.py#L278
_base_ = [
'../_base_/models/repmlp-base_224.py',
'../_base_/datasets/imagenet_bs64_pil_resize.py',
'../_base_/schedules/imagenet_bs4096_AdamW.py',
'../_base_/default_runtime.py'
]
# model settings
model = dict(backbone=dict(img_size=256))
# dataset settings
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='RandomResizedCrop', scale=256),
dict(type='RandomFlip', prob=0.5, direction='horizontal'),
dict(type='PackInputs'),
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='ResizeEdge', scale=292, edge='short', backend='pillow'),
dict(type='CenterCrop', crop_size=256),
dict(type='PackInputs'),
]
train_dataloader = dict(dataset=dict(pipeline=train_pipeline))
val_dataloader = dict(dataset=dict(pipeline=test_pipeline))
test_dataloader = dict(dataset=dict(pipeline=test_pipeline))
# schedule settings
optim_wrapper = dict(clip_grad=dict(max_norm=1.0))
# NOTE: `auto_scale_lr` is for automatically scaling LR
# based on the actual training batch size.
# base_batch_size = (8 GPUs) x (64 samples per GPU)
auto_scale_lr = dict(base_batch_size=512)
_base_ = [
'../_base_/models/repmlp-base_224.py',
'../_base_/datasets/imagenet_bs64_pil_resize.py',
'../_base_/schedules/imagenet_bs1024_adamw_swin.py',
'../_base_/default_runtime.py'
]
# dataset settings
test_pipeline = [
dict(type='LoadImageFromFile'),
# resizing to (256, 256) here, different from resizing shorter edge to 256
dict(type='Resize', scale=(256, 256), backend='pillow'),
dict(type='CenterCrop', crop_size=224),
dict(type='PackInputs'),
]
val_dataloader = dict(dataset=dict(pipeline=test_pipeline))
test_dataloader = dict(dataset=dict(pipeline=test_pipeline))
# schedule settings
optim_wrapper = dict(clip_grad=dict(max_norm=5.0))
# NOTE: `auto_scale_lr` is for automatically scaling LR
# based on the actual training batch size.
# base_batch_size = (8 GPUs) x (64 samples per GPU)
auto_scale_lr = dict(base_batch_size=512)
_base_ = ['./repmlp-base_8xb64_in1k.py']
model = dict(backbone=dict(deploy=True))
_base_ = ['./repmlp-base_8xb64_in1k-256px.py']
model = dict(backbone=dict(deploy=True))
# RepVGG
> [RepVGG: Making VGG-style ConvNets Great Again](https://arxiv.org/abs/2101.03697)
<!-- [ALGORITHM] -->
## Introduction
RepVGG is a VGG-style convolutional architecture. It has the following advantages:
1. The model has a VGG-like plain (a.k.a. feed-forward) topology 1 without any branches. I.e., every layer takes the output of its only preceding layer as input and feeds the output into its only following layer.
2. The model’s body uses only 3 × 3 conv and ReLU.
3. The concrete architecture (including the specific depth and layer widths) is instantiated with no automatic search, manual refinement, compound scaling, nor other heavy designs.
<div align=center>
<img src="https://user-images.githubusercontent.com/26739999/142573223-f7f14d32-ea08-43a1-81ad-5a6a83ee0122.png" width="60%"/>
</div>
## Abstract
<details>
<summary>Show the paper's abstract</summary>
<br>
We present a simple but powerful architecture of convolutional neural network, which has a VGG-like inference-time body composed of nothing but a stack of 3x3 convolution and ReLU, while the training-time model has a multi-branch topology. Such decoupling of the training-time and inference-time architecture is realized by a structural re-parameterization technique so that the model is named RepVGG. On ImageNet, RepVGG reaches over 80% top-1 accuracy, which is the first time for a plain model, to the best of our knowledge. On NVIDIA 1080Ti GPU, RepVGG models run 83% faster than ResNet-50 or 101% faster than ResNet-101 with higher accuracy and show favorable accuracy-speed trade-off compared to the state-of-the-art models like EfficientNet and RegNet.
</br>
</details>
## How to use it?
<!-- [TABS-BEGIN] -->
**Predict image**
```python
from mmpretrain import inference_model, get_model
model = get_model('repvgg-A0_8xb32_in1k', pretrained=True)
model.backbone.switch_to_deploy()
predict = inference_model(model, 'demo/bird.JPEG')
print(predict['pred_class'])
print(predict['pred_score'])
```
**Use the model**
```python
import torch
from mmpretrain import get_model
model = get_model('repvgg-A0_8xb32_in1k', pretrained=True)
inputs = torch.rand(1, 3, 224, 224)
out = model(inputs)
print(type(out))
# To extract features.
feats = model.extract_feat(inputs)
print(type(feats))
```
**Train/Test Command**
Prepare your dataset according to the [docs](https://mmpretrain.readthedocs.io/en/latest/user_guides/dataset_prepare.html#prepare-dataset).
Train:
```shell
python tools/train.py configs/repvgg/repvgg-A0_8xb32_in1k.py
```
Test:
```shell
python tools/test.py configs/repvgg/repvgg-A0_8xb32_in1k.py https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A0_8xb32_in1k_20221213-60ae8e23.pth
```
Test with reparameterized model:
```shell
python tools/test.py configs/repvgg/repvgg-A0_8xb32_in1k.py repvgg_A0_deploy.pth --cfg-options model.backbone.deploy=True
```
**Reparameterization**
The checkpoints provided are all `training-time` models. Use the reparameterize tool to switch them to more efficient `inference-time` architecture, which not only has fewer parameters but also less calculations.
```bash
python tools/convert_models/reparameterize_model.py ${CFG_PATH} ${SRC_CKPT_PATH} ${TARGET_CKPT_PATH}
```
`${CFG_PATH}` is the config file, `${SRC_CKPT_PATH}` is the source chenpoint file, `${TARGET_CKPT_PATH}` is the target deploy weight file path.
To use reparameterized weights, the config file must switch to the deploy config files.
```bash
python tools/test.py ${deploy_cfg} ${deploy_checkpoint} --metrics accuracy
```
You can also use `backbone.switch_to_deploy()` to switch to the deploy mode in Python code. For example:
```python
from mmpretrain.models import RepVGG
backbone = RepVGG(arch='A0')
backbone.switch_to_deploy()
```
<!-- [TABS-END] -->
## Models and results
### Image Classification on ImageNet-1k
| Model | Pretrain | Params (M) | Flops (G) | Top-1 (%) | Top-5 (%) | Config | Download |
| :---------------------------- | :----------: | :--------: | :-------: | :-------: | :-------: | :---------------------------------: | :-------------------------------------------------------------------------------------: |
| `repvgg-A0_8xb32_in1k` | From scratch | 8.31 | 1.36 | 72.37 | 90.56 | [config](repvgg-A0_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A0_8xb32_in1k_20221213-60ae8e23.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A0_8xb32_in1k_20221213-60ae8e23.log) |
| `repvgg-A1_8xb32_in1k` | From scratch | 12.79 | 2.36 | 74.23 | 91.80 | [config](repvgg-A1_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A1_8xb32_in1k_20221213-f81bf3df.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A1_8xb32_in1k_20221213-f81bf3df.log) |
| `repvgg-A2_8xb32_in1k` | From scratch | 25.50 | 5.12 | 76.49 | 93.09 | [config](repvgg-A2_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A2_8xb32_in1k_20221213-a8767caf.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A2_8xb32_in1k_20221213-a8767caf.log) |
| `repvgg-B0_8xb32_in1k` | From scratch | 3.42 | 15.82 | 75.27 | 92.21 | [config](repvgg-B0_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B0_8xb32_in1k_20221213-5091ecc7.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B0_8xb32_in1k_20221213-5091ecc7.log) |
| `repvgg-B1_8xb32_in1k` | From scratch | 51.83 | 11.81 | 78.19 | 94.04 | [config](repvgg-B1_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1_8xb32_in1k_20221213-d17c45e7.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1_8xb32_in1k_20221213-d17c45e7.log) |
| `repvgg-B1g2_8xb32_in1k` | From scratch | 41.36 | 8.81 | 77.87 | 93.99 | [config](repvgg-B1g2_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g2_8xb32_in1k_20221213-ae6428fd.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g2_8xb32_in1k_20221213-ae6428fd.log) |
| `repvgg-B1g4_8xb32_in1k` | From scratch | 36.13 | 7.30 | 77.81 | 93.77 | [config](repvgg-B1g4_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g4_8xb32_in1k_20221213-a7a4aaea.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g4_8xb32_in1k_20221213-a7a4aaea.log) |
| `repvgg-B2_8xb32_in1k` | From scratch | 80.32 | 18.37 | 78.58 | 94.23 | [config](repvgg-B2_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2_8xb32_in1k_20221213-d8b420ef.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2_8xb32_in1k_20221213-d8b420ef.log) |
| `repvgg-B2g4_8xb32_in1k` | From scratch | 55.78 | 11.33 | 79.44 | 94.72 | [config](repvgg-B2g4_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2g4_8xb32_in1k_20221213-0c1990eb.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2g4_8xb32_in1k_20221213-0c1990eb.log) |
| `repvgg-B3_8xb32_in1k` | From scratch | 110.96 | 26.21 | 80.58 | 95.33 | [config](repvgg-B3_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3_8xb32_in1k_20221213-927a329a.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3_8xb32_in1k_20221213-927a329a.log) |
| `repvgg-B3g4_8xb32_in1k` | From scratch | 75.63 | 16.06 | 80.26 | 95.15 | [config](repvgg-B3g4_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3g4_8xb32_in1k_20221213-e01cb280.pth) \| [log](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3g4_8xb32_in1k_20221213-e01cb280.log) |
| `repvgg-D2se_3rdparty_in1k`\* | From scratch | 120.39 | 32.84 | 81.81 | 95.94 | [config](repvgg-D2se_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-D2se_3rdparty_4xb64-autoaug-lbs-mixup-coslr-200e_in1k_20210909-cf3139b7.pth) |
*Models with * are converted from the [official repo](https://github.com/DingXiaoH/RepVGG/blob/9f272318abfc47a2b702cd0e916fca8d25d683e7/repvgg.py#L250). The config files of these models are only for inference. We haven't reproduce the training results.*
## Citation
```bibtex
@inproceedings{ding2021repvgg,
title={Repvgg: Making vgg-style convnets great again},
author={Ding, Xiaohan and Zhang, Xiangyu and Ma, Ningning and Han, Jungong and Ding, Guiguang and Sun, Jian},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={13733--13742},
year={2021}
}
```
Collections:
- Name: RepVGG
Metadata:
Training Data: ImageNet-1k
Architecture:
- re-parameterization Convolution
- VGG-style Neural Network
Paper:
URL: https://arxiv.org/abs/2101.03697
Title: 'RepVGG: Making VGG-style ConvNets Great Again'
README: configs/repvgg/README.md
Code:
URL: https://github.com/open-mmlab/mmpretrain/blob/v0.16.0/mmcls/models/backbones/repvgg.py#L257
Version: v0.16.0
Models:
- Name: repvgg-A0_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-A0_8xb32_in1k.py
Metadata:
FLOPs: 1360233728
Parameters: 8309384
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 72.37
Top 5 Accuracy: 90.56
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A0_8xb32_in1k_20221213-60ae8e23.pth
- Name: repvgg-A1_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-A1_8xb32_in1k.py
Metadata:
FLOPs: 2362750208
Parameters: 12789864
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 74.23
Top 5 Accuracy: 91.80
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A1_8xb32_in1k_20221213-f81bf3df.pth
- Name: repvgg-A2_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-A2_8xb32_in1k.py
Metadata:
FLOPs: 5115612544
Parameters: 25499944
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 76.49
Top 5 Accuracy: 93.09
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A2_8xb32_in1k_20221213-a8767caf.pth
- Name: repvgg-B0_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B0_8xb32_in1k.py
Metadata:
FLOPs: 15820000000
Parameters: 3420000
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 75.27
Top 5 Accuracy: 92.21
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B0_8xb32_in1k_20221213-5091ecc7.pth
- Name: repvgg-B1_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B1_8xb32_in1k.py
Metadata:
FLOPs: 11813537792
Parameters: 51829480
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 78.19
Top 5 Accuracy: 94.04
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1_8xb32_in1k_20221213-d17c45e7.pth
- Name: repvgg-B1g2_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B1g2_8xb32_in1k.py
Metadata:
FLOPs: 8807794688
Parameters: 41360104
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 77.87
Top 5 Accuracy: 93.99
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g2_8xb32_in1k_20221213-ae6428fd.pth
- Name: repvgg-B1g4_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B1g4_8xb32_in1k.py
Metadata:
FLOPs: 7304923136
Parameters: 36125416
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 77.81
Top 5 Accuracy: 93.77
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B1g4_8xb32_in1k_20221213-a7a4aaea.pth
- Name: repvgg-B2_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B2_8xb32_in1k.py
Metadata:
FLOPs: 18374175232
Parameters: 80315112
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 78.58
Top 5 Accuracy: 94.23
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2_8xb32_in1k_20221213-d8b420ef.pth
- Name: repvgg-B2g4_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B2g4_8xb32_in1k.py
Metadata:
FLOPs: 11329464832
Parameters: 55777512
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 79.44
Top 5 Accuracy: 94.72
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B2g4_8xb32_in1k_20221213-0c1990eb.pth
- Name: repvgg-B3_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B3_8xb32_in1k.py
Metadata:
FLOPs: 26206448128
Parameters: 110960872
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 80.58
Top 5 Accuracy: 95.33
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3_8xb32_in1k_20221213-927a329a.pth
- Name: repvgg-B3g4_8xb32_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-B3g4_8xb32_in1k.py
Metadata:
FLOPs: 16062065152
Parameters: 75626728
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 80.26
Top 5 Accuracy: 95.15
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-B3g4_8xb32_in1k_20221213-e01cb280.pth
- Name: repvgg-D2se_3rdparty_in1k
In Collection: RepVGG
Config: configs/repvgg/repvgg-D2se_8xb32_in1k.py
Metadata:
FLOPs: 32838581760
Parameters: 120387572
Results:
- Dataset: ImageNet-1k
Task: Image Classification
Metrics:
Top 1 Accuracy: 81.81
Top 5 Accuracy: 95.94
Weights: https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-D2se_3rdparty_4xb64-autoaug-lbs-mixup-coslr-200e_in1k_20210909-cf3139b7.pth
Converted From:
Weights: https://drive.google.com/drive/folders/1Avome4KvNp0Lqh2QwhXO6L5URQjzCjUq
Code: https://github.com/DingXiaoH/RepVGG/blob/9f272318abfc47a2b702cd0e916fca8d25d683e7/repvgg.py#L250
_base_ = [
'../_base_/models/repvgg-A0_in1k.py',
'../_base_/datasets/imagenet_bs32_pil_resize.py',
'../_base_/schedules/imagenet_bs256_coslr.py',
'../_base_/default_runtime.py'
]
val_dataloader = dict(batch_size=256)
test_dataloader = dict(batch_size=256)
# schedule settings
optim_wrapper = dict(
paramwise_cfg=dict(
bias_decay_mult=0.0,
custom_keys={
'branch_3x3.norm': dict(decay_mult=0.0),
'branch_1x1.norm': dict(decay_mult=0.0),
'branch_norm.bias': dict(decay_mult=0.0),
}))
# schedule settings
param_scheduler = dict(
type='CosineAnnealingLR',
T_max=120,
by_epoch=True,
begin=0,
end=120,
convert_to_iter_based=True)
train_cfg = dict(by_epoch=True, max_epochs=120)
default_hooks = dict(
checkpoint=dict(type='CheckpointHook', interval=1, max_keep_ckpts=3))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment