pytorch - 如何在 PyTorch conv2d 函数中批量使用组参数?
问题描述
接下来是如何在 PyTorch conv2d 函数中使用组参数中的问题
我可以知道输入批次大小是否= 4,对于每个批次,它都有独立的过滤器来与之转换,我将代码修改如下,
import torch
import torch.nn.functional as F
filters = torch.autograd.Variable(torch.randn(3,4,3,3))
inputs = torch.autograd.Variable(torch.randn(4,3,10,10))
out = F.conv2d(inputs, filters, padding=1, groups=3)
我有另一个错误 RuntimeError: Given groups=3, weight of size [3, 4, 3, 3], expected input[4, 3, 10, 10] 有 12 个通道,但有 3 个通道 如何解决?
解决方案
当您有过滤器时,shape (3,4,3,3)
预计通道数为 12
这应该工作
import torch
import torch.nn.functional as F
inputs = torch.autograd.Variable(torch.randn(3,12,10,10))
filters = torch.autograd.Variable(torch.randn(3,4,3,3))
out = F.conv2d(inputs, filters, padding=1, groups=3)
推荐阅读
- c# - 将 Html.DropDownListFor 与 System.Linq.Enumerable 一起使用时,选择/选项中没有值属性
- python - 如何纠正 TypeError:execute() 需要 2 到 4 个位置参数,但给出了 5 个?
- c# - C#如何递归搜索属性名称
- javascript - 每个间隔拆分字符串并将其附加到其相应的数组数组
- python - 问题安装 python 要求。错误:命令出错,退出状态为 1
- javascript - 试图让我的函数能够拥有动态选择器,这样我就不必重复自己了
- vector - 如何转换 Vec
- 到 Vec
? - 到 Vec
- sql - 如何解决 max_stack_depth?
- reactjs - heroku 不想玩我的 p5-react 应用程序
- haskell - 不知道如何正确键入我的 N 叉树