当前位置:网站首页>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
边栏推荐
- 一文读懂当前常用的加密技术体系(对称、非对称、信息摘要、数字签名、数字证书、公钥体系)
- Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
- Development environment EAS login license modification
- 图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
- Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
- 线性代数第三章-矩阵的初等变换与线性方程组
- You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
- 创建线程的三种方式
- 框架解析2.源码-登录认证
- What is JSON? First acquaintance with JSON
猜你喜欢
JVM series (3) -- memory allocation and recycling strategy
Pytoch learning record (x): data preprocessing + batch normalization (BN)
线性代数第三章-矩阵的初等变换与线性方程组
Pytorch学习记录(十二):学习率衰减+正则化
Pytorch learning record (7): skills in processing data and training models
SQL注入
PyEMD安装及简单使用
JVM系列(3)——内存分配与回收策略
lambda表达式
多线程与高并发(1)——线程的基本知识(实现,常用方法,状态)
随机推荐
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
Pytorch Learning record (XIII): Recurrent Neural Network
Split and merge multiple one-dimensional arrays into two-dimensional arrays
Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
C3P0数据库连接池使用
What is JSON? First acquaintance with JSON
异常的处理:抓抛模型
JDBC工具类封装
EditorConfig
container
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
Filebrowser realizes private network disk
MySQL transaction
建表到页面完整实例演示—联表查询
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
Multithreading and high concurrency (3) -- synchronized principle
Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型
Practical operation - Nacos installation and configuration