当前位置:网站首页>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 .
边栏推荐
- C read / write application configuration file app exe. Config and display it on the interface
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Pytorch(三) —— 函数优化
- LeetCode_ 53 (maximum subarray and)
- 2022危险化学品生产单位安全生产管理人员题库及答案
- 2022 polymerization process test questions and simulation test
- Common methods in transforms
- Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
- OdeInt與GPU
- Dataloader的使用
猜你喜欢

2022年上海市安全员C证考试题模拟考试题库及答案

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022

Technology sharing | broadcast function design in integrated dispatching

STM32扩展版 按键扫描

神经网络的基本骨架-nn.Moudle的使用

OdeInt与GPU

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

2022年聚合工艺考试题及模拟考试

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

The index is invalid
随机推荐
Common methods in transforms
Pytorch(二) —— 激活函数、损失函数及其梯度
2022危险化学品生产单位安全生产管理人员题库及答案
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
Pytorch(四) —— 可视化工具 Visdom
STM32 extended key scan
2022年化工自动化控制仪表操作证考试题库及答案
pytorch神经网络搭建 模板
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Cmake selecting compilers and setting compiler options
如何看待智慧城市建设中的改变和机遇?
Extension fragment
Dede collection plug-in does not need to write rules
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
pytorch中常用数据集的使用方法
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
The longest increasing subsequence and its optimal solution, total animal weight problem
C -- array