本专栏用于记录关于深度学习的笔记,不光方便自己复习与查阅,同时也希望能给您解决一些关于深度学习的相关问题,并提供一些微不足道的人工神经网络模型设计思路。
专栏地址:「深度学习一遍过」必修篇
目录
1 正常卷积
以某二分类问题为例
核心代码
class simpleconv3(nn.Module):
def __init__(self):
super(simpleconv3,self).__init__()
self.conv1 = nn.Conv2d(3, 12, 3, 2)
self.bn1 = nn.BatchNorm2d(12)
self.conv2 = nn.Conv2d(12, 24, 3, 2)
self.bn2 = nn.BatchNorm2d(24)
self.conv3 = nn.Conv2d(24, 48, 3, 2)
self.bn3 = nn.BatchNorm2d(48)
self.fc1 = nn.Linear(1200 , 1200)
self.fc2 = nn.Linear(1200 , 128)
self.fc3 = nn.Linear(128 , 2)
def forward(self , x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = F.relu(self.bn3(self.conv3(x)))
x = x.view(-1 , 1200)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
模型结构
2 深度可分离卷积
还以此二分类问题为例
核心代码
class simpleconv3(nn.Module):
def __init__(self):
super(simpleconv3,self).__init__()
self.conv1 = nn.Conv2d(3, 12, 3, 2)
self.bn1 = nn.BatchNorm2d(12)
self.conv2 = nn.Conv2d(12, 24, 3, 2)
self.bn2 = nn.BatchNorm2d(24)
self.depth_conv = nn.Conv2d(in_channels=24,out_channels=24,kernel_size=3,stride=1,padding=1,groups=24)
self.bn3_1 = nn.BatchNorm2d(24)
self.point_conv = nn.Conv2d(in_channels=24,out_channels=48,kernel_size=1,stride=1,padding=0,groups=1)
self.bn3_2 = nn.BatchNorm2d(48)
self.fc1 = nn.Linear(48 * 11 * 11 , 1200)
self.fc2 = nn.Linear(1200 , 128)
self.fc3 = nn.Linear(128 , 2)
def forward(self , x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = F.relu(self.bn3_1(self.depth_conv(x)))
x = F.relu(self.bn3_2(self.point_conv(x)))
x = x.view(-1 , 48 * 11 * 11)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
模型结构
3 性能比较
参数量 | 训练时间(秒/百轮) | 模型大小 | 验证集准确率Top | |
正常的卷积 | 1,608,722 | 93.73 | 6,293 KB |
0.9785 |
深度可分离卷积 | 7,129,394 | 159.47 | 27,861 KB | 0.9586 |
训练集与测试集上的 及 曲线比较:(灰线:正常卷积;绿线:深度可分离卷积)
欢迎大家交流评论,一起学习
希望本文能帮助您解决您在这方面遇到的问题
感谢阅读
END