python - 了解 PyTorch CNN channel

标签 python machine-learning neural-network deep-learning pytorch

我对 CNN 和 channel 的工作方式有点困惑。具体来说,这两个实现为什么不相等? # of output channels 不就是应用了多少 # filter 吗?

    self.conv1 = nn.Conv2d(1, 10, kernel_size=(3, self.embeds_size))
    self.conv2 = nn.ModuleList([nn.Conv2d(1, 1, kernel_size=(3, self.embeds_size)) for f in range(10)])
    ...


    conv1s = self.conv1(x)
    conv2s = [conv(x) for conv in self.conv2]
    conv2s = torch.stack(conv2s, 1).squeeze(2)
    print(torch.equal(conv1s, conv2s))

最佳答案

检查不同模块的状态字典。除非你正在做一些你没有告诉我们的奇特的事情,否则 PyTorch 将随机初始化权重。具体来说,试试这个:

print(self.conv1.state_dict()["weight"][0])
print(self.conv2[0].state_dict()["weight"][0])

它们会有所不同。

关于python - 了解 PyTorch CNN channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49362616/

相关文章:

python-3.x - 在 python 中使用 MLP 分类器的不平衡数据集

python - 将一串空格分隔的单词拆分为多行

python - 有没有更好的方法将方法作为参数传递?

machine-learning - Keras多标签分类 'to_categorical'错误

python - 通过从现有值的分布中抽样来估算缺失值

python - 在支持 Multi-Tenancy 的 Django 中正确加载 Keras 模型

python - TimedRotatingFileHandler 更改文件名?

python - GAE 中的多对多关系。查询失败

C# Accord.net。文本分类

machine-learning - 在反向传播中使用激活导数