Dilated Convolution

[Paper]: Multi-scale Context Aggregation by Dilated Convolutions

[Caffe-Code]

1. Caffe 中的定义

Dilated Convolution 已经可在 Caffe 官方的卷积层参数中定义.

message ConvolutionParameter {
  // Factor used to dilate the kernel, (implicitly) zero-filling the resulting holes. 
  // (Kernel dilation is sometimes referred to by its use in the
  //  algorithme à trous from Holschneider et al. 1987.)
  repeated uint32 dilation = 18; // The dilation; defaults to 1
}
layer {
  name: "ct_conv1_1"
  type: "Convolution"
  bottom: "fc-final"
  top: "ct_conv1_1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 1
  }
  convolution_param {
    num_output: 42
    pad: 33
    kernel_size: 3
  }
}
layer {
  name: "ct_relu1_1"
  type: "ReLU"
  bottom: "ct_conv1_1"
  top: "ct_conv1_1"
}
layer {
  name: "ct_conv1_2"
  type: "Convolution"
  bottom: "ct_conv1_1"
  top: "ct_conv1_2"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 1
  }
  convolution_param {
    num_output: 42
    pad: 0
    kernel_size: 3
  }
}
layer {
  name: "ct_relu1_2"
  type: "ReLU"
  bottom: "ct_conv1_2"
  top: "ct_conv1_2"
}
layer {
  name: "ct_conv2_1"
  type: "Convolution"
  bottom: "ct_conv1_2"
  top: "ct_conv2_1"
  convolution_param {
    num_output: 84
    kernel_size: 3
    dilation: 2
  }
}
layer {
  name: "ct_relu2_1"
  type: "ReLU"
  bottom: "ct_conv2_1"
  top: "ct_conv2_1"
}
layer {
  name: "ct_conv3_1"
  type: "Convolution"
  bottom: "ct_conv2_1"
  top: "ct_conv3_1"
  convolution_param {
    num_output: 168
    kernel_size: 3
    dilation: 4
  }
}
layer {
  name: "ct_relu3_1"
  type: "ReLU"
  bottom: "ct_conv3_1"
  top: "ct_conv3_1"
}
layer {
  name: "ct_conv4_1"
  type: "Convolution"
  bottom: "ct_conv3_1"
  top: "ct_conv4_1"
  convolution_param {
    num_output: 336
    kernel_size: 3
    dilation: 8
  }
}
layer {
  name: "ct_relu4_1"
  type: "ReLU"
  bottom: "ct_conv4_1"
  top: "ct_conv4_1"
}
layer {
  name: "ct_conv5_1"
  type: "Convolution"
  bottom: "ct_conv4_1"
  top: "ct_conv5_1"
  convolution_param {
    num_output: 672
    kernel_size: 3
    dilation: 16
  }
}
layer {
  name: "ct_relu5_1"
  type: "ReLU"
  bottom: "ct_conv5_1"
  top: "ct_conv5_1"
}
layer {
  name: "ct_fc1"
  type: "Convolution"
  bottom: "ct_conv5_1"
  top: "ct_fc1"
  convolution_param {
    num_output: 672
    kernel_size: 3
  }
}
layer {
  name: "ct_fc1_relu"
  type: "ReLU"
  bottom: "ct_fc1"
  top: "ct_fc1"
}
layer {
  name: "ct_final"
  type: "Convolution"
  bottom: "ct_fc1"
  top: "ct_final"
  convolution_param {
    num_output: 21
    kernel_size: 1
  }
}

2. Paper - Multi-scale Context Aggregation by Dilated Convolutions

语义分割属于 dense prediction 问题, 不同于图像分类问题.

Dilated Convolutions 能够整合多尺度内容信息,且不损失分辨率,支持接受野的指数增长.

图像分类任务通过连续的 Pooling 和 Subsampling 层整合多尺度的内容信息,降低图像分别率,以得到全局预测输出.

Dense Prediction 需要结合多尺度内容推理(multi-scale contextual reasoning)与 full-resolution 输出.

处理 multi-scale reasoning 与 full-resolution dense prediction 冲突的方法:

  • 利用重复的 up-convolutions 操作,重构丢失的分辨率,保留downsampled 层的全局信息.
  • 利用图像不同 rescaled 的信息作为网络输入,并结合其输出. 不过无法确定哪个 rescaled 输入图像是最需要的.

Dilated Convolutions 不会降低图像分辨率,或分析 rescaled 图像,整合了多尺度的内容信息. 可以以任何分辨率加入到已有的网络结构中.

2.1 Dilated Convolution

定义离散函数: F:Z2R F : Z 2 → R <script type="math/tex" id="MathJax-Element-79">F: Z^2 \rightarrow R</script>, 假设 Ωr=[r,r]2Z2 Ω r = [ − r , r ] 2 ⋂ Z 2 <script type="math/tex" id="MathJax-Element-80">\Omega _r = [-r, r]^2 \bigcap Z^2</script>, k:ΩR k : Ω → R <script type="math/tex" id="MathJax-Element-81">k: \Omega \rightarrow R</script> 是大小为 (2r+1)2 ( 2 r + 1 ) 2 <script type="math/tex" id="MathJax-Element-82">(2r+1)^2</script> 的离散 filter. 则离散卷积操作 <script type="math/tex" id="MathJax-Element-83">*</script> 的定义为:

(Fk)(p)=s+t=p<script type="math/tex" id="MathJax-Element-84">(F*k)(\mathbf{p}) = \sum_{\mathbf{s} + \mathbf{t}= \mathbf{p}}</script> .

其一般化形式为:

(Flk)(p)=s+lt=p ( F ∗ l k ) ( p ) = ∑ s + l t = p <script type="math/tex" id="MathJax-Element-85">(F*_lk)(\mathbf{p}) = \sum_{\mathbf{s} + l\mathbf{t}= \mathbf{p}}</script>

