Resnet网络--BasicBlock与BottleNeck
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的更多相关文章
- 深度学习之ResNet网络
介绍 Resnet分类网络是当前应用最为广泛的CNN特征提取网络. 我们的一般印象当中,深度学习愈是深(复杂,参数多)愈是有着更强的表达能力.凭着这一基本准则CNN分类网络自Alexnet的7层发展到 ...
- PyTorch对ResNet网络的实现解析
PyTorch对ResNet网络的实现解析 1.首先导入需要使用的包 import torch.nn as nn import torch.utils.model_zoo as model_zoo # ...
- Resnet网络详细结构(针对Cifar10)
Resnet网络详细结构(针对Cifar10) 结构 具体结构(Pytorch) conv1 (conv1): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, ...
- 学习笔记-ResNet网络
ResNet网络 ResNet原理和实现 总结 一.ResNet原理和实现 神经网络第一次出现在1998年,当时用5层的全连接网络LetNet实现了手写数字识别,现在这个模型已经是神经网络界的“hel ...
- ResNet网络再剖析
随着2018年秋季的到来,提前批和内推大军已经开始了,自己也成功得当了几次炮灰,不过在总结的过程中,越是了解到自己的不足,还是需要加油. 最近重新复习了resnet网络,又能发现一些新的理念,感觉很f ...
- 0609-搭建ResNet网络
0609-搭建ResNet网络 目录 一.ResNet 网络概述 二.利用 torch 实现 ResNet34 网络 三.torchvision 中的 resnet34网络调用 四.第六章总结 pyt ...
- ResNet网络的训练和预测
ResNet网络的训练和预测 简介 Introduction 图像分类与CNN 图像分类 是指将图像信息中所反映的不同特征,把不同类别的目标区分开来的图像处理方法,是计算机视觉中其他任务,比如目标检测 ...
- ResNet网络的Pytorch实现
1.文章原文地址 Deep Residual Learning for Image Recognition 2.文章摘要 神经网络的层次越深越难训练.我们提出了一个残差学习框架来简化网络的训练,这些 ...
- 深度残差网络(DRN)ResNet网络原理
一说起“深度学习”,自然就联想到它非常显著的特点“深.深.深”(重要的事说三遍),通过很深层次的网络实现准确率非常高的图像识别.语音识别等能力.因此,我们自然很容易就想到:深的网络一般会比浅的网络效果 ...
- 深度残差网络——ResNet学习笔记
深度残差网络—ResNet总结 写于:2019.03.15—大连理工大学 论文名称:Deep Residual Learning for Image Recognition 作者:微软亚洲研究院的何凯 ...
随机推荐
- go标准库之fmt
go标准库之fmt fmt库 Print系列 1. Print 不换行 2. Println 换行 3. Printf 不换行,可以使用格式化占位符 格式化占位符 占位符 说明 通用 --- %v 值 ...
- ubuntu20.04系统openjdk11变更openjdk-8-jdk
ubuntu20.04系统openjdk11变更openjdk-8-jdk一.卸载openjdk11先检查是否安装,命令:dpkg --list | grep -i jdk移除openjdk包,命令: ...
- Docker-Compose实战<下篇>
本文是在上一篇文章的基础上做的一些内容追加,上文最后截止内容是docker-compose build将镜像生成完成.接下来我将继续写启动相关服务,访问服务以及常用命令使用等. 1 启动镜像 使用命令 ...
- WDA学习(18):UI Element:TabStrip使用
1.11 UI Element:Tabstrip使用 本实例显示UI Element:Tabstrip的使用. 1.创建Component; 2.选择Layout页签,设置页面: 创建UI Eleme ...
- ARC(Automatic Reference Counting)自动引用计数 unowned、weak 使用区别
自动引用计数 引用类型(类.函数.闭包) 当声明一个变量指向某个引用类型时 当前引用类型的引用计数就会加1 当变量不指向该类型时 引用类型就会 -1 当引用计数为0时 当前引用类型就会被系统回收 i ...
- iOS开发之运行报错 dyld: Library not loaded: *** Reason: image not found
xcode运行报错 dyld: Library not loaded: @rpath/Flutter.framework/Flutter Referenced from: /private/var ...
- Linux基础第六章:逻辑卷的使用、扩容和磁盘配额
一.逻辑卷的使用及扩容 1.概念优点及注意事项 2.使用命令及基本格式 3.创建逻辑卷 ①创建物理卷 ②创建卷组 ③创建逻辑卷 ④格式化.挂载yk26逻辑卷在/mnt下并在逻辑卷yk26下创建文件a. ...
- 运用TextSuite和TestRunner运行测试脚本
运用TextSuite和TestRunner运行测试脚本 import app.testcase.loginUI import unittest # mysuite = unittest.TestSu ...
- 用Flask+Element+Vue搭建md5、sha加密网站
目录 一.绘制网站页面 1.1 绘制输入框 1.2 绘制表单 二.flask后端接口 三.前后端数据交互 在本章中,我们能学到: 1.Element 中的输入框.按钮.消息提示组件的使用 2.axio ...
- kubectl工具安装指南
kubectl是一个用于连接Service Mesh控制平面的工具,可以安装在办公电脑的Windows系统上,也可以安装在虚拟机的Linux系统上,只要网络能与控制平面的公网地址互通即可.下面分别介绍 ...