当前位置:网站首页>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
边栏推荐
- When splicing HQL, the new field does not appear in the construction method
- Resolve the conflict between computed attribute and input blur event
- we引用My97DatePicker 实现时间插件使用
- 自动化的艺术
- 3、 Gradient descent solution θ
- 《JVM系列》 第七章 -- 字节码执行引擎
- 【Servlet】Servlet 详解(使用+原理)
- 1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
- Leetcode151 - invert words in string - String - simulation
- Explain TCP's three handshakes in detail
猜你喜欢

编程哲学——自动加载、依赖注入与控制反转

1N5408-ASEMI整流二极管1N5408

Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?

Role of asemi rectifier module mdq100-16 in intelligent switching power supply

1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)

LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找

ASEMI整流模块MDQ100-16在智能开关电源中的作用
![[NLP] HMM hidden Markov + Viterbi word segmentation](/img/9a/b39a166320c2f2001f10913f789c90.png)
[NLP] HMM hidden Markov + Viterbi word segmentation

8.4 循环神经网络从零实现

Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
随机推荐
[NLP] HMM hidden Markov + Viterbi word segmentation
vscode中文插件不生效问题解决
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
分享3个使用工具,在家剪辑5个作品挣了400多
GIS数据处理-cesium中模型位置设置
[servlet] detailed explanation of servlet (use + principle)
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
epoll 的 ET,LT工作模式———实例程序
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
Leetcode153 - find the minimum value in the rotation sort array - array - binary search
Mds55-16-asemi rectifier module mds55-16
【Proteus仿真】自动量程(范围<10V)切换数字电压表
电容
一款不错的工具:aardio
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
8.4 循环神经网络从零实现
Don't you know the usage scenario of the responsibility chain model?
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
【JZ46 把数字翻译成字符串】
we引用My97DatePicker 实现时间插件使用