网站建设的费用报价,网站开发工程师面试问哪些问题,高性能网站建设指南在线阅读,免费做电脑网站吗#x1f368; 本文为#x1f517;365天深度学习训练营 中的学习记录博客 #x1f366; 参考文章地址#xff1a; 365天深度学习训练营-第J2周#xff1a;ResNet-50V2算法实战与解析 #x1f356; 作者#xff1a;K同学啊 一、ResNetV2与ResNet结构对比 改进点
(a)origi… 本文为365天深度学习训练营 中的学习记录博客 参考文章地址 365天深度学习训练营-第J2周ResNet-50V2算法实战与解析 作者K同学啊 一、ResNetV2与ResNet结构对比 改进点
(a)original 表示原始的 ResNet 的残差结构(b)proposed 表示新的 ResNet 的残差结构。主要差别就是(a)结构先卷积后进行 BN 和激活函数计算最后执行 addition 后再进行ReLU 计算 (b)结构先进行 BN 和激活函数计算后卷积把 addition 后的 ReLU 计算放到了残差结构内部。
改进结果
作者使用这两种不同的结构在 CIFAR-10 数据集上做测试模型用的是 1001层的 ResNet 模型。从图中结果我们可以看出(b)proposed 的测试集错误率明显更低一些达到了 4.92%的错误率(a)original 的测试集错误率是 7.61% 二、模型实现
2.1 残差结构 Residual Block
class Block2(nn.Module):def __init__(self, in_channel, filters, kernel_size3, stride1, conv_shortcutFalse):super(Block2, self).__init__()self.preact nn.Sequential(nn.BatchNorm2d(in_channel),nn.ReLU(True))self.shortcut conv_shortcutif self.shortcut:self.short nn.Conv2d(in_channel, 4*filters, 1, stridestride, padding0, biasFalse)elif stride1:self.short nn.MaxPool2d(kernel_size1, stridestride, padding0)else:self.short nn.Identity()self.conv1 nn.Sequential(nn.Conv2d(in_channel, filters, 1, stride1, biasFalse),nn.BatchNorm2d(filters),nn.ReLU(True))self.conv2 nn.Sequential(nn.Conv2d(filters, filters, kernel_size, stridestride, padding1, biasFalse),nn.BatchNorm2d(filters),nn.ReLU(True))self.conv3 nn.Conv2d(filters, 4*filters, 1, stride1, biasFalse)def forward(self, x):x1 self.preact(x)if self.shortcut:x2 self.short(x1)else:x2 self.short(x)x1 self.conv1(x1)x1 self.conv2(x1)x1 self.conv3(x1)x x1 x2return x 2.2 模块构建
class Stack2(nn.Module):def __init__(self, in_channel, filters, blocks, stride2):super(Stack2, self).__init__()self.conv nn.Sequential()self.conv.add_module(str(0), Block2(in_channel, filters, conv_shortcutTrue))for i in range(1, blocks-1):self.conv.add_module(str(i), Block2(4*filters, filters))self.conv.add_module(str(blocks-1), Block2(4*filters, filters, stridestride))def forward(self, x):x self.conv(x)return x 2.3 网络构建 构建ResNet50V2
class ResNet50V2(nn.Module):def __init__(self,include_topTrue, # 是否包含位于网络顶部的全链接层preactTrue, # 是否使用预激活use_biasTrue, # 是否对卷积层使用偏置input_shape[224, 224, 3],classes1000,poolingNone): # 用于分类图像的可选类数super(ResNet50V2, self).__init__()self.conv1 nn.Sequential()self.conv1.add_module(conv, nn.Conv2d(3, 64, 7, stride2, padding3, biasuse_bias, padding_modezeros))if not preact:self.conv1.add_module(bn, nn.BatchNorm2d(64))self.conv1.add_module(relu, nn.ReLU())self.conv1.add_module(max_pool, nn.MaxPool2d(kernel_size3, stride2, padding1))self.conv2 Stack2(64, 64, 3)self.conv3 Stack2(256, 128, 4)self.conv4 Stack2(512, 256, 6)self.conv5 Stack2(1024, 512, 3, stride1)self.post nn.Sequential()if preact:self.post.add_module(bn, nn.BatchNorm2d(2048))self.post.add_module(relu, nn.ReLU())if include_top:self.post.add_module(avg_pool, nn.AdaptiveAvgPool2d((1, 1)))self.post.add_module(flatten, nn.Flatten())self.post.add_module(fc, nn.Linear(2048, classes))else:if poolingavg:self.post.add_module(avg_pool, nn.AdaptiveAvgPool2d((1, 1)))elif poolingmax:self.post.add_module(max_pool, nn.AdaptiveMaxPool2d((1, 1)))def forward(self, x):x self.conv1(x)x self.conv2(x)x self.conv3(x)x self.conv4(x)x self.conv5(x)x self.post(x)return x 三、鸟类数据集效果
数据集可视化 后三个epoch
Epoch:18, Train_acc:92.9%, Train_loss:0.210, Test_acc:84.1%Test_loss:0.538
Epoch:19, Train_acc:94.9%, Train_loss:0.160, Test_acc:89.4%Test_loss:0.484
Epoch:20, Train_acc:92.7%, Train_loss:0.270, Test_acc:82.3%Test_loss:0.700
Done
best_acc 0.9491150442477876
Loss与Accuracy图 指定图片预测 文章转载自: http://www.morning.mlyq.cn.gov.cn.mlyq.cn http://www.morning.fkcjs.cn.gov.cn.fkcjs.cn http://www.morning.smxrx.cn.gov.cn.smxrx.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.pjrgb.cn.gov.cn.pjrgb.cn http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.mnmrx.cn.gov.cn.mnmrx.cn http://www.morning.nzmw.cn.gov.cn.nzmw.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.wsxxq.cn.gov.cn.wsxxq.cn http://www.morning.chongzhanggui.cn.gov.cn.chongzhanggui.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.mumgou.com.gov.cn.mumgou.com http://www.morning.bjsites.com.gov.cn.bjsites.com http://www.morning.mwwnz.cn.gov.cn.mwwnz.cn http://www.morning.hmfxl.cn.gov.cn.hmfxl.cn http://www.morning.mcqhb.cn.gov.cn.mcqhb.cn http://www.morning.zcwwb.cn.gov.cn.zcwwb.cn http://www.morning.snkry.cn.gov.cn.snkry.cn http://www.morning.fdjwl.cn.gov.cn.fdjwl.cn http://www.morning.dxhnm.cn.gov.cn.dxhnm.cn http://www.morning.nlgmr.cn.gov.cn.nlgmr.cn http://www.morning.tqbw.cn.gov.cn.tqbw.cn http://www.morning.ksggl.cn.gov.cn.ksggl.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.sfdsn.cn.gov.cn.sfdsn.cn http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.qmtzq.cn.gov.cn.qmtzq.cn http://www.morning.ygflz.cn.gov.cn.ygflz.cn http://www.morning.zdmlt.cn.gov.cn.zdmlt.cn http://www.morning.lkfsk.cn.gov.cn.lkfsk.cn http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn http://www.morning.tpdg.cn.gov.cn.tpdg.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.ykgkh.cn.gov.cn.ykgkh.cn http://www.morning.djpgc.cn.gov.cn.djpgc.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.jbfjp.cn.gov.cn.jbfjp.cn http://www.morning.hwprz.cn.gov.cn.hwprz.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.mgkcz.cn.gov.cn.mgkcz.cn http://www.morning.nlwrg.cn.gov.cn.nlwrg.cn http://www.morning.hypng.cn.gov.cn.hypng.cn http://www.morning.ltqzq.cn.gov.cn.ltqzq.cn http://www.morning.kkwgg.cn.gov.cn.kkwgg.cn http://www.morning.dfrenti.com.gov.cn.dfrenti.com http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.rwbh.cn.gov.cn.rwbh.cn http://www.morning.kkrnm.cn.gov.cn.kkrnm.cn http://www.morning.tldfp.cn.gov.cn.tldfp.cn http://www.morning.zcqtr.cn.gov.cn.zcqtr.cn http://www.morning.xnnpy.cn.gov.cn.xnnpy.cn http://www.morning.rxnr.cn.gov.cn.rxnr.cn http://www.morning.mqmxg.cn.gov.cn.mqmxg.cn http://www.morning.pdghl.cn.gov.cn.pdghl.cn http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.ncfky.cn.gov.cn.ncfky.cn http://www.morning.yrck.cn.gov.cn.yrck.cn http://www.morning.symgk.cn.gov.cn.symgk.cn http://www.morning.mmxnb.cn.gov.cn.mmxnb.cn http://www.morning.wsyq.cn.gov.cn.wsyq.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.jyyw.cn.gov.cn.jyyw.cn http://www.morning.mrxgm.cn.gov.cn.mrxgm.cn http://www.morning.mdjtk.cn.gov.cn.mdjtk.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.rgqnt.cn.gov.cn.rgqnt.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.qnbgh.cn.gov.cn.qnbgh.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn http://www.morning.yfrlk.cn.gov.cn.yfrlk.cn http://www.morning.hgbzc.cn.gov.cn.hgbzc.cn http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn