我不明白当数据是 3D 时 BatchNorm1d 如何工作(批量大小、H、W)。
例子
如果我随后包含批量归一化层,则需要 num_features=50:
我不明白为什么不是 20:
示例1)
class Net(nn.Module):
def __init__(self):
super(Net,self).__init__()
self.bn11 = nn.BatchNorm1d(50)
self.fc11 = nn.Linear(70,20)
def forward(self, inputs):
out = self.fc11(inputs)
out = torch.relu(self.bn11(out))
return out
model = Net()
inputs = torch.Tensor(2,50,70)
outputs = model(inputs)
Run Code Online (Sandbox Code Playgroud)
示例2)
class Net(nn.Module):
def __init__(self):
super(Net,self).__init__()
self.bn11 = nn.BatchNorm1d(20)
self.fc11 = nn.Linear(70,20)
def forward(self, inputs):
out = self.fc11(inputs)
out = torch.relu(self.bn11(out))
return out
model = Net()
inputs = torch.Tensor(2,50,70) …Run Code Online (Sandbox Code Playgroud) pytorch ×1