码农知识堂 - 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(深蓝)

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

  • 相关阅读:
    动态规划进阶——LeetCode53. 最大子数组的和
    “VariousSwimmingCalories”app Tech Support(URL)
    C++的map用法
    Ajax fetch navigator.sendBeacon 三个的区别
    企典软件:一套系统解决85%以上企业管理难题
    基于DBC Signal Group生成Autosar SR接口(1)
    单片机之从C语言基础到专家编程 - 4 C语言基础 - 4.11函数
    学习springboot杂乱无章的笔记
    C++ 语言学习 day01 (linux ),基本输入输出错误输出函数,名字空间的含义,内联函数,缺省参数,引用 ,、new操作符
    现场直击!维视智造携多款明星产品亮相VisionChina 2022深圳机器视觉展
  • 原文地址:https://blog.csdn.net/qq_43827595/article/details/127224545
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号