栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

用pytorch实现LeNet-5(有注释)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用pytorch实现LeNet-5(有注释)

# 第一层卷积池化 Sequential内的函数顺序执行 # 原文中激活函数都是用的sigmoid 这里使用更好的ReLu self.conv_pool1 nn.Sequential( nn.Conv2d(in_channels 1, # input (1, 28, 28) padding to(1,32,32) # 这里的input和output的值都是针对一个样本来说的 而训练时是一次输入一个batch out_channels 6, kernel_size (5, 5), padding 2), # output(6, 28, 28) nn.ReLU(), # 激活函数 nn.MaxPool2d(2, stride 2) # output(6, 14, 14) self.conv_pool2 nn.Sequential( nn.Conv2d(in_channels 6, out_channels 16, kernel_size (5, 5) ), # output(16, 10, 10) nn.ReLU(), nn.MaxPool2d(2, stride 2) # output(16, 5, 5) # 全连接层 self.fc1 nn.Sequential( # 这里用全连接层代替原文的卷积层 nn.Linear(16*5*5, 120), nn.ReLU() # 全连接层 self.fc2 nn.Sequential( nn.Linear(120, 84), nn.ReLU() # 输出层 self.out nn.Sequential( nn.Linear(84, 10), # 前向传播 def forward(self, x): x self.conv_pool1(x) x self.conv_pool2(x) x x.view(x.size(0), -1) # resize to 2-dims(batch_size, 16*5*5) 展平成1维 x self.fc1(x) x self.fc2(x) x self.out(x) return x
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267983.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号