Skip to content

Commit

Permalink
rm channel output
Browse files Browse the repository at this point in the history
  • Loading branch information
astonzhang committed Aug 27, 2018
1 parent ca961e7 commit 0980d9d
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions chapter_convolutional-neural-networks/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ K = nd.array([[[0, 1], [2, 3]], [[1, 2], [3, 4]]])
corr2d_multi_in(X, K)
```

```{.json .output n=2}
[
{
"data": {
"text/plain": "\n[[ 56. 72.]\n [104. 120.]]\n<NDArray 2x2 @cpu(0)>"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
]
```

## 多输出通道

当输入通道有多个时,由于我们对各个通道的结果做了累加,所以不论输入通道数是多少,输出通道数总是为1。设卷积核输入通道数和输出通道数分别为$c_i$和$c_o$,高和宽分别为$k_h$和$k_w$。如果我们希望得到含多个通道的输出,我们可以为每个输出通道分别创建形状为$c_i\times k_h\times k_w$的核数组。将它们在在输出通道维上连结,卷积核的形状即$c_o\times c_i\times k_h\times k_w$。在互相关运算时,每个输出通道上的结果由卷积核在相同输出通道上的核数组与整个输入数组计算而来。
Expand All @@ -70,38 +57,12 @@ K = nd.stack(K, K + 1, K + 2)
K.shape
```

```{.json .output n=4}
[
{
"data": {
"text/plain": "(3, 2, 2, 2)"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
]
```

下面我们对输入数组`X`与核数组`K`做互相关运算。此时的输出含有3个通道。其中第一个通道的结果与之前输入数组`X`与多输入通道单输出通道核的计算结果一致。

```{.python .input n=5}
corr2d_multi_in_out(X, K)
```

```{.json .output n=5}
[
{
"data": {
"text/plain": "\n[[[ 56. 72.]\n [104. 120.]]\n\n [[ 76. 100.]\n [148. 172.]]\n\n [[ 96. 128.]\n [192. 224.]]]\n<NDArray 3x2x2 @cpu(0)>"
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
]
```

## $1\times 1$卷积层

最后我们讨论卷积窗口形状为$1\times 1$($k_h=k_w=1$)的多通道卷积层。我们通常称之为$1\times 1$卷积层,并将其中的卷积运算称为$1\times 1$卷积。因为使用了最小窗口,$1\times 1$卷积失去了卷积层可以识别高宽维上相邻元素构成的模式的功能。实际上,$1\times 1$卷积的主要计算发生在通道维上。图5.5展示了一个输入通道数为3、输出通道数为2的$1\times 1$卷积核。值得注意的是,输入和输出的高宽相同。输出中的每个元素来自输入中在高和宽上相同位置的元素在不同通道之间的按权重累加。假设我们将通道维当做是特征维,将高和宽维度上的元素当成数据样本。那么$1\times 1$卷积层的作用与全连接层等价。
Expand Down Expand Up @@ -132,19 +93,6 @@ Y2 = corr2d_multi_in_out(X, K)
(Y1 - Y2).norm().asscalar() < 1e-6
```

```{.json .output n=7}
[
{
"data": {
"text/plain": "True"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
]
```

在之后的模型里我们将会看到$1\times 1$卷积层被当做保持高宽维形状不变的全连接层使用。这可以通过调整网络层之间的通道数来控制模型复杂度。


Expand Down

0 comments on commit 0980d9d

Please sign in to comment.