当前位置:网站首页>Neural networks - use of maximum pooling
Neural networks - use of maximum pooling
2022-07-01 04:45:00 【booze-J】
article
Official documentation of the pooling layer Many pooling methods are introduced in , But the most common one is MaxPool2d, Here we also use MaxPool2d To explain , Other similar , The key is to learn to watch Official documents
summary :
The purpose of maximum pooling is to Keep the input characteristics , But at the same time, reduce the amount of data , After maximum pooling, the amount of data is reduced , For the whole network , There are fewer parameters to calculate , Will train faster .
It is equivalent to watching videos on the Internet , Video again 1080P Of ,720P Of ,360P Of , You know what ,1080P It is equivalent to inputting video ,720P Is equivalent to the video after maximum pooling ,720P It can also meet the needs , When the net doesn't work, you can watch it 720P Yeah .
What is maximum pooling ?
The maximum pool operation is equivalent to the core moving on the image , Filter out the maximum value of the area covered by the core , Be careful The moving step of the kernel is kernel_size.
Speaking of MaxPool2d The interface is used here , The key is to learn how to communicate .
torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)
Parameter description
- kernel_size – the size of the window to take a max over
- stride – the stride of the window. Default value is kernel_size
- padding – implicit zero padding to be added on both sides
- dilation – a parameter that controls the stride of elements in the window
- return_indices – if True, will return the max indices along with the outputs. Useful for torch.nn.MaxUnpool2d later
- ceil_mode – when True, will use ceil instead of floor to compute the output shape
Pick out some common ones and tell you :
- kernel_size When you pass in a constant , A size of kernel_size X kernel_size The size of the nuclear ,kernel_size When a tuple is passed in , Then a core with specified height and width will be generated .
- Speaking of Ceil_model Parameters , In some cases , The core cannot be completely covered on the image , Only part of the image is covered , The other part has gone outside the image ,Ceil_model It was decided at this time , Do you want to perform a maximum pool operation on the block that only covers the part , Take the maximum , if Ceil_model by True, Then the maximum pool operation is performed , Take the maximum , Otherwise, the maximum pool operation will not be performed , Do not take the maximum value . You can see the figure below Ceil_model Parameters :
The process :
result :
MaxPool2d The sample code used is as follows :
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("CIFAR10",train=False,transform=torchvision.transforms.ToTensor(),download=True)
# Be careful dataset in transform The parameter receives an object , So we need to add parentheses , In addition, when using neural network for operation, the data type required is tensor type , therefore transforms Parameters to add .
dataloader = DataLoader(dataset,batch_size=64)
# Building neural networks
class Booze(nn.Module):
# Inherit nn.Module The initialization
def __init__(self):
super(Booze, self).__init__()
self.maxpool1 = MaxPool2d(kernel_size=3,ceil_mode=True)
# rewrite forward function
def forward(self,x):
output = self.maxpool1(x)
return output
obj = Booze()
# Use tensorboard Visualization process
writer = SummaryWriter("logs")
step = 0
for data in dataloader:
imgs,targets = data
writer.add_images("input",imgs,step)
output = obj(imgs)
writer.add_images("output",output,step)
step+=1
writer.close()
The above code is finished , stay pycharm Below terminal Window type tensorboard --logdir=logs Enter to check :
The effect is as follows :

It can be seen from the results above , After the maximum pool processing, the part is obviously more blurred than the original image , But when compared with the original image, at least the original features can be seen .
边栏推荐
- 最长递增子序列及最优解、动物总重量问题
- Cmake selecting compilers and setting compiler options
- 2022 t elevator repair new version test questions and t elevator repair simulation test question bank
- Day 52 - tree problem
- js解决浮点数相乘精度丢失问题
- Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
- Research on medical knowledge atlas question answering system (I)
- pytorch 卷积操作
- Introduction to JVM stack and heap
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
猜你喜欢

分布式架构系统拆分原则、需求、微服务拆分步骤
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

Difficulties in the development of knowledge map & the importance of building industry knowledge map

Introduction to JVM stack and heap

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

MySQL winter vacation self-study 2022 12 (5)

The index is invalid

Cmake selecting compilers and setting compiler options

Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions

VR线上展览所具备应用及特色
随机推荐
OdeInt与GPU
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
Odeint and GPU
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
All in all, the low code still needs to solve these four problems
常用的Transforms中的方法
Take a cold bath
Codeforces Round #771 (Div. 2) ABCD|E
Some tools that research dogs may need
Common methods in transforms
JS to solve the problem of floating point multiplication precision loss
LeetCode_ 58 (length of last word)
2022年T电梯修理题库及模拟考试
Pytorch(二) —— 激活函数、损失函数及其梯度
Introduction to JVM stack and heap
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
总结全了,低代码还需要解决这4点问题
Shell analysis server log command collection
[godot] unity's animator is different from Godot's animplayer
2022 t elevator repair new version test questions and t elevator repair simulation test question bank