前言
本学习笔记参考自B站up主霹雳吧啦Wz
代码均来自导师github开源项目WZMIAOMIAO/deep-learning-for-image-processing: deep learning for image processing including classification and object-detection etc. (github.com)
视频链接在这里:2.1 pytorch官方demo(Lenet)_哔哩哔哩_bilibili
AlexNet网络结构
AlexNet是2012年ImageNet竞赛冠军获得者Hinton和他的学生Alex Krizhevsky设计的。
其中也是首次再CNN中应用到了ReLU和Dropout
![](https://s2.loli.net/2022/05/15/YdsSHaO7UoNZ8qM.png)
输入的数据特征为224×224×3,同时论文中采用双GPU并行运算的方法,我们就只采用单GPU,所以就运行下方图中的一半就好了。
![](https://s2.loli.net/2022/05/15/s6jKz1LyOkfRPIx.png)
1、Model
注意:pytorch框架中的Tensor通道排序为[batch_size, channel, height, width]
import torch.nn as nn
import torch
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False): # init_weights为定义的初始化权重函数
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<