当前位置:网站首页>Maxpool2d explanation -- Application in arrays and images
Maxpool2d explanation -- Application in arrays and images
2022-06-30 23:16:00 【Philo`】
MaxPool2d Detailed explanation -- Applications in arrays and images
1、 Environmental requirements
1、 Need to install Pytorch rely on
2、 Official documents conv2d
3、 Picture needs CIFAR10 Data sets
2、 Principle explanation
Cover the original data with convolution kernel , Select the maximum value covered by convolution kernel in the original data

Select the maximum value of convolution kernel coverage ,ceil_mode Controls whether the convolution kernel is retained after exceeding the original data
3、 Function requirements
function :
Parameter requirements 
kernel_sizeSet convolution kernel size attributestrideand conv2d Medium stride equally , Is an attribute that controls the movement stride ,Note here ,conv2d The default value is 1, however MaxPool2d The default value is the convolution kernel sizepaddingSet the properties filled around the original datadilation:Indicates the addition of... Between the original data 0 Properties ofceil_modeControls when the convolution kernel exceeds the original image , Whether the max Make a reservation
4、 Example
4.1、 Array
Code :
import torch
import torchvision
from torch.nn import Module,MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
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)
print(" front ",input.shape) # torch.Size([5, 5]), The input conditions are not met , Format conversion required
input = torch.reshape(input,(-1,1,5,5))
print(" after ",input.shape) # after torch.Size([1, 1, 5, 5]) One bach_size,
class ConNet(Module):
def __init__(self):
super(ConNet, self).__init__()
# Use of pool layer , Set convolution kernel to 3*3, The excess part retains the data
self.maxpool = MaxPool2d(kernel_size=3,ceil_mode=True)
def forward(self,input):
output = self.maxpool(input)
return output
# Instantiate objects
Work = ConNet()
# Neural network call
output = Work(input)
print(output)
result :
4.2、 Images
Code :
import torch
import torchvision
from torch.nn import Module,MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
class ConNet(Module):
def __init__(self):
super(ConNet, self).__init__()
# Use of pool layer , Set convolution kernel to 3*3, The excess part retains the data
self.maxpool = MaxPool2d(kernel_size=3,ceil_mode=True)
def forward(self,input):
output = self.maxpool(input)
return output
# Instantiate objects
Work = ConNet()
# CIFAR10 Data usage
dataset = torchvision.datasets.CIFAR10("./datasetvision",train=False,download=False,transform=torchvision.transforms.ToTensor())
# Data loading
dataloader = DataLoader(dataset,batch_size=64)
writer = SummaryWriter("logs_MaxPool")
step = 0
for data in dataloader:
imgs,target = data
writer.add_images("input",imgs,step)
output = Work(imgs)
writer.add_images("output",output,step)
step = step + 1
writer.close()
result :

4.3、Conv2d+MaxPool2d Images
Code :
import torch
import torchvision
from torch.nn import Module,MaxPool2d,Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
class ConNet(Module):
def __init__(self):
super(ConNet, self).__init__()
# Use of pool layer , Set convolution kernel to 3*3, The excess part retains the data
self.maxpool = MaxPool2d(kernel_size=3,ceil_mode=True)
self.conv2d = Conv2d(in_channels=3,out_channels=3,kernel_size=3,stride=1,padding=0)
def forward(self,input):
output = self.conv2d(input)
output = self.maxpool(output)
return output
# Instantiate objects
Work = ConNet()
# CIFAR10 Data usage
dataset = torchvision.datasets.CIFAR10("./datasetvision",train=False,download=False,transform=torchvision.transforms.ToTensor())
# Data loading
dataloader = DataLoader(dataset,batch_size=64)
writer = SummaryWriter("logs_MaxPoolAndConv2d")
step = 0
for data in dataloader:
imgs,target = data
writer.add_images("input",imgs,step)
output = Work(imgs)
writer.add_images("output",output,step)
step = step + 1
writer.close()
result :

边栏推荐
- D compile time count
- Kubevela 1.4: make application delivery safer, easier to use, and more transparent
- [leetcode] [SQL] notes
- 1175. 質數排列 / 劍指 Offer II 104. 排列的數目
- AtCoder Beginner Contest 255
- CTFSHOW框架复现篇
- [golang] golang implements the string interception function substr
- Dataloader source code_ DataLoader
- What does the software test report contain? How to obtain high quality software test reports?
- 【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(图像分类篇)
猜你喜欢

76页智慧物流园区综合解决方案2022(附下载)

shell 同时执行多任务下载视频

【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(物体检测篇)

MIT doctoral dissertation optimization theory and machine learning practice

Fastjson V2 简单使用手册
![Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical](/img/ce/519778cd731f814ad111d1e37abd10.png)
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical

The sandbox is being deployed on the polygon network

Fastjson V2 simple user manual

远程办公期间,项目小组微信群打卡 | 社区征文

In 2022, the latest JCR officially released the list of the latest global impact factors (top 600)
随机推荐
CTFSHOW权限维持篇
Fastjson V2 simple user manual
How to ensure the security of our core drawings by drawing encryption
高等数学建模
理想中的接口自动化项目
分享十万级TPS的IM即时通讯综合消息系统的架构
唯一性索引与逻辑删除冲突问题解决思路
How cloud computing can protect online education in the post epidemic Era
"Paddle + camera" has become a "prefabricated dish" in the AI world, and it is easier to implement industrial AI quality inspection
C language array interception, C string by array interception method (c/s)
d编译时计数
Redis的事务和锁机制
shell 同时执行多任务下载视频
Warmup preheating learning rate "suggestions collection"
RIDE:获取图片base64
Redis' transaction and locking mechanism
电商秒杀系统
微信小程序通过点击事件传参(data-)
CTFSHOW框架复现篇
Reason why wechat payment wxpaypubhelper V3 callback XML is empty