ResNetV2的网络深度有18,34,50,101,152。50层以下的网络基础块是BasicBlock,50层及以上的网络基础块是BottleNeck。

BasicBlock

图示如下

代码实现

 1 class BasicBlock(nn.Module):
2 expansion = 1
3 def __init__(self, in_channel, out_channel, stride=1, downsample=None):
4 super(BasicBlock, self).__init__()
5 self.conv1 = conv3x3(in_channel, out_channel, stride)
6 self.bn1 = nn.BatchNorm2d(out_channel)
7 self.relu = nn.ReLU(inplace=True)
8 self.conv2 = conv3x3(out_channel, out_channel)
9 self.bn2 = nn.BatchNorm2d(out_channel)
10 self.downsample = downsample
11 self.stride =stride
12
13 def forward(self, x):
14 residual = x
15 out = self.conv1(x)
16 out = self.bn1(out)
17 out = self.relu(out)
18 out = self.conv2(out)
19 out = self.bn2(out)
20 if self.downsample is not None:
21 residual = self.downsample(x)
22
23 out = out + residual
24 out = self.relu(out)
25
26 return out

BottleNeck

图示如下

代码实现:

 1 class Bottleneck(nn.Module):
2
3 expansion = 4
4
5 def __init__(self, in_channel, out_channel, stride=1, downsample=None):
6 super(Bottleneck, self).__init__()
7
8 self.conv1 = nn.Conv2d(in_channel, out_channel, kernel_size=1, stride=stride, bias=False)
9 self.bn1 = nn.BatchNorm2d(out_channel)
10
11 self.conv2 = nn.Conv2d(out_channel, out_channel, kernel_size=3, stride=1, padding=1, bias=False) # stride = 3
12 self.bn2 = nn.BatchNorm2d(out_channel)
13
14 self.conv3 = nn.Conv2d(out_channel, out_channel * 4, kernel_size=1, bias=False)
15 self.bn3 = nn.BatchNorm2d(out_channel * 4)
16
17 self.relu = nn.ReLU(inplace=True)
18 self.stride = stride
19 self.downsample =downsample
20
21
22 def forward(self, x):
23 residual = x
24
25 out = self.conv1(x)
26 out = self.bn1(out)
27 out = self.relu(out)
28
29 out = self.conv2(out)
30 out = self.bn2(out)
31 out = self.relu(out)
32
33 out = self.conv3(out)
34 out = self.bn3(out)
35
36 if self.downsample is not None:
37 residual = self.downsample(x)
38
39 out = out + residual
40 out = self.relu(out)
41
42 return out

Resnet网络--BasicBlock与BottleNeck的更多相关文章

  1. 深度学习之ResNet网络

    介绍 Resnet分类网络是当前应用最为广泛的CNN特征提取网络. 我们的一般印象当中,深度学习愈是深(复杂,参数多)愈是有着更强的表达能力.凭着这一基本准则CNN分类网络自Alexnet的7层发展到 ...

  2. PyTorch对ResNet网络的实现解析

    PyTorch对ResNet网络的实现解析 1.首先导入需要使用的包 import torch.nn as nn import torch.utils.model_zoo as model_zoo # ...

  3. Resnet网络详细结构(针对Cifar10)

    Resnet网络详细结构(针对Cifar10) 结构 具体结构(Pytorch) conv1 (conv1): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, ...

  4. 学习笔记-ResNet网络

    ResNet网络 ResNet原理和实现 总结 一.ResNet原理和实现 神经网络第一次出现在1998年,当时用5层的全连接网络LetNet实现了手写数字识别,现在这个模型已经是神经网络界的“hel ...

  5. ResNet网络再剖析

    随着2018年秋季的到来,提前批和内推大军已经开始了,自己也成功得当了几次炮灰,不过在总结的过程中,越是了解到自己的不足,还是需要加油. 最近重新复习了resnet网络,又能发现一些新的理念,感觉很f ...

  6. 0609-搭建ResNet网络

    0609-搭建ResNet网络 目录 一.ResNet 网络概述 二.利用 torch 实现 ResNet34 网络 三.torchvision 中的 resnet34网络调用 四.第六章总结 pyt ...

  7. ResNet网络的训练和预测

    ResNet网络的训练和预测 简介 Introduction 图像分类与CNN 图像分类 是指将图像信息中所反映的不同特征,把不同类别的目标区分开来的图像处理方法,是计算机视觉中其他任务,比如目标检测 ...

  8. ResNet网络的Pytorch实现

    1.文章原文地址 Deep Residual Learning for  Image Recognition 2.文章摘要 神经网络的层次越深越难训练.我们提出了一个残差学习框架来简化网络的训练,这些 ...

  9. 深度残差网络(DRN)ResNet网络原理

    一说起“深度学习”,自然就联想到它非常显著的特点“深.深.深”(重要的事说三遍),通过很深层次的网络实现准确率非常高的图像识别.语音识别等能力.因此,我们自然很容易就想到:深的网络一般会比浅的网络效果 ...

  10. 深度残差网络——ResNet学习笔记

    深度残差网络—ResNet总结 写于:2019.03.15—大连理工大学 论文名称:Deep Residual Learning for Image Recognition 作者:微软亚洲研究院的何凯 ...

随机推荐

  1. pytorch的inverse算子转onnx失败

    https://github.com/microsoft/onnxruntime-extensions/blob/main/tutorials/pytorch_custom_ops_tutorial. ...

  2. 【Monkey】Monkey命令与使用

    Monkey 通过Monkey程序模拟用户触摸屏幕.滑动Trackball. 按键等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常,Monkey 主要用于Android 的压力测试  ...

  3. go-浅学设计模式随记

    责任链模式 组成:由多个处理器及处理器处理标志串联组成 作用:常用于处理流水线事务,利用多个处理器对同一个对象进行处理,可以利用各处理器开关 场景:常见逻辑层处理逻辑:获取参数.fetch数据.逻辑处 ...

  4. maven 通用pom.xml

    1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http:// ...

  5. fiddler设置自动响应

    使用fiddler 设置AutoResponder 1.auto responder:自动响应器,设置并开启后将把请求接口拦截并返回 2.enable rules:开启规则,开启后规则启用 3.unm ...

  6. 常用的Linux命令与它们的功能

    概要 filename 文件名 dir 文件夹名 string 字符串 username 用户名 groupname 组名 regex 正则表达式 path 路径 partition 分区名 port ...

  7. C#textbox更改字体颜色只读后不起作用的解决办法

    textbox的属性ReadOnly设置为true只读后,只更改字体颜色并不起作用. 解决办法是,连同背景色一起设置即可. textBox1.BackColor =textBox1.BackColor ...

  8. 整合jUnit4和jUnit5

    整合jUnit4 1.引入依赖 <dependency> <groupId>org.springframework</groupId> <artifactId ...

  9. Collections.synchronizedList使用方法

    ArrayList众所周知ArrayList是非线程安全的,在多线程的情况下,向list插入数据的时候,可能会造成数据丢失的情况.并且一个线程在遍历List,另一个线程修改List,会报Concurr ...

  10. 语言-页面-模板-thymeleaf

    一.语法 二.使用 Thymeleaf入门到吃灰 - 鞋破露脚尖儿 - 博客园 (cnblogs.com)