3.**Fully connected layers**: Finally, considering that the network would be of no use if it was only capable of detecting a set of features without having the capability of classifying them into a class label, fully connected layers are used at the end of CNNs to take the features that were detected by the previous layer (known as the feature map) and output the probability of that group of features belonging to a class label, which is used to make the final prediction.
2. Change the definition of the **transform** variable so that it includes, in addition to normalizing and converting the data into tensors, the following transformations:
6. We define our forward pass by obtaining and summing the embeddings for all input context words. This then passes through the fully connected layer with ReLU activation functions and finally into the classification layer, which predicts which word in the corpus corresponds to the summed embeddings of the context words the most:
让我们看一下`forward`方法的工作方式。 `z_dim`维度的输入噪声矢量经过完全连接的层以提供 12544 输出。 然后,我们将 12544 输出调整为`256 x 7 x 7`,其中 256 是通道数。 `256 x 7 x 7`张量然后通过反卷积层以提供`128 x 14 x 14`输出,然后通过具有 128 个特征和泄漏 ReLU 的 Batchnorm 层。 `128 x 14 x 14`然后在第二次反卷积中转换为`64 x 14 x 14`张量,在第三次反卷积中变为`1 x 28 x 28`张量; 这些只是我们需要的尺寸。 然后,我们创建生成器对象并将其移动到设备。
让我们看一下`forward`方法的工作方式。 `z_dim`维度的输入噪声矢量经过全连接层以提供 12544 输出。 然后,我们将 12544 输出调整为`256 x 7 x 7`,其中 256 是通道数。 `256 x 7 x 7`张量然后通过反卷积层以提供`128 x 14 x 14`输出,然后通过具有 128 个特征和泄漏 ReLU 的 Batchnorm 层。 `128 x 14 x 14`然后在第二次反卷积中转换为`64 x 14 x 14`张量,在第三次反卷积中变为`1 x 28 x 28`张量; 这些只是我们需要的尺寸。 然后,我们创建生成器对象并将其移动到设备。
# 也可以看看
...
...
@@ -171,7 +171,7 @@ self.disc = nn.Sequential(
)
```
4.然后定义最后一个完全连接的层:
4.然后定义最后一个全连接层:
```py
self.fc=nn.Linear(2048,1)
...
...
@@ -195,7 +195,7 @@ def forward(self, input):
# 这个怎么运作...
在本食谱中,我们定义了一个分类器; 使用`nn.Sequential()`定义卷积,激活和批处理规范化单元的数组; 并且还定义了最后一个完全连接的层,该层采用平坦的张量并给出通过 S 形层的单个输出。 由于只有两个类,因此我们最后使用了 S 形层。 输入是尺寸为`1 x 28 x 28`的图像张量,并经过第一卷积单元以给出尺寸为`32 x 14 x 14`的输出张量。 第二个卷积层使它成为`64 x 7 x 7`张量,然后从那里变成`128 x 4 x 4`。 之后,我们将拉平并使张量穿过完全连接的层。
在本食谱中,我们定义了一个分类器; 使用`nn.Sequential()`定义卷积,激活和批处理规范化单元的数组; 并且还定义了最后一个全连接层,该层采用平坦的张量并给出通过 S 形层的单个输出。 由于只有两个类,因此我们最后使用了 S 形层。 输入是尺寸为`1 x 28 x 28`的图像张量,并经过第一卷积单元以给出尺寸为`32 x 14 x 14`的输出张量。 第二个卷积层使它成为`64 x 7 x 7`张量,然后从那里变成`128 x 4 x 4`。 之后,我们将拉平并使张量穿过全连接层。