python - 权重卷积层有多少?
问题描述
我有一个简单的卷积网络:
import torch.nn as nn
class model(nn.Module):
def __init__(self, ks=1):
super(model, self).__init__()
self.conv1 = nn.Conv2d(in_channels=4, out_channels=32, kernel_size=ks, stride=1)
self.fc1 = nn.Linear(8*8*32*ks, 64)
self.fc2 = nn.Linear(64, 64)
def forward(self, x):
x = F.relu(self.conv1(x))
x = x.view(x.size(0), -1)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return x
cnn = model(1)
由于内核大小为1
且输出通道为32
,因此我假设32*1*1
该层中应该有权重。但是,当我询问pytorch
权重矩阵的形状时cnn.conv1.weight.shape
,它会返回torch.Size([32, 4, 1, 1])
。为什么输入通道的数量对conv2d
层的权重很重要?
我错过了什么吗?
解决方案
推荐阅读
- python - 如何为我的表单更改 css 文件中的一些内容?
- javascript - 使用 onchange javascript 重新加载 DIV 内容
- php - `usort` 未按预期对数组元素进行排序
- sql - 多列连接+聚合子查询导致无限运行时间
- java - 请求范围 bean 中的请求范围 bean
- html - iframe“(站点名称)拒绝连接。” 错误
- windows - 是否可以将 UI 自动化作为 Windows 服务运行?
- angular - 如何取消阻止 Angular 应用程序中的字体 - CORS 错误
- php - 使用 PDO 缓慢连接到 Postgresql
- javascript - 如何在弧形闪电图中仅禁用缩放交互