Skip to content

Commit

Permalink
[Feature] Support DenseNet. (open-mmlab#750)
Browse files Browse the repository at this point in the history
* init add densenet implementation

* Add config and converted models

* update meta

* add test for memory efficient

* Add docs

* add doc for jit

* Update checkpoint path

* Update readthedocs

Co-authored-by: mzr1996 <[email protected]>
  • Loading branch information
yingfhu and mzr1996 authored Apr 28, 2022
1 parent df6edd7 commit 59292b3
Show file tree
Hide file tree
Showing 17 changed files with 637 additions and 1 deletion.
11 changes: 11 additions & 0 deletions configs/_base_/models/densenet/densenet121.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Model settings
model = dict(
type='ImageClassifier',
backbone=dict(type='DenseNet', arch='121'),
neck=dict(type='GlobalAveragePooling'),
head=dict(
type='LinearClsHead',
num_classes=1000,
in_channels=1024,
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
))
11 changes: 11 additions & 0 deletions configs/_base_/models/densenet/densenet161.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Model settings
model = dict(
type='ImageClassifier',
backbone=dict(type='DenseNet', arch='161'),
neck=dict(type='GlobalAveragePooling'),
head=dict(
type='LinearClsHead',
num_classes=1000,
in_channels=2208,
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
))
11 changes: 11 additions & 0 deletions configs/_base_/models/densenet/densenet169.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Model settings
model = dict(
type='ImageClassifier',
backbone=dict(type='DenseNet', arch='169'),
neck=dict(type='GlobalAveragePooling'),
head=dict(
type='LinearClsHead',
num_classes=1000,
in_channels=1664,
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
))
11 changes: 11 additions & 0 deletions configs/_base_/models/densenet/densenet201.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Model settings
model = dict(
type='ImageClassifier',
backbone=dict(type='DenseNet', arch='201'),
neck=dict(type='GlobalAveragePooling'),
head=dict(
type='LinearClsHead',
num_classes=1000,
in_channels=1920,
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
))
41 changes: 41 additions & 0 deletions configs/densenet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# DenseNet

> [Densely Connected Convolutional Networks](https://arxiv.org/abs/1608.06993)
<!-- [ALGORITHM] -->
## Abstract

Recent work has shown that convolutional networks can be substantially deeper, more accurate, and efficient to train if they contain shorter connections between layers close to the input and those close to the output. In this paper, we embrace this observation and introduce the Dense Convolutional Network (DenseNet), which connects each layer to every other layer in a feed-forward fashion. Whereas traditional convolutional networks with L layers have L connections - one between each layer and its subsequent layer - our network has L(L+1)/2 direct connections. For each layer, the feature-maps of all preceding layers are used as inputs, and its own feature-maps are used as inputs into all subsequent layers. DenseNets have several compelling advantages: they alleviate the vanishing-gradient problem, strengthen feature propagation, encourage feature reuse, and substantially reduce the number of parameters. We evaluate our proposed architecture on four highly competitive object recognition benchmark tasks (CIFAR-10, CIFAR-100, SVHN, and ImageNet). DenseNets obtain significant improvements over the state-of-the-art on most of them, whilst requiring less computation to achieve high performance.

<div align=center>
<img src="https://user-images.githubusercontent.com/42952108/162675098-9a670883-b13a-4a5a-a9c9-06c39c616a0a.png" width="100%"/>
</div>

## Results and models

### ImageNet-1k

| Model | Params(M) | Flops(G) | Top-1 (%) | Top-5 (%) | Config | Download |
|:---------------:|:---------:|:--------:|:---------:|:---------:|:------:|:--------:|
| DenseNet121\* | 7.98 | 2.88 | 74.96 | 92.21 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet121_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet121_4xb256_in1k_20220426-07450f99.pth) |
| DenseNet169\* | 14.15 | 3.42 | 76.08 | 93.11 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet169_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet169_4xb256_in1k_20220426-a2889902.pth) |
| DenseNet201\* | 20.01 | 4.37 | 77.32 | 93.64 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet201_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet201_4xb256_in1k_20220426-05cae4ef.pth) |
| DenseNet161\* | 28.68 | 7.82 | 77.61 | 93.83 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet161_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet161_4xb256_in1k_20220426-ee6a80a9.pth) |

