浅谈pytorch卷积核大小的设置对全连接神经元的影响

浅谈pytorch卷积核大小的设置对全连接神经元的影响,第1张

浅谈pytorch卷积核大小的设置对全连接神经元的影响

3*3卷积核与2*5卷积核对神经元大小的设置

#这里kerner_size = 2*5
class CONV_NET(torch.nn.Module): #CONV_NET类继承nn.Module类
 def __init__(self):
  super(CONV_NET, self).__init__() #使CONV_NET类包含父类nn.Module的所有属性
  # super()需要两个实参,子类名和对象self
  self.conv1 = nn.Conv2d(1, 32, (2, 5), 1, padding=0)
  self.conv2 = nn.Conv2d(32, 128, 1, 1, padding=0)
  self.fc1 = nn.Linear(512, 128)
  self.relu1 = nn.ReLU(inplace=True)
  self.drop1 = nn.Dropout(0.5)
  self.fc2 = nn.Linear(128, 32)
  self.relu2 = nn.ReLU(inplace=True)
  self.fc3 = nn.Linear(32, 3)
  self.softmax = nn.Softmax(dim=1)

 def forward(self, x):
  x = self.conv1(x)
  x = self.conv2(x)
  x = x.view(x.size(0), -1)
  x = self.fc1(x)
  x = self.relu1(x)
  x = self.drop1(x)
  x = self.fc2(x)
  x = self.relu2(x)
  x = self.fc3(x)
  x = self.softmax(x)
  return x

主要看对称卷积核以及非对称卷积核之间的计算方式

#这里kerner_size = 3*3
class CONV_NET(torch.nn.Module): #CONV_NET类继承nn.Module类
 def __init__(self):
  super(CONV_NET, self).__init__() #使CONV_NET类包含父类nn.Module的所有属性
  # super()需要两个实参,子类名和对象self
  self.conv1 = nn.Conv2d(1, 32, 3, 1, padding=1)
  self.conv2 = nn.Conv2d(32, 128, 1, 1, padding=0)
  self.fc1 = nn.Linear(3200, 128)
  self.relu1 = nn.ReLU(inplace=True)
  self.drop1 = nn.Dropout(0.5)
  self.fc2 = nn.Linear(128, 32)
  self.relu2 = nn.ReLU(inplace=True)
  self.fc3 = nn.Linear(32, 3)
  self.softmax = nn.Softmax(dim=1)

 def forward(self, x):
  x = self.conv1(x)
  x = self.conv2(x)
  x = x.view(x.size(0), -1)
  x = self.fc1(x)
  x = self.relu1(x)
  x = self.drop1(x)
  x = self.fc2(x)
  x = self.relu2(x)
  x = self.fc3(x)
  x = self.softmax(x)
  return x

针对kerner_size=2*5,padding=0,stride=1以及kerner_size=3*3,padding=1,stride=1二者计算方式的比较如图所示

以上这篇浅谈pytorch卷积核大小的设置对全连接神经元的影响就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/3242468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-04
下一篇 2022-10-04

发表评论

登录后才能评论

评论列表(0条)

保存