当前位置:网站首页>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
边栏推荐
- Unity_代码方式添加绑定按钮点击事件
- epoll 的EPOLLONESHOT 事件———实例程序
- LeetCode167-两数之和II-双指针-二分-数组-查找
- Detailed explanation of C language knowledge points -- first knowledge of C language [1]
- 1n5408-asemi rectifier diode
- ASEMI超快恢复二极管与肖特基二极管可以互换吗
- 冰冰学习笔记:一步一步带你实现顺序表
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- Arduino for esp8266串口功能简介
- How do I open the win10 startup folder?
猜你喜欢
We reference My97DatePicker to realize the use of time plug-in
Brute force of DVWA low -- > High
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
【NLP】HMM隐马尔可夫+维特比分词
What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
QT actual combat: Yunxi calendar
LeetCode149-直线上最多的点数-数学-哈希表
随机推荐
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
UML项目实例——抖音的UML图描述
8.2 文本预处理
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
[untitled]
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
LeetCode167-两数之和II-双指针-二分-数组-查找
Unity_ Code mode add binding button click event
Brute force of DVWA low -- > High
Branch statement of process control
1 - first knowledge of go language
Model location setting in GIS data processing -cesium
SQLSERVER事物与锁的问题
Frame synchronization implementation
Svn detailed use tutorial
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
详解TCP的三次握手
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another