深度学习(20)深度卷积神经网络AlexNet

1. AlexNet网络

2. 总结

1. AlexNet网络(使用自定义)

python 复制代码
# 深度卷积神经网络 (AlexNet)
import torch
from torch import nn
from d2l import torch as d2l

net = nn.Sequential(
    nn.Conv2d(1,96,kernel_size=11,stride=4,padding=1),nn.ReLU(), # 数据集为fashion_mnist图片,所以输入通道为1,如果是Imagnet图片,则通道数应为3     
    nn.MaxPool2d(kernel_size=3,stride=2),
    nn.Conv2d(96,256,kernel_size=5,padding=2),nn.ReLU(), # 256为输出通道数
    nn.MaxPool2d(kernel_size=3,stride=2),
    nn.Conv2d(256,384,kernel_size=3,padding=1),nn.ReLU(),
    nn.Conv2d(384,384,kernel_size=3,padding=1),nn.ReLU(),
    nn.Conv2d(384,256,kernel_size=3,padding=1),nn.ReLU(),
    nn.MaxPool2d(kernel_size=3,stride=2),nn.Flatten(),
    nn.Linear(6400,4096),nn.ReLU(),nn.Dropout(p=0.5),
    nn.Linear(4096,4096),nn.ReLU(),nn.Dropout(p=0.5),
    nn.Linear(4096,10))

X = torch.randn(1,1,224,224)
for layer in net:
    X = layer(X)
    print(layer.__class__.__name__,'Output shape:\t', X.shape)
复制代码
Conv2d Output shape:	 torch.Size([1, 96, 54, 54])
ReLU Output shape:	 torch.Size([1, 96, 54, 54])
MaxPool2d Output shape:	 torch.Size([1, 96, 26, 26])
Conv2d Output shape:	 torch.Size([1, 256, 26, 26])
ReLU Output shape:	 torch.Size([1, 256, 26, 26])
MaxPool2d Output shape:	 torch.Size([1, 256, 12, 12])
Conv2d Output shape:	 torch.Size([1, 384, 12, 12])
ReLU Output shape:	 torch.Size([1, 384, 12, 12])
Conv2d Output shape:	 torch.Size([1, 384, 12, 12])
ReLU Output shape:	 torch.Size([1, 384, 12, 12])
Conv2d Output shape:	 torch.Size([1, 256, 12, 12])
ReLU Output shape:	 torch.Size([1, 256, 12, 12])
MaxPool2d Output shape:	 torch.Size([1, 256, 5, 5])
Flatten Output shape:	 torch.Size([1, 6400])
Linear Output shape:	 torch.Size([1, 4096])
ReLU Output shape:	 torch.Size([1, 4096])
Dropout Output shape:	 torch.Size([1, 4096])
Linear Output shape:	 torch.Size([1, 4096])
ReLU Output shape:	 torch.Size([1, 4096])
Dropout Output shape:	 torch.Size([1, 4096])
Linear Output shape:	 torch.Size([1, 10])
python 复制代码
# Fashion-MNIST图像的分辨率 低于ImageNet图像。将它们增加到224×224
batch_size = 128
train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size,resize=224)  

lr, num_epochs = 0.01, 10
d2l.train_ch6(net,train_iter,test_iter,num_epochs,lr,d2l.try_gpu())
复制代码
loss 0.327, train acc 0.881, test acc 0.880
1666.6 examples/sec on cuda:0
相关推荐
代码方舟几秒前
企业级对公银行 KYC 架构:基于天远人脸身份证比对A构建自动化客户尽调网关
运维·人工智能·架构·自动化
xingyun862 分钟前
DeepSeek涨价,你换了吗?——AI大模型服务成本与替代方案深度分析
人工智能
程序员cxuan3 分钟前
DeepSeek Harness 必装的插件公布了!
人工智能·后端·程序员
Claire_887 分钟前
自然语言处理在法律文书生成中的应用:以离婚协议为例的多工具功能对比
人工智能·自然语言处理
樊小肆11 分钟前
DeepSeeker-Code源码导读05-计划模式与子Agent
人工智能·agent
办公室马主任11 分钟前
乐图数字化打通哪几个环节?从车间数据到经营决策的数据链路设计
大数据·人工智能·系统架构·制造
delishcomcn13 分钟前
数字孪生+AI预测:热烫膜分切机迈向“黑灯工厂”的关键路径
大数据·人工智能
ITresearchGuest14 分钟前
高级前端开发职业规划(2026—2035)
人工智能
皮皮虾❀15 分钟前
典铭云赛(FDE服务模式)开通钉钉AI功能全攻略:版本选择与配置指南
人工智能·钉钉
Raas10018 分钟前
MAI Gateway(魔芋企业级AI网关):企业AI网关的合规审计与调用留痕设计
大数据·人工智能·gateway·企业·api网关·mai gateway·企业级网关