当前位置:网站首页>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
边栏推荐
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- Leetcode exercise - 396 Rotation function
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- capacitance
- 拼接hql时,新增字段没有出现在构造方法中
- 线程同步、生命周期
- I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
- Leetcode165 compare version number double pointer string
- LeetCode151-颠倒字符串中的单词-字符串-模拟
- MySQL报错packet out of order
猜你喜欢

Want to be an architect? Tamping the foundation is the most important

Progress in the treatment of depression

MySQL报错packet out of order

【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序

Find daffodils - for loop practice

What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier

Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge

博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA

L'externalisation a duré quatre ans.

LeetCode165-比较版本号-双指针-字符串
随机推荐
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
科技的成就(二十一)
一个月把字节,腾讯,阿里都面了,写点面经总结……
Alexnet model
Find daffodils - for loop practice
QT Detailed explanation of pro file
Progress in the treatment of depression
Resolve the conflict between computed attribute and input blur event
UML project example -- UML diagram description of tiktok
ASEMI整流模块MDQ100-16在智能开关电源中的作用
Leetcode162 - find peak - dichotomy - array
LeetCode162-寻找峰值-二分-数组
thinkphp5+数据大屏展示效果
电容
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
When splicing HQL, the new field does not appear in the construction method
Chapter 7 of JVM series -- bytecode execution engine
1 - first knowledge of go language
Leetcode165 compare version number double pointer string
How do I open the win10 startup folder?