微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pytorch conv2d配重

如何解决pytorch conv2d配重

我有以下两个变量:

result- tensor 1 X 251 X 20
kernel - tensor 1 X 10 X 10

当我运行命令时:

from torch.nn import functional as F
result = F.conv2d(result,kernel)

我得到了错误

RuntimeError: expected stride to be a single integer value or a list of 1 values to match the convolution dimensions,but got stride=[1,1]

我没有大步向前,我在做什么错了?

解决方法

import torch
import torch.nn.functional as F
image = torch.rand(16,3,32,32)
filter = torch.rand(1,5,5)
out_feat_F = F.conv2d(image,filter,stride=1,padding=0)
print(out_feat_F.shape)

出局:

torch.Size([16,1,28,28])

等同于:

import torch
import torch.nn
image = torch.rand(16,32)
conv_filter = torch.nn.Conv2d(in_channels=3,out_channels=1,kernel_size=5,padding=0)
output_feature = conv_filter(image)
print(output_feature.shape)

出局:

torch.Size([16,28])

填充默认为0,步幅默认为1。 第一个示例中的过滤器最后两个维度对应于 第二个示例中的内核大小。

kernel_size=5kernel_size=(5,5)相同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。