当前位置:网站首页>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 .
边栏推荐
- Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
- [FTP] the solution to "227 entering passive mode" during FTP connection
- All in all, the low code still needs to solve these four problems
- STM32扩展版 按键扫描
- Cmake selecting compilers and setting compiler options
- pytorch 卷积操作
- JS to solve the problem of floating point multiplication precision loss
- Leecode records the number of good segmentation of 1525 strings
- 神经网络-使用Sequential搭建神经网络
- Basic exercise of test questions hexadecimal to decimal
猜你喜欢
数据加载及预处理
2022年聚合工艺考试题及模拟考试
[pat (basic level) practice] - [simple simulation] 1064 friends
2022年T电梯修理题库及模拟考试
The index is invalid
先有网络模型的使用及修改
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
Ten wastes of software research and development: the other side of research and development efficiency
C read / write application configuration file app exe. Config and display it on the interface
随机推荐
Dual contractual learning: text classification via label aware data augmentation reading notes
JS rotation chart
常用的Transforms中的方法
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
分布式-总结列表
STM32扩展版 按键扫描
分布式架构系统拆分原则、需求、微服务拆分步骤
2022年聚合工艺考试题及模拟考试
测量三相永磁同步电机的交轴直轴电感
Pytorch(二) —— 激活函数、损失函数及其梯度
All in all, the low code still needs to solve these four problems
CF1638E. Colorful operations Kodori tree + differential tree array
Day 52 - tree problem
pytorch神经网络搭建 模板
分布式锁的实现
2022 polymerization process test questions and simulation test
How to view the changes and opportunities in the construction of smart cities?
解决qiankun中子应用外链文件无法获取
LeetCode_ 58 (length of last word)
Cmake selecting compilers and setting compiler options