当前位置:网站首页>Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
2022-04-23 05:58:00 【umbrellalalalala】
Bloggers are learning 《 Deep learning framework PyTorch: Introduction and practice 》, Record a simple example , To deepen the torch Understanding of forward propagation parameters .
This is an example of defining a network in Chapter 2 of the book , Looking directly at the code may not be intuitive , especially x = x.view(x.size()[0], -1)
This sentence , Beginners want to feel size The change of , as well as fc1
Medium 16 ∗ 5 ∗ 5 16*5*5 16∗5∗5 The source of the :
import torch.nn as nn
import torch.nn.functional as F # Activation and pooling are here
class Net(nn.Module):
def __init__(self):
# nn.Module The function of the subclass must execute the constructor of the parent class in the constructor
super().__init__()
self.conv1 = nn.Conv2d(1, 6, 5) # Input channel 1, Output channel 6, Convolution kernel 5*5, The same below
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16*5*5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
x = F.max_pool2d(F.relu(self.conv2(x)), 2)
x = x.view(x.size()[0], -1)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
net = Net()
print(net)
For bloggers jupyter The output of each layer is recorded size:
# The size of the input picture is 32*32,channel by 1. namely batch*channel*height*width
input = Variable(t.randn(1, 1, 32, 32))
out = net(input)
# Run layer by layer and output the data of each layer size
out1 = net.conv1(input)
pool1 = F.max_pool2d(out1, 2)
out2 = net.conv2(pool1)
pool2 = F.max_pool2d(out2, 2)
stretch = pool2.view(pool2.size()[0], -1)
out3 = net.fc1(strech)
out4 = net.fc2(out3)
out5 = net.fc3(out4)
print('output of conv1:', out1.shape)
print('output of pool1:', pool1.shape)
print('output of conv2:', out2.shape)
print('output of pool2:', pool2.shape)
print('output of stretch:', stretch.shape)
print('output of fc1:', out3.shape)
print('output of fc2:', out4.shape)
print('output of fc3:', out5.shape)
Running results :
output of conv1: torch.Size([1, 6, 28, 28])
output of pool1: torch.Size([1, 6, 14, 14])
output of conv2: torch.Size([1, 16, 10, 10])
output of pool2: torch.Size([1, 16, 5, 5])
output of strech: torch.Size([1, 400])
output of fc1: torch.Size([1, 120])
output of fc2: torch.Size([1, 84])
output of fc3: torch.Size([1, 10])
This is very intuitive ! among x = x.view(x.size()[0], -1)
Yes, it will [1, 16, 5, 5]
Turned into [1, 400]
版权声明
本文为[umbrellalalalala]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230543474540.html
边栏推荐
- Package mall system based on SSM
- Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
- Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
- Write your own redistemplate
- The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
- RedHat6之smb服务访问速度慢解决办法记录
- 2.devops-sonar安装
- 金蝶EAS“总账”系统召唤“反过账”按钮
- JDBC工具类封装
- 深度学习基础——简单了解meta learning(来自李宏毅课程笔记)
猜你喜欢
PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
容器
Multithreading and high concurrency (1) -- basic knowledge of threads (implementation, common methods, state)
Pytorch——数据加载和处理
CONDA virtual environment management (create, delete, clone, rename, export and import)
filebrowser实现私有网盘
基于thymeleaf实现数据库图片展示到浏览器表格
PyQy5学习(四):QAbstractButton+QRadioButton+QCheckBox
MySQL realizes master-slave replication / master-slave synchronization
去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
随机推荐
治疗TensorFlow后遗症——简单例子记录torch.utils.data.dataset.Dataset重写时的图片维度问题
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
K/3 WISE系统考勤客户端日期只能选到2019年问题
容器
Write your own redistemplate
Pytorch学习记录(七):处理数据和训练模型的技巧
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset
软件架构设计——软件架构风格
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
Pyemd installation and simple use
Viewer: introduce MySQL date function
Manually delete registered services on Eureka
图解HashCode存在的意义
Pytorch learning record (IX): convolutional neural network in pytorch
EditorConfig
数字图像处理基础(冈萨雷斯)一
SQL注入
Anaconda
The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect