当前位置:网站首页>Alexnet model
Alexnet model
2022-04-23 14:46: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://blog.csdn.net/Recursions/article/details/124361770
边栏推荐
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- 多语言通信基础 06 go实现grpc的四种数据流模式实现
- LotusDB 设计与实现—1 基本概念
- UML项目实例——抖音的UML图描述
- A blog allows you to learn how to write markdown on vscode
- A good tool: aardio
- PCIe X1 插槽的主要用途是什么?
- 【Proteus仿真】自动量程(范围<10V)切换数字电压表
- LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
- Model location setting in GIS data processing -cesium
猜你喜欢
[NLP] HMM hidden Markov + Viterbi word segmentation
你还不知道责任链模式的使用场景吗?
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
Arduino for esp8266串口功能简介
Parameter stack pressing problem of C language in structure parameter transmission
Introduction to Arduino for esp8266 serial port function
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
1 - first knowledge of go language
1-初识Go语言
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
随机推荐
JumpServer
When splicing HQL, the new field does not appear in the construction method
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Realization of four data flow modes of grpc based on Multilingual Communication
[servlet] detailed explanation of servlet (use + principle)
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
【工厂模式详解】工厂方法模式
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
【JZ46 把数字翻译成字符串】
数组模拟队列进阶版本——环形队列(真正意义上的排队)
pnpm安装使用
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
Resolve the conflict between computed attribute and input blur event
[jz46 translate numbers into strings]
帧同步 实现
Solve the problem of SSH configuration file optimization and slow connection
QT actual combat: Yunxi chat room
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序