当前位置:网站首页>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
边栏推荐
- MDS55-16-ASEMI整流模块MDS55-16
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- 八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
- 555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
- Detailed explanation of C language P2 selection branch statement
- Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
- QT interface optimization: double click effect
- UML项目实例——抖音的UML图描述
猜你喜欢
Model location setting in GIS data processing -cesium
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
QT Detailed explanation of pro file
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
1-初识Go语言
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
你還不知道責任鏈模式的使用場景嗎?
随机推荐
A good tool: aardio
线程同步、生命周期
QT Detailed explanation of pro file
MDS55-16-ASEMI整流模块MDS55-16
LotusDB 设计与实现—1 基本概念
如何打开Win10启动文件夹?
Epoll's et, lt working mode -- example program
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
Branch statement of process control
JumpServer
Contraction mapping theorem
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Thread synchronization, life cycle
OpenFaaS实战之四:模板操作(template)
想要成为架构师?夯实基础最重要
Explain TCP's three handshakes in detail
When splicing HQL, the new field does not appear in the construction method
2-GO variable operation
【JZ46 把数字翻译成字符串】
eolink 如何助力远程办公