当前位置:网站首页>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 .
边栏推荐
- Private method of single test calling object
- 实验一、综合实验【Process on】
- How to batch modify packaging for DXP schematic diagram
- Network security - detailed explanation of VLAN and tunk methods
- Desk lamp control panel - brightness adjustment timer
- Examen final - notes d'apprentissage PHP 6 - traitement des chaînes
- Cmake generate map file
- LabVIEW程序代码更新缓慢
- Implementation of binary search in C language
- C51 minimum system board infrared remote control LED light on and off
猜你喜欢
网络安全-路由原理
Wangbohua: development situation and challenges of photovoltaic industry
Minecraft 1.16.5 module development (50) guide book
Common sorting methods
Use of ecostruxure (3) creating composite function blocks
Multi whale capital: report on China's education intelligent hardware industry in 2022
Basic knowledge of system software development
Spring Festival inventory of Internet giants in 2022
Test enumeration types with STM32 platform running RT thread
Application of stack -- using stack to realize bracket matching (C language implementation)
随机推荐
Implementation of double linked list in C language
Implementation of binary search in C language
RT thread kernel application development message queue experiment
网络安全-三层交换技术和内部网络规划
Video player (II): video decoding
Binary tree related operations (based on recursion, implemented in C language)
Is it safe to open a stock account by mobile phone? What do I need to prepare for opening an account?
Use of ecostruxure (2) IEC61499 to establish function blocks
4diac getting started example
nRF52832 GPIO LED
Account command and account authority
LabVIEW程序代码更新缓慢
Stm32g0 Tim interrupt use
期末复习-PHP学习笔记8-mysql数据库
STM32 control LED lamp
Proteus catalog component names and Chinese English cross reference table
Global digital industry strategy and policy observation in 2021 (China Academy of ICT)
DS1302 digital tube clock
PMIC power management
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)