王权富贵:GoogLeNet的pytorch实现
2019-04-13 23:27
288 查看
感谢kuangliu,参考自这个项目里面的一篇叫googlenet.py的文档。
先构建一个基本的Inception模块。构造如上图所示,具体代码如下所示。
[code]'''GoogLeNet with PyTorch.''' import torch import torch.nn as nn import torch.nn.functional as F class Inception(nn.Module): def __init__(self, in_planes, n1x1, n3x3red, n3x3, n5x5red, n5x5, pool_planes): super(Inception, self).__init__() # 1x1 conv branch self.b1 = nn.Sequential( nn.Conv2d(in_planes, n1x1, kernel_size=1), nn.BatchNorm2d(n1x1), nn.ReLU(True), ) # 1x1 conv -> 3x3 conv branch self.b2 = nn.Sequential( nn.Conv2d(in_planes, n3x3red, kernel_size=1), nn.BatchNorm2d(n3x3red), nn.ReLU(True), nn.Conv2d(n3x3red, n3x3, kernel_size=3, padding=1), nn.BatchNorm2d(n3x3), nn.ReLU(True), ) # 1x1 conv -> 5x5 conv branch self.b3 = nn.Sequential( nn.Conv2d(in_planes, n5x5red, kernel_size=1), nn.BatchNorm2d(n5x5red), nn.ReLU(True), nn.Conv2d(n5x5red, n5x5, kernel_size=3, padding=1), nn.BatchNorm2d(n5x5), nn.ReLU(True), nn.Conv2d(n5x5, n5x5, kernel_size=3, padding=1), nn.BatchNorm2d(n5x5), nn.ReLU(True), ) # 3x3 pool -> 1x1 conv branch self.b4 = nn.Sequential( nn.MaxPool2d(3, stride=1, padding=1), nn.Conv2d(in_planes, pool_planes, kernel_size=1), nn.BatchNorm2d(pool_planes), nn.ReLU(True), )
GooLeNet的构建如下代码所示,对应结构图,在代码下面显示:
[code]class GoogLeNet(nn.Module): def __init__(self): super(GoogLeNet, self).__init__() self.pre_layers = nn.Sequential( nn.Conv2d(3, 192, kernel_size=3, padding=1), nn.BatchNorm2d(192), nn.ReLU(True), ) self.a3 = Inception(192, 64, 96, 128, 16, 32, 32) self.b3 = Inception(256, 128, 128, 192, 32, 96, 64) self.maxpool = nn.MaxPool2d(3, stride=2, padding=1) self.a4 = Inception(480, 192, 96, 208, 16, 48, 64) self.b4 = Inception(512, 160, 112, 224, 24, 64, 64) self.c4 = Inception(512, 128, 128, 256, 24, 64, 64) self.d4 = Inception(512, 112, 144, 288, 32, 64, 64) self.e4 = Inception(528, 256, 160, 320, 32, 128, 128) self.a5 = Inception(832, 256, 160, 320, 32, 128, 128) self.b5 = Inception(832, 384, 192, 384, 48, 128, 128) self.avgpool = nn.AvgPool2d(8, stride=1) self.linear = nn.Linear(1024, 10) def forward(self, x): out = self.pre_layers(x) out = self.a3(out) out = self.b3(out) out = self.maxpool(out) out = self.a4(out) out = self.b4(out) out = self.c4(out) out = self.d4(out) out = self.e4(out) out = self.maxpool(out) out = self.a5(out) out = self.b5(out) out = self.avgpool(out) out = out.view(out.size(0), -1) out = self.linear(out) return out
Inception模块中通道的选取参考如下:
上面代码是简化版,它在开始部分没有经过一个7*7和1*1的卷积,直接从3*3开始。辅助分类器也没有写上。
相关文章推荐
- Tensorflow 实现Google Inception Net
- Google Map开发(一) ASP.NET中调用Google Map API实现简单的地图显示
- mxnet,gluon学习笔记3——主干网络实现代码对比:AlexNet,VGG,NIN,googLeNet,ResNet,DesNet
- asp.net手写AJAX实现类似Google的搜索提示
- google facenet+ROS实现人脸识别
- Tensorflow实现Google Inception Net
- MXNet动手学深度学习笔记:GoogLeNet神经网络实现
- 【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络GoogLeNet
- 浅谈asp.net通过本机cookie仿百度(google)实现搜索input框自动弹出搜索提示
- 使用VB.NET实现 Google Web Service
- keras实现常用深度学习模型LeNet,AlexNet,ZFNet,VGGNet,GoogleNet,Resnet
- 学习笔记TF032:实现Google Inception Net
- Google Map开发(一) ASP.NET中调用Google Map API实现简单的地图显示
- 使用FlexBox和Json实现类似ComboBox(类似Google的输入提示和自动)功能-基于JQuery-ASP.NET
- GoogleNet网络详解与keras实现
- ASP.NET实验五:实现输入内容提示的功能(仿google_百度输入框提示)
- [pytorch] 深度学习分割网络U-net的pytorch模型实现
- 深度学习卷积神经网络——经典网络GoogLeNet(Inception V3)网络的搭建与实现
- Tensorflow实战学习(三十二)【实现Google Inception Net】
- 经典卷积神经网络(LeNet、AlexNet、VGG、GoogleNet、ResNet)的实现(MXNet版本)