当前位置:网站首页>Introduction notes to pytorch deep learning (11) neural network pooling layer
Introduction notes to pytorch deep learning (11) neural network pooling layer
2022-06-30 07:35:00 【Snow fish】
Course notes , Course link
The learning notes are synchronously posted on my Personal website On , Welcome to check .
List of articles
One 、MaxPool2d brief introduction
This section explains the pooling layer . Or through Pytorch Official documents for learning :
open torch.nn Of pooling layers, The most common functions are nn.MaxPool2d, The parameters to be provided are as follows :
kernel_size
Is the size of the window , It can beint
ortuple
data typedilation
: Change the window spacing . As shown in the figure below , Blue is the input , Grey is the window , You can see that the window is 3*3 size , And the interval is dilation by 1. Generally, no setting is required .cell_mode:
: When cell_mode by True when , Will usecell
Pattern instead offloor
Mode to calculate output . A simple explanationcell
Patterns andfloor
Pattern :
Floor The pattern is to round the value down , Such as 2.31 The value is 2 , and Cell The pattern is to round up the value , Such as 2.31 The value is 3. In the maximum pooling operation , When it comes to cell Mode time , If the window and input do not completely coincide , A calculation will also be made ; by floor Mode will discard this calculation .
Maximum pooling is to get the largest number in the window , example :
Two 、 Code demonstration
import torch
from torch import nn
from torch.nn import MaxPool2d
input = torch.tensor([[1, 2, 0, 3, 1],
[0, 1, 2, 3, 1],
[1, 2, 1, 0, 0],
[5, 2, 3, 1, 1],
[2, 1, 0, 1, 1]], dtype=torch.float32)
# N C H W
input = torch.reshape(input, (-1, 1, 5, 5))
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.maxpool1 = MaxPool2d(kernel_size=3, ceil_mode=True)
def forward(self, input):
output = self.maxpool1(input)
return output
net1 = Net()
output = net1(input)
print(output)
Output results :
It is consistent with the previous calculation .
The function of maximum pooling is to reduce the amount of data on the premise of saving data characteristics .
Let's do another example :
Example :
import torch
import torchvision
from torch import nn
from torch.nn import MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10("./dataset", train=False, download=True,
transform=torchvision.transforms.ToTensor())
dataloader = DataLoader(dataset, batch_size=64)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.maxpool1 = MaxPool2d(kernel_size=3, ceil_mode=True)
def forward(self, input):
output = self.maxpool1(input)
return output
net1 = Net()
writer = SummaryWriter("logs")
step = 0
for data in dataloader:
imgs, targets = data
writer.add_images("input", imgs, step)
output = net1(imgs)
writer.add_images("output", output, step)
step = step + 1
writer.close()
use tensorboard View results :
It can be seen that the direct effect of the maximum pool operation is to reduce the pixels of the picture , That's blurred , Only the most prominent features of the original image are retained .
边栏推荐
- PMIC power management
- 线程池——C语言
- Detailed methods for copying local computer files to virtual machine system
- Virtual machine VMware: due to vcruntime140 not found_ 1.dll, unable to continue code execution
- Final review -php learning notes 9-php session control
- Projection point of point on line
- 期末复习-PHP学习笔记9-PHP会话控制
- 24C02
- Shell command, how much do you know?
- STM32 register on LED
猜你喜欢
Next initializesecuritycontext failed: unknown error (0x80092012) - the revocation function cannot check whether the certificate is revoked.
Raspberry pie 4B Getting Started Guide
Wangbohua: development situation and challenges of photovoltaic industry
Test enumeration types with STM32 platform running RT thread
Video player (I): process
Network security and data in 2021: collection of new compliance review articles (215 pages)
Periodic planning work
2021 private equity fund market report (62 pages)
记录开发过程中无法使用管理员身份修改系统文件问题
Disk space, logical volume
随机推荐
C language implementation of chain stack (without leading node)
02 - bare metal and RTOS development modes: five development modes of bare metal and the introduction of RTOS
01 - embedded learning route and career planning: embedded basic knowledge and development process
期末复习-PHP学习笔记8-mysql数据库
Periodic planning work
ADC basic concepts
uniapp图片下方加标签标图片
期末复习-PHP学习笔记9-PHP会话控制
Digital tube EEPROM key to save value
Mailbox application routine of running wild fire RT thread
Shell command, how much do you know?
03 - programming framework: Division of application layer, middle layer and driver layer in bare metal programming
Network security and data in 2021: collection of new compliance review articles (215 pages)
Tencent and Fudan University "2021-2022 yuan universe report" with 102 yuan universe collections
Graphic explanation pads update PCB design basic operation
Use of ecostruxure (3) creating composite function blocks
记录开发过程中无法使用管理员身份修改系统文件问题
Embedded test process
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
1.someip introduction