当前位置:网站首页>Detailed explanation and reproduction of AlexNet network
Detailed explanation and reproduction of AlexNet network
2022-08-03 07:03:00 【WGS。】
详细请看:
''' Here the convolution kernel number set to the half of the original '''
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
# pytorch tensor通道顺序:[batch_size, channel, height, width],通道数、高、宽,The following comments to ignorebatch_size
# 这里为了方便padding直接为2了,The results for the decimal words will discard decimal point
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.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) # dim=1是channel的维度
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)
边栏推荐
猜你喜欢

el-tree设置利用setCheckedNodessetCheckedKeys默认勾选节点,以及通过setChecked新增勾选指定节点

10 common data types in MySQL

el-table实现列筛选功能,控制列的显示和隐藏(实现简单,效果满分)
![mysql 数据去重的三种方式[实战]](/img/37/ad4007a32d9eb563a303756785e72f.png)
mysql 数据去重的三种方式[实战]

【干货分享】PCB 板变形原因!不看不知道

Content type ‘applicationx-www-form-urlencoded;charset=UTF-8‘ not supported“【已解决】

Servlet详解含实例

SQLServer2019安装(Windows)

mysql事务与多版本并发控制

CISP-PTE真题演示
随机推荐
计算机网络高频面试考点
Getting Started with Chrome Plugin Development
cookie和session区别
docker-compose部署mysql
MySQL之concat的用法
el-table实现列筛选功能,控制列的显示和隐藏(实现简单,效果满分)
一家可靠的HDI板厂,需要具备哪些基本条件?
PCB制造常用的13种测试方法,你了解几种?
快速理解JVM+GC
MySQL的安装教程(嗷嗷详细,包教包会~)
MySQL中,对结果或条件进行字符串拼接
FiBiNet torch复现
UniApp 自定义条件编译详细使用流程
El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
Nacos单机模式的安装与启动
prometheus 监控mysql数据库
MySql的安装配置超详细教程与简单的建库建表方法
Basic syntax of MySQL DDL and DML and DQL
【multi_scale】多尺度训练——目标检测训练trick
【DIoU CIoU】DIoU和CIoU损失函数理解及代码实现