其中 l l <script type="math/tex" id="MathJax-Element-86">l</script> 为 dilation 因子,l<script type="math/tex" id="MathJax-Element-87">*_l</script> 为 dilation convolution. 当 l=1 l = 1 <script type="math/tex" id="MathJax-Element-88">l=1</script> 时,即为普通的离散卷积操作 <script type="math/tex" id="MathJax-Element-89">*</script>.

基于 Dilation Convolution 的网络支持接受野的指数增长,不丢失分辨率信息.

F0,F1,...,Fn1:Z2R<script type="math/tex" id="MathJax-Element-90">F_0, F_1, ..., F_{n-1} : Z^2 \rightarrow R</script> 为离散函数, k0,k1,...,kn2:ΩR k 0 , k 1 , . . . , k n − 2 : Ω → R <script type="math/tex" id="MathJax-Element-91">k_0, k_1, ... ,k_{n-2} : \Omega \rightarrow R</script> 是离散的 3×3 3 × 3 <script type="math/tex" id="MathJax-Element-92">3×3</script> fliters, 采用指数增长 dilation 的 filters后,

Fi+1=Fi2iki, for i=0,1,...,n2 F i + 1 = F i ∗ 2 i k i ,   f o r   i = 0 , 1 , . . . , n − 2 <script type="math/tex" id="MathJax-Element-93">F_{i+1} = F_i *_{2^i} k_i, \space for \space i = 0, 1, ..., n-2</script>

定义 Fi+1 F i + 1 <script type="math/tex" id="MathJax-Element-94">F_{i+1}</script> 中的元素 p p <script type="math/tex" id="MathJax-Element-95">\mathbf{p}</script> 的接受野为: F0 F 0 <script type="math/tex" id="MathJax-Element-96">F_0</script> 中可以改变 Fi+1(p) F i + 1 ( p ) <script type="math/tex" id="MathJax-Element-97">F_{i+1}(\mathbf{p})</script> 值的元素集. Fi+1 F i + 1 <script type="math/tex" id="MathJax-Element-98">F_{i+1}</script> 中 p p <script type="math/tex" id="MathJax-Element-99">\mathbf{p}</script> 的接受野的大小即为这些元素集的数目.

显而易见, Fi+1 F i + 1 <script type="math/tex" id="MathJax-Element-100">F_{i+1}</script> 中各元素的接受野大小为 (2i+21)×(2i+21) ( 2 i + 2 − 1 ) × ( 2 i + 2 − 1 ) <script type="math/tex" id="MathJax-Element-101">(2^{i+2} - 1) × (2^{i+2} - 1)</script>. 接受野是指数增长大小的平方.

如图 Figure1.
这里写图片描述
Figure1:Dilated Convolution例示.

(a) 采用 1-dilated convolution 对 F0 F 0 <script type="math/tex" id="MathJax-Element-102">F_0</script> 操作得到的 F1 F 1 <script type="math/tex" id="MathJax-Element-103">F_1</script>, F1 F 1 <script type="math/tex" id="MathJax-Element-104">F_1</script> 中各元素的接受野为 3×3 3 × 3 <script type="math/tex" id="MathJax-Element-105">3×3</script>.

(b) 采用 2-dilated convolution 对 F1 F 1 <script type="math/tex" id="MathJax-Element-106">F_1</script> 操作得到的 F2 F 2 <script type="math/tex" id="MathJax-Element-107">F_2</script>, F2 F 2 <script type="math/tex" id="MathJax-Element-108">F_2</script> 中各元素的接受野为 7×7 7 × 7 <script type="math/tex" id="MathJax-Element-109">7×7</script>.

(c) 采用 4-dilated convolution 对 F2 F 2 <script type="math/tex" id="MathJax-Element-110">F_2</script> 操作得到的 F3 F 3 <script type="math/tex" id="MathJax-Element-111">F_3</script>, F3 F 3 <script type="math/tex" id="MathJax-Element-112">F_3</script> 中各元素的接受野为 15×15 15 × 15 <script type="math/tex" id="MathJax-Element-113">15×15</script>.

各层的参数数量是相同的. 随着参数的线性增加,接受野指数增长.

2.2 多尺度内容信息聚合(Multi-scale Context Aggreation)

context 模块通过整合多尺度内容信息来提高 dense prediction 的结果. 其输入是 C C <script type="math/tex" id="MathJax-Element-126">C</script> 个特征图(feature maps), 输出也是 C<script type="math/tex" id="MathJax-Element-127">C</script> 个特征图,输入输出的形式相同.
这里写图片描述

context 模块的基本形式中,各层具有 C C <script type="math/tex" id="MathJax-Element-128">C</script> 个 channels. 尽管特征图没有归一化,模块内也没有定义loss,但各层的表示是相同的,可以直接用于获得 dense per-class prediction. 直观上是可以增加特征图的准确度的.

基本的 context 模块有 7 层,各层采用具有不同的 dilation 因子的 3×3<script type="math/tex" id="MathJax-Element-129">3×3</script> 卷积. 各卷积操作后跟着一个逐元素截断(pointwise truncation)操作: max(,0) m a x ( ⋅ , 0 ) <script type="math/tex" id="MathJax-Element-130">max(\cdot, 0)</script>. 最终的输出是采用 1×1×C 1 × 1 × C <script type="math/tex" id="MathJax-Element-131">1×1×C</script> 的卷积操作得到的.

3. Reference

[1] - caffe::ConvolutionLayer

[2] - Multi-scale context aggregation by dilated convolutions

[3] - dilation8_pascal_voc_deploy.prototxt

[4] - 如何理解空洞卷积(dilated convolution)?

更多推荐