码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 你必须要知道CNN模型:ResNet残差网络


    相关资料

    • ResNet原始论文:https://arxiv.org/pdf/1512.03385.pdf
    • 我的wps论文笔记:Deep Residual Learning for Image Recognition
      在这里插入图片描述
    • 李沐视频:残差网络 ResNet【动手学深度学习v2】
    • 知乎:ResNet网络层分析

    CNN模型ResNet的核心思想

    ResNet解决了深度CNN模型难训练的问题。
    ResNet-18,ResNet-34,ResNet-50都可以用做CV中的图片特征提取器。

    • https://zh.d2l.ai/chapter_convolutional-modern/resnet.html
      在这里插入图片描述

    ResNet块

    原始ResNet块(1x1卷积是通道数变化的作用)

    果然是Conv->BN->ReLU的顺序。

    在这里插入图片描述

    我们也可以尝试各种架构的残差块,具体看实验效果,也学效果可能都差不多
    在这里插入图片描述

    ResNet:ResNet18, ResNet34, ResNet50…

    ResNet在PyTorch的官方代码中共有5种不同深度的结构,深度分别为18、34、50、101、152(各种网络的深度指的是“需要通过训练更新参数”的层数,如卷积层,全连接层等),和论文完全一致。
    在这里插入图片描述

    ResNet-18代码

    • https://zh.d2l.ai/chapter_convolutional-modern/resnet.html

    Pytorch官方代码

    • https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
    class BasicBlock(nn.Module):
        expansion: int = 1
    
        def __init__(
            self,
            inplanes: int,
            planes: int,
            stride: int = 1,
            downsample: Optional[nn.Module] = None,
            groups: int = 1,
            base_width: int = 64,
            dilation: int = 1,
            norm_layer: Optional[Callable[..., nn.Module]] = None,
        ) -> None:
            super().__init__()
            if norm_layer is None:
                norm_layer = nn.BatchNorm2d
            if groups != 1 or base_width != 64:
                raise ValueError("BasicBlock only supports groups=1 and base_width=64")
            if dilation > 1:
                raise NotImplementedError("Dilation > 1 not supported in BasicBlock")
            # Both self.conv1 and self.downsample layers downsample the input when stride != 1
            self.conv1 = conv3x3(inplanes, planes, stride)
            self.bn1 = norm_layer(planes)
            self.relu = nn.ReLU(inplace=True)
            self.conv2 = conv3x3(planes, planes)
            self.bn2 = norm_layer(planes)
            self.downsample = downsample
            self.stride = stride
    
        def forward(self, x: Tensor) -> Tensor:
            identity = x
    
            out = self.conv1(x)
            out = self.bn1(out)
            out = self.relu(out)
    
            out = self.conv2(out)
            out = self.bn2(out)
    
            if self.downsample is not None:
                identity = self.downsample(x)
    
            out += identity
            out = self.relu(out)
    
            return 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    相关问题

    问题1:Transformer中用的是ResNet吗?

    不是的,Transformer用的只是残差的思想,只是把输入加到输出。而ResNet是把多个ResNet块堆叠起来的CNN模型,是用在CV领域的图片特征提取器。

    问题2:ResNet为什么能训练出1000层的模型

    • 李沐: ResNet为什么能训练出1000层的模型

    一句话:梯度反向传播时,加深网络时,改用乘法,而不是加法。

    这样的好处:通常在靠近输入层的参数通常是比较难训练的,因为拿到的梯度比较小。引入ResNet后,因为加入了跳转或者说高速公路,所以在算梯度的时候,底层W的梯度可以直接让loss从高速公路反传过来,就不需要一定把中间很多卷积层走完。所以说在一开始的时候,我最下面的层也会拿到比较大的梯度,就是因为我加入了高速公路。。。同样地,倒数第二层也可以通过它上层的高速公路得到参数更新。 因此无论你模型有多深,我下面的层都能做参数的更新。
    在这里插入图片描述

    附:CNN模型ResNet-18网络架构图

    Conv(浅蓝)-> BN(白色) -> ReLU(深蓝)

    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    ES6-04-模块化的暴露:export关键字
    基于自适应自回归模型的高级人工智能概念及其实现
    linux服务端c++开发工具介绍(vscode版)
    Macos 远程登录 Ubuntu22.04 桌面
    Android仿淘宝、京东Banner滑动查看图文详情
    Python接口自动化 —— Json 数据处理实战(详解)
    Redis配置优化
    牛客NC314 体育课测验(一)【中等 图,BFS,拓扑排序 Java,Go、PHP】
    全志R128驱动OLED屏幕步骤教程
    第五篇、Callable接口实现多线程
  • 原文地址:https://blog.csdn.net/qq_43827595/article/details/127224545
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号