AlexNet网络
AlexNet网络的实现 导入必要的工具包 import time import torch from torch import nn , optim import torchvision 添加路径并且根据有无GPU进行选择 import sys sys . path . append ( ".." ) import d2lzh_pytorch as d2l device = torch . device ( 'cuda' if torch . cuda . is_available ( ) else 'cpu' ) 搭建自己的神经网络层 class AlexNet ( nn . Module ) : def __init__ ( self ) : super ( AlexNet , self ) . __init__ ( ) self . conv = nn . Sequential ( nn . Conv2d ( 1 , 96 , 11 , 4 ) , nn . ReLU ( ) , nn . MaxPool2d ( 3 , 2 ) , nn . Conv2d ( 96 , 256 , 5 , 1 , 2 ) , nn . ReLU ( ) , nn . MaxPool2d ( 3 , 2 ) , nn . Conv2d ( 256 , 384 , 3 , 1 , 1 ) ,