当前位置:网站首页>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
边栏推荐
- Leetcode153 - find the minimum value in the rotation sort array - array - binary search
- ASEMI三相整流桥和单相整流桥的详细对比
- 中富金石财富班29800效果如何?与专业投资者同行让投资更简单
- Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
- QT interface optimization: double click effect
- select 同时接收普通数据 和 带外数据
- LeetCode149-直线上最多的点数-数学-哈希表
- 大文件如何快速上传?
- 你还不知道责任链模式的使用场景吗?
- 【无标题】
猜你喜欢
1-初识Go语言
1 - first knowledge of go language
UML project example -- UML diagram description of tiktok
抑郁症治疗的进展
A good tool: aardio
【工厂模式详解】工厂方法模式
分享 20 个不容错过的 ES6 的技巧
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
DVWA之暴力破解(Brute Force)Low-->high
L'externalisation a duré quatre ans.
随机推荐
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
想要成为架构师?夯实基础最重要
pnpm安装使用
epoll 的 ET,LT工作模式———实例程序
LeetCode162-寻找峰值-二分-数组
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
Leetcode167 - sum of two numbers II - double pointer - bisection - array - Search
Epolloneshot event of epoll -- instance program
Branch statement of process control
每日一题-LeetCode396-旋转函数-递推
Mds55-16-asemi rectifier module mds55-16
Master in minutes --- ternary operator (ternary operator)
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
多语言通信基础 06 go实现grpc的四种数据流模式实现
ASEMI三相整流桥和单相整流桥的详细对比
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Redis主从同步
How do I open the win10 startup folder?
eolink 如何助力远程办公