第7章畳み込みニューラルネットワーク
7.5.1. Maximum Pooling and Average Pooling7.5.1 最大プーリングと平均プーリング
Like convolutional layers, pooling operators consist of a fixed-shape window that is slid over all regions in the input according to its stride, computing a single output for each location traversed by the fixed-shape window (sometimes known as the pooling window). However, unlike the cross-correlation computation of the inputs and kernels in the convolutional layer, the pooling layer contains no parameters (there is no kernel). Instead, pooling operators are deterministic, typically calculating either the maximum or the average value of the elements in the pooling window. These operations are called maximum pooling (max-pooling for short) and average pooling, respectively.
英語のヒント
畳み込み層と同じく、プーリングの演算子は形の決まった窓からなり、その窓はストライドに従って入力のすべての領域の上をすべらされ、形の決まった窓(プーリングの窓と呼ばれることもある)が通る位置ごとに一つの出力を計算する。しかし、畳み込み層での入力とカーネルの相互相関の計算と違って、プーリング層はパラメータを含まない(カーネルがない)。その代わり、プーリングの演算子は決定論的で、ふつうはプーリングの窓の中の要素の最大値か平均値のどちらかを計算する。これらの演算は、それぞれ最大プーリング(略してマックスプーリング)と平均プーリングと呼ばれる。
Average pooling is essentially as old as CNNs. The idea is akin to downsampling an image. Rather than just taking the value of every second (or third) pixel for the lower resolution image, we can average over adjacent pixels to obtain an image with better signal-to-noise ratio since we are combining the information from multiple adjacent pixels. Max-pooling was introduced in Riesenhuber and Poggio (1999) in the context of cognitive neuroscience to describe how information aggregation might be aggregated hierarchically for the purpose of object recognition; there already was an earlier version in speech recognition (Yamaguchi et al., 1990). In almost all cases, max-pooling, as it is also referred to, is preferable to average pooling.
英語のヒント
平均プーリングは、本質的にはCNNと同じくらい古い。その考えは、画像をダウンサンプリングすることに近い。解像度の低い画像のために一つおき(あるいは二つおき)の画素の値をとるだけでなく、隣り合う画素の平均をとれば、隣り合う複数の画素の情報を組み合わせているので、信号対雑音比のよりよい画像が得られる。最大プーリングは、Riesenhuber and Poggio (1999)で、物体認識のために情報の集約が階層的にどう集約されうるかを説明するのに、認知神経科学の文脈で導入された。音声認識では、それより前の版がすでにあった(Yamaguchi et al., 1990)。ほとんどすべての場合に、最大プーリング(マックスプーリングとも呼ばれる)のほうが平均プーリングより望ましい。
In both cases, as with the cross-correlation operator, we can think of the pooling window as starting from the upper-left of the input tensor and sliding across it from left to right and top to bottom. At each location that the pooling window hits, it computes the maximum or average value of the input subtensor in the window, depending on whether max or average pooling is employed.
英語のヒント
どちらの場合も、相互相関の演算子と同じく、プーリングの窓は入力テンソルの左上から始まり、その上を左から右へ、上から下へとすべっていくと考えられる。プーリングの窓が当たる各位置で、最大プーリングと平均プーリングのどちらを使うかに応じて、窓の中の入力の部分テンソルの最大値または平均値を計算する。
Fig. 7.5.1図7.5.1
Max-pooling with a pooling window shape of . The shaded portions are the first output element as well as the input tensor elements used for the output computation: .
英語のヒント
プーリングの窓の形状がの最大プーリング。網かけの部分は、最初の出力要素と、その出力の計算に使われる入力テンソルの要素である。。
The output tensor in Fig. 7.5.1 has a height of 2 and a width of 2. The four elements are derived from the maximum value in each pooling window:
英語のヒント
図7.5.1の出力テンソルは高さ2、幅2である。四つの要素は、各プーリングの窓の最大値から導かれる。
(7.5.1)
More generally, we can define a pooling layer by aggregating over a region of said size. Returning to the problem of edge detection, we use the output of the convolutional layer as input for max-pooling. Denote by
X the input of the convolutional layer input and Y the pooling layer output. Regardless of whether or not the values of X[i, j], X[i, j + 1], X[i+1, j] and X[i+1, j + 1] are different, the pooling layer always outputs Y[i, j] = 1. That is to say, using the max-pooling layer, we can still detect if the pattern recognized by the convolutional layer moves no more than one element in height or width.英語のヒント
もっと一般に、その大きさの領域にわたって集約することで、のプーリング層を定義できる。縁の検出の問題に戻って、畳み込み層の出力をの最大プーリングへの入力として使う。畳み込み層の入力を
X、プーリング層の出力をYで表す。X[i, j]、X[i, j + 1]、X[i+1, j]、X[i+1, j + 1]の値が異なるかどうかにかかわらず、プーリング層はいつもY[i, j] = 1を出力する。つまり、の最大プーリング層を使えば、畳み込み層が認識したパターンが高さや幅の方向に1要素までしか動かないなら、それをやはり検出できる。In the code below, we implement the forward propagation of the pooling layer in the
pool2d function. This function is similar to the corr2d function in Section 7.2. However, no kernel is needed, computing the output as either the maximum or the average of each region in the input.英語のヒント
下のコードでは、プーリング層の順伝播を
pool2d関数に実装する。この関数は、7.2節のcorr2d関数に似ている。しかし、カーネルは必要なく、出力を、入力の各領域の最大値か平均値のどちらかとして計算する。def pool2d(X, pool_size, mode='max'):
p_h, p_w = pool_size
Y = torch.zeros((X.shape[0] - p_h + 1, X.shape[1] - p_w + 1))
for i in range(Y.shape[0]):
for j in range(Y.shape[1]):
if mode == 'max':
Y[i, j] = X[i: i + p_h, j: j + p_w].max()
elif mode == 'avg':
Y[i, j] = X[i: i + p_h, j: j + p_w].mean()
return YWe can construct the input tensor
X in Fig. 7.5.1 to validate the output of the two-dimensional max-pooling layer.英語のヒント
図7.5.1の入力テンソル
Xを組み立てて、2次元の最大プーリング層の出力を確かめられる。X = torch.tensor([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])
pool2d(X, (2, 2))tensor([[4., 5.],
[7., 8.]])Also, we can experiment with the average pooling layer.
英語のヒント
平均プーリング層で実験することもできる。
pool2d(X, (2, 2), 'avg')tensor([[2., 3.],
[5., 6.]])