第7章畳み込みニューラルネットワーク
7.2.2. Convolutional Layers7.2.2 畳み込み層
A convolutional layer cross-correlates the input and kernel and adds a scalar bias to produce an output. The two parameters of a convolutional layer are the kernel and the scalar bias. When training models based on convolutional layers, we typically initialize the kernels randomly, just as we would with a fully connected layer.
英語のヒント
畳み込み層は、入力とカーネルの相互相関をとり、スカラーのバイアスを加えて出力を生み出す。畳み込み層の二つのパラメータは、カーネルとスカラーのバイアスである。畳み込み層にもとづくモデルを訓練するときには、全結合層の場合とちょうど同じように、ふつうカーネルを無作為に初期化する。
We are now ready to implement a two-dimensional convolutional layer based on the
corr2d function defined above. In the __init__ constructor method, we declare weight and bias as the two model parameters. The forward propagation method calls the corr2d function and adds the bias.英語のヒント
これで、上で定義した
corr2d関数にもとづいて、2次元の畳み込み層を実装する準備ができた。コンストラクタである__init__メソッドでは、weightとbiasを二つのモデルパラメータとして宣言する。順伝播のメソッドは、corr2d関数を呼び出してバイアスを加える。class Conv2D(nn.Module):
def __init__(self, kernel_size):
super().__init__()
self.weight = nn.Parameter(torch.rand(kernel_size))
self.bias = nn.Parameter(torch.zeros(1))
def forward(self, x):
return corr2d(x, self.weight) + self.biasIn convolution or an convolution kernel, the height and width of the convolution kernel are and , respectively. We also refer to a convolutional layer with an convolution kernel simply as an convolutional layer.
英語のヒント
の畳み込み、つまりの畳み込みカーネルでは、畳み込みカーネルの高さと幅はそれぞれとである。の畳み込みカーネルをもつ畳み込み層のことを、単にの畳み込み層とも呼ぶ。