当前位置:网站首页>动手学深度学习_VggNet
动手学深度学习_VggNet
2022-08-04 18:37:00 【CV小Rookie】
VggNet 是 AlexNet 的改进,将 AlexNet 网络中的 5x5 或 11x11 的卷积核全都替换成 3x3 的大小;maxpoolin 改成了 2x2 的大小;另外对于部分卷积和Pooling进行块的封装,使用循环来构建复杂的框架。
上图是Vgg16的结构图,可以看到一共有 5 块,前两块是2层卷积+一层maxpooling,后三层是3层卷积+一层maxpooling。
具体设计网络的时候可以参考下面的表格,十分清晰。
def Conv3x3BNReLU(in_channels,out_channels):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels,out_channels=out_channels,kernel_size=3,stride=1,padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU6(inplace=True)
)
class VGG(nn.Module):
def __init__(self, block_nums,num_classes=10):
super(VGG, self).__init__()
self.stage1 = self._make_layers(in_channels=1, out_channels=64, block_num=block_nums[0])
self.stage2 = self._make_layers(in_channels=64, out_channels=128, block_num=block_nums[1])
self.stage3 = self._make_layers(in_channels=128, out_channels=256, block_num=block_nums[2])
self.stage4 = self._make_layers(in_channels=256, out_channels=512, block_num=block_nums[3])
self.stage5 = self._make_layers(in_channels=512, out_channels=512, block_num=block_nums[4])
self.classifier = nn.Sequential(
nn.Linear(in_features=512*7*7,out_features=4096),
nn.Dropout(p=0.2),
nn.Linear(in_features=4096, out_features=4096),
nn.Dropout(p=0.2),
nn.Linear(in_features=4096, out_features=num_classes)
)
self._init_params()
def _make_layers(self, in_channels, out_channels, block_num):
layers = []
layers.append(Conv3x3BNReLU(in_channels,out_channels))
for i in range(1,block_num):
layers.append(Conv3x3BNReLU(out_channels,out_channels))
layers.append(nn.MaxPool2d(kernel_size=2,stride=2, ceil_mode=False))
return nn.Sequential(*layers)
def _init_params(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
elif isinstance(m, nn.BatchNorm2d):
nn.init.constant_(m.weight, 1)
nn.init.constant_(m.bias, 0)
def forward(self, x):
x = self.stage1(x)
x = self.stage2(x)
x = self.stage3(x)
x = self.stage4(x)
x = self.stage5(x)
x = x.view(x.size(0),-1)
out = self.classifier(x)
return out
def VGG16():
block_nums = [2, 2, 3, 3, 3]
model = VGG(block_nums)
return model
def VGG19():
block_nums = [2, 2, 4, 4, 4]
model = VGG(block_nums)
return model
打印一下看看网络具体结构吧
Sequential output shape: torch.Size([1, 64, 112, 112]) Sequential output shape: torch.Size([1, 128, 56, 56]) Sequential output shape: torch.Size([1, 256, 28, 28]) Sequential output shape: torch.Size([1, 512, 14, 14]) Sequential output shape: torch.Size([1, 512, 7, 7]) Flatten output shape: torch.Size([1, 25088]) Linear output shape: torch.Size([1, 4096]) ReLU output shape: torch.Size([1, 4096]) Dropout output shape: torch.Size([1, 4096]) Linear output shape: torch.Size([1, 4096]) ReLU output shape: torch.Size([1, 4096]) Dropout output shape: torch.Size([1, 4096]) Linear output shape: torch.Size([1, 10])
边栏推荐
- 什么是网站监控,网站监控软件有什么用?
- Flask框架实现注册加密功能详解【Flask企业课学习】
- EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?
- PHP代码审计7—文件上传漏洞
- 天呐,七夕我收到9份告白~
- Global electronics demand slows: Samsung's Vietnam plant significantly reduces capacity
- Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
- 通配符SSL证书不支持多域名吗?
- Thrift installation configuration
- gbase8s创建RANGE分片表
猜你喜欢
面试官:MVCC是如何实现的?
How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
limux入门3—磁盘与分区管理
unity中实现ue眼球的渲染
ros2订阅esp32发布的电池电压数据
EasyCVR调用云端录像API接口返回错误且无录像文件生成,是什么原因?
网络运维管理从基础到实战-自用笔记(1)构建综合园区网、接入互联网
Matlab drawing 1
路由技术
随机推荐
PHP代码审计9—代码执行漏洞
当项目中自动格式化插件Prettier和ESLint冲突报错时如何解决
运力升级助力算力流转,中国数字经济的加速时刻
EasyCVR如何通过接口调用设备录像的倍速回放?
July 31, 2022 Summary of the third week of summer vacation
vantui 组件 van-field 路由切换时,字体样式混乱问题
Matlab drawing 1
如何封装 svg
Understanding of margin collapse and coincidence
mood swings
How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
路由懒加载
如何给MySQL添加自定义语法 ?
ECCV 2022 | FPN错位对齐,实现高效半监督目标检测(PseCo)
Google Earth Engine APP——一键在线查看全球1984-至今年的影像同时加载一个影像分析
EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
阿里云国际版使用ROS搭建WordPress教程
网络运维管理从基础到实战-自用笔记(1)构建综合园区网、接入互联网
关于使用腾讯云HiFlow场景连接器每天提醒签到打卡
企业即时通讯软件有哪些功能?对企业有什么帮助?