当前位置:网站首页>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
边栏推荐
- 外包干了四年,废了...
- A good tool: aardio
- Detailed explanation of SAR command
- Detailed explanation of C language P2 selection branch statement
- 51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
- Usage of BC
- MySQL error packet out of order
- [jz46 translate numbers into strings]
- epoll 的EPOLLONESHOT 事件———实例程序
- Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
猜你喜欢
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
全连接层的作用是什么?
3、 Gradient descent solution θ
线程同步、生命周期
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
抑郁症治疗的进展
ASEMI整流模块MDQ100-16在智能开关电源中的作用
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
Bingbing learning notes: take you step by step to realize the sequence table
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
随机推荐
详解TCP的三次握手
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
你還不知道責任鏈模式的使用場景嗎?
阿里研发三面,面试官一套组合拳让我当场懵逼
Achievements in science and Technology (21)
First acquaintance with STL
2-GO variable operation
2-Go变量操作
UML项目实例——抖音的UML图描述
Logical volume creation and expansion
eolink 如何助力远程办公
When splicing HQL, the new field does not appear in the construction method
【JZ46 把数字翻译成字符串】
redis的五种数据类型
Solve the problem of SSH configuration file optimization and slow connection
想要成为架构师?夯实基础最重要
QT interface optimization: QT border removal and form rounding
We reference My97DatePicker to realize the use of time plug-in
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)