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

yipeiwu_com7年前Python基础

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卷积核大小的设置对全连接神经元的影响就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python ZipFile模块详解

Python zipfile模块用来做zip格式编码的压缩和解压缩的,zipfile里有两个非常重要的class, 分别是ZipFile和ZipInfo, 在绝大多数的情况下,我们只需要...

python中将阿拉伯数字转换成中文的实现代码

复制代码 代码如下: #!/usr/bin/python #-*- encoding: utf-8 -*- import types class NotIntegerError(Exce...

Python实现查看系统启动项功能示例

本文实例讲述了Python实现查看系统启动项功能。分享给大家供大家参考,具体如下: 一、代码 # -*- coding:utf-8 -*- #! python3 from win32...

同时安装Python2 & Python3 cmd下版本自由选择的方法

同时安装Python2 & Python3 cmd下版本自由选择的方法

系统:win7 python2.7,python3.6同时安装,于是问题来了,python27与python36文件夹下的文件名都是python.exe 这样在cmd下,直接输入pyt...

python中的一些类型转换函数小结

函数               &...