当前位置:网站首页>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
边栏推荐
猜你喜欢
ASEMI整流模块MDQ100-16在智能开关电源中的作用
What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
Redis主从同步
L'externalisation a duré quatre ans.
[detailed explanation of factory mode] factory method mode
【NLP】HMM隐马尔可夫+维特比分词
想要成为架构师?夯实基础最重要
eolink 如何助力远程办公
1-初识Go语言
随机推荐
Frame synchronization implementation
自动化的艺术
epoll 的EPOLLONESHOT 事件———实例程序
Achievements in science and Technology (21)
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
Find daffodils - for loop practice
LeetCode162-寻找峰值-二分-数组
epoll 的 ET,LT工作模式———实例程序
Want to be an architect? Tamping the foundation is the most important
Unity_ Code mode add binding button click event
如何打开Win10启动文件夹?
Daily question - leetcode396 - rotation function - recursion
Mds55-16-asemi rectifier module mds55-16
科技的成就(二十一)
牛客网数据库SQL实战详细剖析(26-30)
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
UML project example -- UML diagram description of tiktok
Progress in the treatment of depression
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user