[paper note] Densely Connected Convolutional Networks

本文深入探讨了DenseNet网络结构的设计理念与实现细节,包括其如何通过密集连接提高参数效率和减少特征冗余,以及在多种数据集上的实验表现。此外,还介绍了如瓶颈层、压缩因子等关键组件的作用。

Intuition

  • Current trend of CNN architecture: create short paths from early layers to later layers.
    • ResNet
    • Highway network: The first network with more than 100 layers, bypassing paths
    • Stochastic depth: Improves the training of deep residual networks by dropping layers randomly during training, which manages to train a 1202-layer ResNet
    • FractalNets
  • Wide filter is helpful.
  • Connect all layers with each other.
  • Combine features by concatenating them (ResNet combines by summation).
  • DenseNet layers are very narrow (12 feature-maps per layer), resulting in less parameters

Model

dense block

  • Dense connectivity: concatenate all the preceding layers:
    xl=Hl([x0,x1,,xl1])
  • Composite function:
    H_l is defined as BN + ReLU + 3x3 Conv
  • Pooling and dense block
    • See figure above
    • Transition layer between dense blocks, consist of BN + 1x1 Conv + 2x2 AveragePooing
  • Growth rate k:
    • The number of output feature-maps.
    • The l-th layer will have k x (l-1) + k_0 input feature-maps (k_0:input image channels)
  • Bottleneck layers
    • Introduce 1x1 Conv before 3x3 Conv to reduce number of feature-maps will improve computation efficiency.
    • H_l is changed to BN + ReLU + 1x1 Conv + BN + ReLU + 3x3 Conv
    • 1x1 Conv reduce the input to 4k feature-maps in the experiment.
  • Compression
    • Reduce feature-maps number in transition layer by factor θ

Experiment

  • Datasets
    • CIFAR-10/100, 32x32
      • Zero-padded with 4 pixels on each side
      • Randomly cropped to again produce 32×32 images
      • Half of the images are then horizontally mirrored
    • SVHN (Street View House Numbers), 32x32
    • ImageNet, 224x224, 1.2m for training, 50000 for validation, 1000 classes
  • Settings: weight decay 10e-4, Nesterov momentum of 0.9 w\o dampening, learning rate 0.1 with decay scheme, dropout when no data augmentation
  • Accuracy result:
    • 3.46% on CIFAR-10, L=190, k=40
    • 17.18% on CIFAR-100, L=190, k=40
    • 1.59% on SVHN, L=100, k=24
  • Capacity: the performance continues improving when L, k increase, showing the DenseNet is less prone to overfitting (???)
  • Parameter efficiency.
### Densely Connected Convolutional Networks (DenseNet) 的架构与实现 #### 架构解释 DenseNet 是一种密集连接的卷积神经网络,其核心思想在于通过层间的密集连接来增强特征重用并减少冗余参数。在传统卷积网络中,每一层仅与其相邻的一层相连;而在 DenseNet 中,每层不仅接受前一层的输入,还接受之前所有层的输出作为额外输入[^3]。 这种设计使得 DenseNet 能够显著降低模型复杂度和计算成本,因为各层无需重复学习相同的特征图。具体而言,DenseNet 将每一层的输出视为全局状态的一部分,并允许后续层访问这些状态。因此,最终分类器能够利用整个网络中的所有特征图进行预测[^5]。 #### 实现方法 以下是 DenseNet 的基本构建单元及其 Python 实现: 1. **Dense Block**: 密集块由多个卷积层组成,其中每一层都将自身的输出与其他层的输出拼接在一起。 2. **Transition Layer**: 这些层用于控制特征图的数量以及缩小图像尺寸,通常包括批量归一化(Batch Normalization)、ReLU 和平均池化操作。 下面是基于 PyTorch 的简单实现示例: ```python import torch.nn as nn import torch class Bottleneck(nn.Module): """Bottleneck 层""" def __init__(self, in_channels, growth_rate): super(Bottleneck, self).__init__() inter_channel = 4 * growth_rate self.bn1 = nn.BatchNorm2d(in_channels) self.conv1 = nn.Conv2d(in_channels, inter_channel, kernel_size=1, bias=False) self.relu = nn.ReLU(inplace=True) self.bn2 = nn.BatchNorm2d(inter_channel) self.conv2 = nn.Conv2d(inter_channel, growth_rate, kernel_size=3, padding=1, bias=False) def forward(self, x): out = self.conv1(self.relu(self.bn1(x))) out = self.conv2(self.relu(self.bn2(out))) out = torch.cat((x, out), dim=1) # 特征图拼接 return out class Transition(nn.Module): """过渡层""" def __init__(self, in_channels, out_channels): super(Transition, self).__init__() self.bn = nn.BatchNorm2d(in_channels) self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=1, bias=False) self.avg_pool = nn.AvgPool2d(kernel_size=2, stride=2) def forward(self, x): out = self.conv(self.bn(x)) out = self.avg_pool(out) return out class DenseNet(nn.Module): """DenseNet 主体结构""" def __init__(self, num_init_features, growth_rate, block_config, num_classes=1000): super(DenseNet, self).__init__() self.features = nn.Sequential( nn.Conv2d(3, num_init_features, kernel_size=7, stride=2, padding=3, bias=False), nn.BatchNorm2d(num_init_features), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=3, stride=2, padding=1) ) num_features = num_init_features for i, num_layers in enumerate(block_config): dense_block = self._make_dense_block(growth_rate, num_layers, num_features) self.features.add_module(f"denseblock{i + 1}", dense_block) num_features += num_layers * growth_rate if i != len(block_config) - 1: trans_layer = Transition(num_features, num_features // 2) self.features.add_module(f"transition{i + 1}", trans_layer) num_features //= 2 self.classifier = nn.Linear(num_features, num_classes) def _make_dense_block(self, growth_rate, n_layers, input_channels): layers = [] for _ in range(n_layers): layers.append(Bottleneck(input_channels, growth_rate)) input_channels += growth_rate return nn.Sequential(*layers) def forward(self, x): features = self.features(x) out = nn.functional.adaptive_avg_pool2d(features, (1, 1)) out = torch.flatten(out, 1) out = self.classifier(out) return out ``` 上述代码定义了一个基础版本的 DenseNet 模型,其中包括瓶颈层(`Bottleneck`)和过渡层(`Transition`)。通过调整 `growth_rate` 和 `block_config` 参数,可以灵活配置不同的 DenseNet 变种。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值