当前位置:网站首页>Alexnet model
Alexnet model
2022-04-23 14:51:00 【Recurss】
import torch.nn as nn
import torch
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
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.Tanh(),
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)
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)
版权声明
本文为[Recurss]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231446151852.html
边栏推荐
- Want to be an architect? Tamping the foundation is the most important
- 冰冰学习笔记:一步一步带你实现顺序表
- Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
- vscode中文插件不生效问题解决
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- Progress in the treatment of depression
- Arduino for esp8266串口功能简介
- Comment eolink facilite le télétravail
- Detailed explanation of C language knowledge points -- first knowledge of C language [1]
- GIS数据处理-cesium中模型位置设置
猜你喜欢
随机推荐
Unity_ Code mode add binding button click event
ASEMI整流模块MDQ100-16在智能开关电源中的作用
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
QT actual combat: Yunxi calendar
【JZ46 把数字翻译成字符串】
LeetCode167-两数之和II-双指针-二分-数组-查找
Programming philosophy - automatic loading, dependency injection and control inversion
LeetCode162-寻找峰值-二分-数组
MDS55-16-ASEMI整流模块MDS55-16
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
Select receives both normal data and out of band data
January 1, 1990 is Monday. Define the function date_ to_ Week (year, month, day), which realizes the function of returning the day of the week after inputting the year, month and day, such as date_ to
抑郁症治疗的进展
Outsourcing for four years, abandoned
epoll 的EPOLLONESHOT 事件———实例程序
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
go基础 反射
Progress in the treatment of depression








