首页 > 解决方案 > PyTorch 2D 卷积层需要解释

问题描述

我需要解释 PyTorch 中的 Conv2d 操作中发生了什么。

如果我运行以下命令:

import torch
import torch.nn.functional as F

torch.manual_seed(0)

x = torch.randint(20, (1,3,4,4));
y = torch.randint(2, (1,3,2,2));
z = F.conv2d(x,y, stride=1);

print(f"Input: (shape={x.shape})\n")
print(x)
print("")
print(f"Filter/convolutional kernel: (shape={y.shape})\n")
print(y)
print("")
print(f"Feature Map: (shape={z.shape})\n")
print(z)

我得到:

在此处输入图像描述

特征图中左上角的条目不应该是:

19+19+6+16+8+18+17=103?

谢谢

标签: pythondeep-learningpytorch

解决方案


原来我的算术是错误的!

19+19+6+16+8+3+19=90


推荐阅读