当前位置:网站首页>Detailed explanation and reproduction of AlexNet network
Detailed explanation and reproduction of AlexNet network
2022-08-03 07:03:00 【WGS。】
详细请看:
''' Here the convolution kernel number set to the half of the original '''
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
# pytorch tensor通道顺序:[batch_size, channel, height, width],通道数、高、宽,The following comments to ignorebatch_size
# 这里为了方便padding直接为2了,The results for the decimal words will discard decimal point
nn.Conv2d(3, 48, kernel_size=11, stride=4, padding=2), # input[3, 224, 224] output[48, 55, 55]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), # output[48, 27, 27]
nn.Conv2d(48, 128, kernel_size=5, padding=2), # output[128, 27, 27]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), # output[128, 13, 13]
nn.Conv2d(128, 192, kernel_size=3, padding=1), # output[192, 13, 13]
nn.ReLU(inplace=True),
nn.Conv2d(192, 192, kernel_size=3, padding=1), # output[192, 13, 13]
nn.ReLU(inplace=True),
nn.Conv2d(192, 128, kernel_size=3, padding=1), # output[128, 13, 13]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), # output[128, 6, 6]
)
self.classifier = nn.Sequential(
nn.Dropout(p=0.5),
nn.Linear(128 * 6 * 6, 2048),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5),
nn.Linear(2048, 2048),
nn.ReLU(inplace=True),
nn.Linear(2048, num_classes),
)
# 初始化权重
if init_weights:
self._initialize_weights()
def forward(self, x):
x = self.features(x)
x = torch.flatten(x, start_dim=1) # dim=1是channel的维度
x = self.classifier(x)
return x
def _initialize_weights(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.Linear):
nn.init.normal_(m.weight, 0, 0.01)
nn.init.constant_(m.bias, 0)
边栏推荐
- C语言实现通讯录功能(400行代码实现)
- El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
- 连续型特征做embedding代码示例
- MySql之json_extract函数处理json字段
- Content type ‘applicationx-www-form-urlencoded;charset=UTF-8‘ not supported“【已解决】
- sql优化常用的几种方法
- MySQL的on duplicate key update 的使用
- RADIUS计费认证如何配置?这篇文章一步一步教你完成
- IFM网络详解及torch复现
- 【应届生租房】应届生如何租房以及注意事项
猜你喜欢
随机推荐
Nacos与Eureka的区别
Servlet详解含实例
MySQL的on duplicate key update 的使用
linux安装redis
PostMan测试接口-----上传文件、导出excel
Oracle Common Commands - Basic Commands
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
PHP Composer常用命令积累
el-tree设置选中高亮焦点高亮、选中的节点加深背景,更改字体颜色等
如何使用md5码验证文件的一致性
信息学奥赛一本通T1447:靶形数独
MySQL的安装(详细教程)
Nvidia NX使用向日葵远程桌面遇到的问题
连续型特征做embedding代码示例
Shell脚本--信号发送与捕捉
ES6中 Symbol 的基础学习,迭代器和生成器的基本用法
el-tabs(标签栏)的入门学习
CPU上下文切换详解思维导图
Scala 高阶(八):集合内容汇总(下篇)
MySQL中,对结果或条件进行字符串拼接