*Models with \* are converted from [pytorch](https://pytorch.org/vision/stable/models.html), guided by [original repo](https://github.com/liuzhuang13/DenseNet). The config files of these models are only for inference. We don't ensure these config files' training accuracy and welcome you to contribute your reproduction results.*


## Citation

```bibtex
@misc{https://doi.org/10.48550/arxiv.1608.06993,
doi = {10.48550/ARXIV.1608.06993},
url = {https://arxiv.org/abs/1608.06993},
author = {Huang, Gao and Liu, Zhuang and van der Maaten, Laurens and Weinberger, Kilian Q.},
keywords = {Computer Vision and Pattern Recognition (cs.CV), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Densely Connected Convolutional Networks},
publisher = {arXiv},
year = {2016},
copyright = {arXiv.org perpetual, non-exclusive license}
}
```
10 changes: 10 additions & 0 deletions configs/densenet/densenet121_4xb256_in1k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_base_ = [
'../_base_/models/densenet/densenet121.py',
'../_base_/datasets/imagenet_bs64.py',
'../_base_/schedules/imagenet_bs256.py',
'../_base_/default_runtime.py',
]

data = dict(samples_per_gpu=256)

runner = dict(type='EpochBasedRunner', max_epochs=90)
10 changes: 10 additions & 0 deletions configs/densenet/densenet161_4xb256_in1k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_base_ = [
'../_base_/models/densenet/densenet161.py',
'../_base_/datasets/imagenet_bs64.py',
'../_base_/schedules/imagenet_bs256.py',
'../_base_/default_runtime.py',
]

data = dict(samples_per_gpu=256)

runner = dict(type='EpochBasedRunner', max_epochs=90)
10 changes: 10 additions & 0 deletions configs/densenet/densenet169_4xb256_in1k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_base_ = [
'../_base_/models/densenet/densenet169.py',
'../_base_/datasets/imagenet_bs64.py',
'../_base_/schedules/imagenet_bs256.py',
'../_base_/default_runtime.py',
]

data = dict(samples_per_gpu=256)

runner = dict(type='EpochBasedRunner', max_epochs=90)
10 changes: 10 additions & 0 deletions configs/densenet/densenet201_4xb256_in1k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_base_ = [
'../_base_/models/densenet/densenet201.py',
'../_base_/datasets/imagenet_bs64.py',
'../_base_/schedules/imagenet_bs256.py',
'../_base_/default_runtime.py',
]

data = dict(samples_per_gpu=256)

runner = dict(type='EpochBasedRunner', max_epochs=90)
76 changes: 76 additions & 0 deletions configs/densenet/metafile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Collections:
- Name: DenseNet
Metadata:
Training Data: ImageNet-1k
Architecture:
- DenseBlock
Paper:
URL: https://arxiv.org/abs/1608.06993
Title: Densely Connected Convolutional Networks
README: configs/densenet/README.md

Models:
- Name: densenet121_4xb256_in1k
Metadata:
FLOPs: 2881695488
Parameters: 7978856
In Collections: DenseNet
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 74.96
Top 5 Accuracy: 92.21
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/densenet/densenet121_4xb256_in1k_20220426-07450f99.pth
Config: configs/densenet/densenet121_4xb256_in1k.py
Converted From:
Weights: https://download.pytorch.org/models/densenet121-a639ec97.pth
Code: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
- Name: densenet169_4xb256_in1k
Metadata:
FLOPs: 3416860160
Parameters: 14149480
In Collections: DenseNet
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 76.08
Top 5 Accuracy: 93.11
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/densenet/densenet169_4xb256_in1k_20220426-a2889902.pth
Config: configs/densenet/densenet169_4xb256_in1k.py
Converted From:
Weights: https://download.pytorch.org/models/densenet169-b2777c0a.pth
Code: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
- Name: densenet201_4xb256_in1k
Metadata:
FLOPs: 4365236736
Parameters: 20013928
In Collections: DenseNet
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 77.32
Top 5 Accuracy: 93.64
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/densenet/densenet201_4xb256_in1k_20220426-05cae4ef.pth
Config: configs/densenet/densenet201_4xb256_in1k.py
Converted From:
Weights: https://download.pytorch.org/models/densenet201-c1103571.pth
Code: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
- Name: densenet161_4xb256_in1k
Metadata:
FLOPs: 7816363968
Parameters: 28681000
In Collections: DenseNet
Results:
- Dataset: ImageNet-1k
Metrics:
Top 1 Accuracy: 77.61
Top 5 Accuracy: 93.83
Task: Image Classification
Weights: https://download.openmmlab.com/mmclassification/v0/densenet/densenet161_4xb256_in1k_20220426-ee6a80a9.pth
Config: configs/densenet/densenet161_4xb256_in1k.py
Converted From:
Weights: https://download.pytorch.org/models/densenet161-8d451a50.pth
Code: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
1 change: 1 addition & 0 deletions docs/en/api/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Backbones
Conformer
ConvMixer
ConvNeXt
DenseNet
DistilledVisionTransformer
EfficientNet
HRNet
Expand Down
4 changes: 4 additions & 0 deletions docs/en/model_zoo.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ The ResNet family models below are trained by standard data augmentations, i.e.,
| CSPDarkNet50\* | 27.64 | 5.04 | 80.05 | 95.07 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/cspnet/cspdarknet50_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/cspnet/cspdarknet50_3rdparty_8xb32_in1k_20220329-bd275287.pth) |
| CSPResNet50\* | 21.62 | 3.48 | 79.55 | 94.68 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/cspnet/cspresnet50_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/cspnet/cspresnet50_3rdparty_8xb32_in1k_20220329-dd6dddfb.pth) |
| CSPResNeXt50\* | 20.57 | 3.11 | 79.96 | 94.96 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/cspnet/cspresnext50_8xb32_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/cspnet/cspresnext50_3rdparty_8xb32_in1k_20220329-2cc84d21.pth) |
| DenseNet121\* | 7.98 | 2.88 | 74.96 | 92.21 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet121_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet121_4xb256_in1k_20220426-07450f99.pth) |
| DenseNet169\* | 14.15 | 3.42 | 76.08 | 93.11 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet169_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet169_4xb256_in1k_20220426-a2889902.pth) |
| DenseNet201\* | 20.01 | 4.37 | 77.32 | 93.64 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet201_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet201_4xb256_in1k_20220426-05cae4ef.pth) |
| DenseNet161\* | 28.68 | 7.82 | 77.61 | 93.83 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/densenet/densenet161_4xb256_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/densenet/densenet161_4xb256_in1k_20220426-ee6a80a9.pth) |
| VAN-T\* | 4.11 | 0.88 | 75.41 | 93.02 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/van/van-tiny_8xb128_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/van/van-tiny_8xb128_in1k_20220427-8ac0feec.pth) |
| VAN-S\* | 13.86 | 2.52 | 81.01 | 95.63 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/van/van-small_8xb128_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/van/van-small_8xb128_in1k_20220427-bd6a9edd.pth) |
| VAN-B\* | 26.58 | 5.03 | 82.80 | 96.21 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/van/van-base_8xb128_in1k.py) | [model](https://download.openmmlab.com/mmclassification/v0/van/van-base_8xb128_in1k_20220427-5275471d.pth) |
Expand Down
1 change: 1 addition & 0 deletions docs/zh_CN/api/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Backbones
Conformer
ConvMixer
ConvNeXt
DenseNet
DistilledVisionTransformer
EfficientNet
HRNet
Expand Down
3 changes: 2 additions & 1 deletion mmcls/models/backbones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .convnext import ConvNeXt
from .cspnet import CSPDarkNet, CSPNet, CSPResNet, CSPResNeXt
from .deit import DistilledVisionTransformer
from .densenet import DenseNet
from .efficientnet import EfficientNet
from .hrnet import HRNet
from .lenet import LeNet5
Expand Down Expand Up @@ -41,5 +42,5 @@
'Conformer', 'MlpMixer', 'DistilledVisionTransformer', 'PCPVT', 'SVT',
'EfficientNet', 'ConvNeXt', 'HRNet', 'ResNetV1c', 'ConvMixer',
'CSPDarkNet', 'CSPResNet', 'CSPResNeXt', 'CSPNet', 'RepMLPNet',
'PoolFormer', 'VAN'
'PoolFormer', 'DenseNet', 'VAN'
]
Loading

0 comments on commit 59292b3

Please sign in to comment.