Skip to content

Commit

Permalink
version: 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ffiirree committed Dec 8, 2022
1 parent 851c21d commit 0526677
Show file tree
Hide file tree
Showing 31 changed files with 351 additions and 257 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Computer Vision Models

## Classification
## Backbones

- [x] `AlexNet` - [ImageNet Classification with Deep Convolutional Neural Networks](https://papers.nips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf), 2012
- [x] `VGGNets` - [Very Deep Convolutional Networks for Large-Scale Image Recognition](https://arxiv.org/abs/1409.1556), 2014
Expand All @@ -25,14 +25,12 @@
- [x] `ShuffleNet V2` - [ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design](https://arxiv.org/abs/1807.11164), 2018
- [x] `MnasNet` - [MnasNet: Platform-Aware Neural Architecture Search for Mobile](https://arxiv.org/abs/1807.11626), 2018
- [x] `GhostNet` - [GhostNet: More Features from Cheap Operations](https://arxiv.org/abs/1911.11907), CVPR, 2019
- [ ] `ResNeSt` - [ResNeSt: Split-Attention Networks](https://arxiv.org/abs/2004.08955), 2020
- [ ] `HRNet` - [Deep High-Resolution Representation Learning for Visual Recognition](https://arxiv.org/abs/1908.07919), 2019
- [ ] `CSPNet` - [CSPNet: A New Backbone that can Enhance Learning Capability of CNN](https://arxiv.org/abs/1911.11929), 2019
- [x] `EfficientNet` - [EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks](https://arxiv.org/abs/1905.11946), 2019
- [x] `EfficientNetV2` - [EfficientNetV2: Smaller Models and Faster Training](https://arxiv.org/abs/2104.00298), 2021
- [x] `RegNet` - [Designing Network Design Spaces](https://arxiv.org/abs/2003.13678), 2020
- [ ] `GPU-EfficientNets` - [Neural Architecture Design for GPU-Efficient Networks](https://arxiv.org/abs/2006.14090), 2020
- [ ] `HaloNets` - [Scaling Local Self-Attention for Parameter Efficient Visual Backbones](https://arxiv.org/abs/2103.12731), 2021
- [ ] `LambdaNetworks` - [LambdaNetworks: Modeling Long-Range Interactions Without Attention](https://arxiv.org/abs/2102.08602), 2021
- [ ] `RepVGG` - [RepVGG: Making VGG-style ConvNets Great Again](https://arxiv.org/abs/2101.03697), 2021
- [ ] `HardCoRe-NAS` - [HardCoRe-NAS: Hard Constrained diffeRentiable Neural Architecture Search](https://arxiv.org/abs/2102.11646), 2021
Expand All @@ -47,9 +45,11 @@
- [x] `Squeeze-and-Excitation` - [Squeeze-and-Excitation Networks](https://arxiv.org/abs/1709.01507), CVPR, 2017
- [x] `Gather-Excite` - [Gather-Excite: Exploiting Feature Context in Convolutional Neural Networks](https://arxiv.org/abs/1810.12348), NeurIPS, 2018
- [x] `CBAM` - [CBAM: Convolutional Block Attention Module](https://arxiv.org/abs/1807.06521), ECCV, 2018
- [x] `SKNets` - [Selective Kernel Networks](https://arxiv.org/abs/1903.06586), CVPR, 2019
- [x] `SelectiveKernel` - [Selective Kernel Networks](https://arxiv.org/abs/1903.06586), CVPR, 2019
- [x] `ECA` - [ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks](https://arxiv.org/abs/1910.03151), CVPR, 2019
- [x] `GlobalContextBlick` - [GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond](https://arxiv.org/abs/1904.11492), 2019
- [x] `GlobalContext` - [GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond](https://arxiv.org/abs/1904.11492), 2019
- [ ] `ResNeSt` - [ResNeSt: Split-Attention Networks](https://arxiv.org/abs/2004.08955), 2020
- [ ] `HaloNets` - [Scaling Local Self-Attention for Parameter Efficient Visual Backbones](https://arxiv.org/abs/2103.12731), 2021

### Transformer

Expand Down
8 changes: 4 additions & 4 deletions cvm/models/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
num_classes: int = 1000,
width_coefficient: float = 1,
depth_coefficient: float = 1,
se_ratio: float = 0.25,
rd_ratio: float = 0.25,
dropout_rate: float = 0.2,
drop_path_rate: float = 0.2,
dilations: List[int] = None,
Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(
self.n[i],
self.s[i],
self.k[i],
se_ratio,
rd_ratio,
dilations[len(self.features) + (stages[i] - 1)]
)

Expand All @@ -117,7 +117,7 @@ def make_layers(
n: int,
stride: int,
kernel_size: int = 3,
se_ratio: float = None,
rd_ratio: float = None,
dilation: int = 1
):
layers = []
Expand All @@ -130,7 +130,7 @@ def make_layers(
self.block(
inp, oup, t,
kernel_size=kernel_size, stride=stride if dilation == 1 else 1,
dilation=max(dilation // stride, 1), survival_prob=survival_prob, se_ratio=se_ratio
dilation=max(dilation // stride, 1), survival_prob=survival_prob, rd_ratio=rd_ratio
)
)

Expand Down
16 changes: 8 additions & 8 deletions cvm/models/efficientnetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
filters: List[int] = [24, 24, 48, 64, 128, 160, 256, 1280],
layers: List[int] = [2, 4, 5, 6, 9, 15],
strides: List[int] = [1, 2, 2, 2, 1, 2],
se_ratio: List[float] = [0, 0, 0, 0.25, 0.25, 0.25],
rd_ratio: List[float] = [0, 0, 0, 0.25, 0.25, 0.25],
thumbnail: bool = False,
**kwargs: Any
):
Expand All @@ -76,7 +76,7 @@ def __init__(
features.append(
self.make_layers(
block_type[i], filters[i], expand_ratio[i], filters[i+1],
n=layers[i], stride=strides[i], se_ratio=se_ratio[i]
n=layers[i], stride=strides[i], rd_ratio=rd_ratio[i]
)
)

Expand All @@ -98,7 +98,7 @@ def make_layers(
oup: int,
n: int,
stride: int,
se_ratio: float = None
rd_ratio: float = None
):
layers = []
for i in range(n):
Expand All @@ -111,7 +111,7 @@ def make_layers(
block(
inp, oup, t,
stride=stride,
survival_prob=survival_prob, se_ratio=se_ratio
survival_prob=survival_prob, rd_ratio=rd_ratio
)
)

Expand All @@ -136,7 +136,7 @@ def efficientnet_v2_s(pretrained: bool = False, pth: str = None, **kwargs: Any):
filters=[24, 24, 48, 64, 128, 160, 256, 1280],
layers=[2, 4, 5, 6, 9, 15],
strides=[1, 2, 2, 2, 1, 2],
se_ratio=[0, 0, 0, 0.25, 0.25, 0.25],
rd_ratio=[0, 0, 0, 0.25, 0.25, 0.25],
**kwargs
)

Expand All @@ -155,7 +155,7 @@ def efficientnet_v2_m(pretrained: bool = False, pth: str = None, **kwargs: Any):
filters=[24, 24, 48, 80, 160, 176, 304, 512, 1280],
layers=[3, 5, 5, 7, 14, 18, 5],
strides=[1, 2, 2, 2, 1, 2, 1],
se_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
rd_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
**kwargs
)

Expand All @@ -174,7 +174,7 @@ def efficientnet_v2_l(pretrained: bool = False, pth: str = None, **kwargs: Any):
filters=[32, 32, 64, 96, 192, 224, 384, 640, 1280],
layers=[4, 7, 7, 10, 19, 25, 7],
strides=[1, 2, 2, 2, 1, 2, 1],
se_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
rd_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
**kwargs
)

Expand All @@ -193,7 +193,7 @@ def efficientnet_v2_xl(pretrained: bool = False, pth: str = None, **kwargs: Any)
filters=[32, 32, 64, 96, 192, 256, 512, 640, 1280],
layers=[4, 8, 8, 16, 24, 32, 8],
strides=[1, 2, 2, 2, 1, 2, 1],
se_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
rd_ratio=[0, 0, 0, 0.25, 0.25, 0.25, 0.25],
**kwargs
)

Expand Down
12 changes: 6 additions & 6 deletions cvm/models/ghostnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __init__(
dw_kernel_size: int = 3,
stride: int = 1,
act_layer: nn.Module = nn.ReLU,
se_ratio: float = 0.
rd_ratio: float = 0.
):
super(GhostBottleneck, self).__init__()
has_se = se_ratio is not None and se_ratio > 0.
has_attn = rd_ratio is not None and rd_ratio > 0.
self.stride = stride

# Point-wise expansion
Expand All @@ -73,8 +73,8 @@ def __init__(
self.bn_dw = nn.BatchNorm2d(mid_chs)

# Squeeze-and-excitation
if has_se:
self.se = blocks.SEBlock(mid_chs, ratio=se_ratio)
if has_attn:
self.se = blocks.SEBlock(mid_chs, rd_ratio=rd_ratio)
else:
self.se = None

Expand Down Expand Up @@ -137,10 +137,10 @@ def __init__(

for cfg in cfgs:
stage = blocks.Stage()
for k, t, c, se_ratio, s in cfg:
for k, t, c, rd_ratio, s in cfg:
oup = make_divisible(c * multiplier, 4)
stage.append(GhostBottleneck(
inp, make_divisible(t * multiplier, 4), oup, k, s, se_ratio=se_ratio
inp, make_divisible(t * multiplier, 4), oup, k, s, rd_ratio=rd_ratio
))
inp = oup

Expand Down
6 changes: 3 additions & 3 deletions cvm/models/mnasnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def make_layers(
n: int,
stride: int,
kernel_size: int = 3,
se_ratio: float = None
rd_ratio: float = None
):
layers = [blocks.InvertedResidualBlock(inp, oup, t, kernel_size, stride, se_ratio=se_ratio)]
layers = [blocks.InvertedResidualBlock(inp, oup, t, kernel_size, stride, rd_ratio=rd_ratio)]

for _ in range(n - 1):
layers.append(blocks.InvertedResidualBlock(oup, oup, t, kernel_size, se_ratio=se_ratio))
layers.append(blocks.InvertedResidualBlock(oup, oup, t, kernel_size, rd_ratio=rd_ratio))

return blocks.Stage(layers)

Expand Down
34 changes: 17 additions & 17 deletions cvm/models/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ def __init__(
blocks.Conv2dBlock(in_channels, 16, 3, stride=FRONT_S, activation_fn=hs)
)),
('stage1', blocks.Stage(
blocks.InvertedResidualBlock(16, 16, 1, kernel_size=3, stride=strides[0], se_ratio=0.5, se_ind=True)
blocks.InvertedResidualBlock(16, 16, 1, kernel_size=3, stride=strides[0], rd_ratio=0.5, se_ind=True)
)),
('stage2', blocks.Stage(
blocks.InvertedResidualBlock(16, 24, 72/16, kernel_size=3, stride=strides[1], dilation=dilations[0]),
blocks.InvertedResidualBlock(24, 24, 88/24, kernel_size=3, dilation=dilations[1])
)),
('stage3', blocks.Stage(
blocks.InvertedResidualBlock(24, 40, 4, kernel_size=5, stride=strides[2], dilation=dilations[1], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 40, 6, kernel_size=5, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 40, 6, kernel_size=5, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 48, 3, kernel_size=5, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(48, 48, 3, kernel_size=5, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs)
blocks.InvertedResidualBlock(24, 40, 4, kernel_size=5, stride=strides[2], dilation=dilations[1], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 40, 6, kernel_size=5, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 40, 6, kernel_size=5, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(40, 48, 3, kernel_size=5, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(48, 48, 3, kernel_size=5, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs)
)),
('stage4', blocks.Stage(
blocks.InvertedResidualBlock(48, 96, 6, kernel_size=5, stride=strides[3], dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(96, 96, 6, kernel_size=5, dilation=dilations[3], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(96, 96, 6, kernel_size=5, dilation=dilations[3], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(48, 96, 6, kernel_size=5, stride=strides[3], dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(96, 96, 6, kernel_size=5, dilation=dilations[3], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(96, 96, 6, kernel_size=5, dilation=dilations[3], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.Conv2d1x1Block(96, 576, activation_fn=hs)
))
]))
Expand Down Expand Up @@ -125,22 +125,22 @@ def __init__(
blocks.InvertedResidualBlock(24, 24, t=3, kernel_size=3, dilation=dilations[0])
)),
('stage2', blocks.Stage(
blocks.InvertedResidualBlock(24, 40, t=3, kernel_size=5, stride=strides[1], dilation=dilations[0], se_ratio=0.25, se_ind=True),
blocks.InvertedResidualBlock(40, 40, t=3, kernel_size=5, dilation=dilations[1], se_ratio=0.25, se_ind=True),
blocks.InvertedResidualBlock(40, 40, t=3, kernel_size=5, dilation=dilations[1], se_ratio=0.25, se_ind=True)
blocks.InvertedResidualBlock(24, 40, t=3, kernel_size=5, stride=strides[1], dilation=dilations[0], rd_ratio=0.25, se_ind=True),
blocks.InvertedResidualBlock(40, 40, t=3, kernel_size=5, dilation=dilations[1], rd_ratio=0.25, se_ind=True),
blocks.InvertedResidualBlock(40, 40, t=3, kernel_size=5, dilation=dilations[1], rd_ratio=0.25, se_ind=True)
)),
('stage3', blocks.Stage(
blocks.InvertedResidualBlock(40, 80, t=6, kernel_size=3, stride=strides[2], dilation=dilations[1], activation_fn=hs),
blocks.InvertedResidualBlock(80, 80, t=200/80, kernel_size=3, dilation=dilations[2], activation_fn=hs),
blocks.InvertedResidualBlock(80, 80, t=184/80, kernel_size=3, dilation=dilations[2], activation_fn=hs),
blocks.InvertedResidualBlock(80, 80, t=184/80, kernel_size=3, dilation=dilations[2], activation_fn=hs),
blocks.InvertedResidualBlock(80, 112, t=6, kernel_size=3, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(112, 112, t=6, kernel_size=3, dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs)
blocks.InvertedResidualBlock(80, 112, t=6, kernel_size=3, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(112, 112, t=6, kernel_size=3, dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs)
)),
('stage4', blocks.Stage(
blocks.InvertedResidualBlock(112, 160, t=6, kernel_size=5, stride=strides[3], dilation=dilations[2], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(160, 160, t=6, kernel_size=5, dilation=dilations[3], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(160, 160, t=6, kernel_size=5, dilation=dilations[3], se_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(112, 160, t=6, kernel_size=5, stride=strides[3], dilation=dilations[2], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(160, 160, t=6, kernel_size=5, dilation=dilations[3], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.InvertedResidualBlock(160, 160, t=6, kernel_size=5, dilation=dilations[3], rd_ratio=0.25, se_ind=True, activation_fn=hs),
blocks.Conv2d1x1Block(160, 960, activation_fn=hs)
))
]))
Expand Down
6 changes: 2 additions & 4 deletions cvm/models/ops/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from .norm_act import normalizer, activation, normalizer_fn, activation_fn, norm_activation
from .factory import normalizer, activation, normalizer_fn, activation_fn, norm_activation, attention, attention_fn
from .stage import Stage
from .affine import Affine
from .vanilla_conv2d import Conv2d1x1, Conv2d3x3, Conv2d1x1BN, Conv2d3x3BN, Conv2d1x1Block, Conv2dBlock
from .bottleneck import ResBasicBlockV1, BottleneckV1, ResBasicBlockV2, BottleneckV2
from .channel_combine import Combine
from .channel_split import ChannelChunk, ChannelSplit
from .channel_shuffle import ChannelShuffle
from .channel import Combine, ChannelChunk, ChannelSplit, ChannelShuffle
from .depthwise_separable_conv2d import DepthwiseConv2d, PointwiseConv2d, DepthwiseConv2dBN, PointwiseConv2dBN, DepthwiseBlock, PointwiseBlock
from .inverted_residual_block import InvertedResidualBlock, FusedInvertedResidualBlock
from .squeeze_excite import se, SEBlock
Expand Down
2 changes: 1 addition & 1 deletion cvm/models/ops/blocks/aspp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import torch.nn as nn
import torch.nn.functional as F
from .vanilla_conv2d import Conv2d1x1, Conv2d1x1Block, Conv2dBlock
from .channel_combine import Combine
from .channel import Combine
from typing import List


Expand Down
Loading

0 comments on commit 0526677

Please sign in to comment.