*Memos:
- My post explains Pooling Layer.
- My post explains AvgPool1d().
- My post explains AvgPool3d().
- My post explains MaxPool1d().
- My post explains MaxPool2d().
- My post explains MaxPool3d().
- My post explains requires_grad.
AvgPool2d() can get the 3D or 4D tensor of the one or more elements computed by 2D average pooling from the 3D or 4D tensor of one or more elements as shown below:
*Memos:
- The 1st argument for initialization is
kernel_size
(Required-Type:int
ortuple
orlist
ofint
). *It must be1 <= x
. - The 2nd argument for initialization is
stride
(Optional-Default:None
-Type:int
ortuple
orlist
ofint
): *Memos:- It must be
1 <= x
. - If it's
None
,kernel_size
is set.
- It must be
- The 3rd argument for initialization is
padding
(Optional-Default:0
-Type:int
ortuple
orlist
ofint
). *It must be0 <= x
. - The 4th argument for initialization is
ceil_mode
(Optional-Default:False
-Type:bool
). - The 5th argument for initialization is
count_include_pad
(Optional-Default:True
-Type:bool
). - The 6th argument for initialization is
divisor_override
(Optional-Default:None
-Type:int
). - The 1st argument is
input
(Required-Type:tensor
ofint
orfloat
): *Memos:- It must be the 3D or 4D tensor of one or more elements.
- The tensor's
requires_grad
which isFalse
by default is not set toTrue
byAvgPool2d()
.
import torch
from torch import nn
tensor1 = torch.tensor([[[8., -3., 0., 1., 5., -2.]]])
tensor1.requires_grad
# False
avgpool2d = nn.AvgPool2d(kernel_size=1)
tensor2 = avgpool2d(input=tensor1)
tensor2
# tensor([[[8., -3., 0., 1., 5., -2.]]])
tensor2.requires_grad
# False
avgpool2d
# AvgPool2d(kernel_size=1, stride=1, padding=0)
avgpool2d.kernel_size
# 1
avgpool2d.stride
# 1
avgpool2d.padding
# 0
avgpool2d.ceil_mode
# False
avgpool2d.count_include_pad
# True
avgpool2d.divisor_override
# None
avgpool2d = nn.AvgPool2d(kernel_size=1, stride=None, padding=0,
ceil_mode=False, count_include_pad=True,
divisor_override=None)
avgpool2d(input=tensor1)
# tensor([[[8., -3., 0., 1., 5., -2.]]])
avgpool2d = nn.AvgPool2d(kernel_size=2, padding=1)
avgpool2d(input=tensor1)
# tensor([[[2.0000, -0.7500, 1.5000, -0.5000]]])
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1)
avgpool2d(input=tensor1)
# tensor([[[0.5556, 0.6667]]])
avgpool2d = nn.AvgPool2d(kernel_size=4, padding=2)
avgpool2d(input=tensor1)
# tensor([[[0.3125, 0.2500]]])
etc.
avgpool2d = nn.AvgPool2d(kernel_size=7, padding=3)
avgpool2d(input=tensor1)
# tensor([[[0.1224]]])
etc.
avgpool2d = nn.AvgPool2d(kernel_size=7, padding=3, divisor_override=2)
avgpool2d(input=tensor1)
# tensor([[[3.]]])
my_tensor = torch.tensor([[[8., -3., 0.],
[1., 5., -2.]]])
avgpool2d = nn.AvgPool2d(kernel_size=1)
avgpool2d(input=my_tensor)
# tensor([[[8., -3., 0.],
# [1., 5., -2.]]])
avgpool2d = nn.AvgPool2d(kernel_size=2)
avgpool2d(input=my_tensor)
# tensor([[[2.7500]]])
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1)
avgpool2d(input=my_tensor)
# tensor([[[1.2222]]])
etc.
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1, divisor_override=2)
avgpool2d(input=my_tensor)
# tensor([[[5.5000]]])
my_tensor = torch.tensor([[[8.], [-3.], [0.]],
[[1.], [5.], [-2.]]])
avgpool2d = nn.AvgPool2d(kernel_size=1)
avgpool2d(input=my_tensor)
# tensor([[[8.], [-3.], [0.]],
# [[1.], [5.], [-2.]]])
avgpool2d = nn.AvgPool2d(kernel_size=2, padding=1)
avgpool2d(input=my_tensor)
# tensor([[[2.0000], [-0.7500]],
# [[0.2500], [0.7500]]])
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1)
avgpool2d(input=my_tensor)
# tensor([[[0.5556]], [[0.6667]]])
etc.
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1, divisor_override=2)
avgpool2d(input=my_tensor)
# tensor([[[2.5000]], [[3.0000]]])
my_tensor = torch.tensor([[[[8.], [-3.], [0.]],
[[1.], [5.], [-2.]]]])
avgpool2d = nn.AvgPool2d(kernel_size=1)
avgpool2d(input=my_tensor)
# tensor([[[[8.], [-3.], [0.]],
# [[1.], [5.], [-2.]]]])
avgpool2d = nn.AvgPool2d(kernel_size=2, padding=1)
avgpool2d(input=my_tensor)
# tensor([[[[2.0000], [-0.7500]],
# [[0.2500], [0.7500]]]])
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1)
avgpool2d(input=my_tensor)
# tensor([[[[0.5556]], [[0.6667]]]])
etc.
avgpool2d = nn.AvgPool2d(kernel_size=3, padding=1, divisor_override=2)
avgpool2d(input=my_tensor)
# tensor([[[[2.5000]], [[3.0000]]]])
my_tensor = torch.tensor([[[[8], [-3], [0]],
[[1], [5], [-2]]]])
avgpool2d = nn.AvgPool2d(kernel_size=1)
avgpool2d(input=my_tensor)
# tensor([[[[8], [-3], [0]],
# [[1], [5], [-2]]]])
Top comments (0)