MaxPool1d() in PyTorch

Buy Me a Coffee☕

*Memos:

My post explains Pooling Layer.

My post explains requires_grad.

MaxPool1d() can get the 2D or 3D tensor of the one or more values computed by 1D max pooling from the 2D or 3D tensor of one or more elements as shown below…


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)

Buy Me a Coffee

*Memos:

MaxPool1d() can get the 2D or 3D tensor of the one or more values computed by 1D max pooling from the 2D or 3D tensor of one or more elements as shown below:

*Memos:

  • The 1st argument for initialization is kernel_size(Required-Type:int or tuple or list of int). *It must be 1 <= x.
  • The 2nd argument for initialization is stride(Optional-Default:kernel_size-Type:int or tuple or list of int). *It must be 1 <= x.
  • The 3rd argument for initialization is padding(Optional-Default:0-Type:int or tuple or list of int). *It must be 0 <= x.
  • The 4th argument for initialization is dilation(Optional-Default:1-Type:int or tuple or list of int). *It must be 1 <= x.
  • The 5th argument for initialization is return_indices(Optional-Default:False-Type:bool).
  • The 6th argument for initialization is ceil_mode(Optional-Default:False-Type:bool).
  • The 1st argument is input(Required-Type:tensor of float).
  • The tensor's requires_grad which is False by default is not set to True by MaxPool1d().
import torch
from torch import nn

tensor1 = torch.tensor([[8., -3., 0., 1., 5., -2.]])

tensor1.requires_grad
# False

maxpool1d = nn.MaxPool1d(kernel_size=1)
tensor2 = maxpool1d(input=tensor1)
tensor2
# tensor([[8., -3., 0., 1., 5., -2.]])

tensor2.requires_grad
# False

maxpool1d
# MaxPool1d(kernel_size=1, stride=1, padding=0, dilation=1, ceil_mode=False)

maxpool1d.kernel_size
# 1

maxpool1d.stride
# 1

maxpool1d.padding
# 0

maxpool1d.dilation
# 1

maxpool1d.return_indices
# False

maxpool1d.ceil_mode
# False

maxpool1d = nn.MaxPool1d(kernel_size=1, stride=None, padding=0, 
                         dilation=1, return_indices=False, ceil_mode=False)
maxpool1d(input=tensor1)
# tensor([[8., -3., 0., 1., 5., -2.]])

maxpool1d = nn.MaxPool1d(kernel_size=2, return_indices=True)
maxpool1d(input=tensor1)
# (tensor([[8., 1., 5.]]), tensor([[0, 3, 4]]))

maxpool1d = nn.MaxPool1d(kernel_size=3, return_indices=True)
maxpool1d(input=tensor1)
# (tensor([[8., 5.]]), tensor([[0, 4]]))

maxpool1d = nn.MaxPool1d(kernel_size=4, return_indices=True)
maxpool1d(input=tensor1)
# (tensor([[8.]]), tensor([[0]]))

maxpool1d = nn.MaxPool1d(kernel_size=5, return_indices=True)
maxpool1d(input=tensor1)
# (tensor([[8.]]), tensor([[0]]))

maxpool1d = nn.MaxPool1d(kernel_size=6, return_indices=True)
maxpool1d(input=tensor1)
# (tensor([[8.]]), tensor([[0]]))

my_tensor = torch.tensor([[8., -3., 0.],
                          [1., 5., -2.]])
maxpool1d = nn.MaxPool1d(kernel_size=1, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[8., -3., 0.],
#          [1., 5., -2.]]),
#  tensor([[0, 1, 2],
#          [0, 1, 2]]))

maxpool1d = nn.MaxPool1d(kernel_size=2, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[8.],
#          [5.]]),
#  tensor([[0],
#          [1]]))

maxpool1d = nn.MaxPool1d(kernel_size=3, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[8.],
#          [5.]]),
#  tensor([[0],
#          [1]]))

my_tensor = torch.tensor([[8.], [-3.], [0.], [1.], [5.], [-2.]])

maxpool1d = nn.MaxPool1d(kernel_size=1, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[8.], [-3.], [0.], [1.], [5.], [-2.]]),
#  tensor([[0], [0], [0], [0], [0], [0]]))

maxpool1d = nn.MaxPool1d(kernel_size=1, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[8.], [-3.], [0.], [1.], [5.], [-2.]]),
#  tensor([[0], [0], [0], [0], [0], [0]]))

my_tensor = torch.tensor([[[8.], [-3.], [0.]],
                          [[1.], [5.], [-2.]]])
maxpool1d = nn.MaxPool1d(kernel_size=1, return_indices=True)
maxpool1d(input=my_tensor)
# (tensor([[[8.], [-3.], [0.]],
#          [[1.], [5.], [-2.]]]),
#  tensor([[[0], [0], [0]],
#          [[0], [0], [0]]]))


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)


Print Share Comment Cite Upload Translate Updates
APA

Super Kai (Kazuya Ito) | Sciencx (2024-09-14T12:43:00+00:00) MaxPool1d() in PyTorch. Retrieved from https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/

MLA
" » MaxPool1d() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Saturday September 14, 2024, https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/
HARVARD
Super Kai (Kazuya Ito) | Sciencx Saturday September 14, 2024 » MaxPool1d() in PyTorch., viewed ,<https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/>
VANCOUVER
Super Kai (Kazuya Ito) | Sciencx - » MaxPool1d() in PyTorch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/
CHICAGO
" » MaxPool1d() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Accessed . https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/
IEEE
" » MaxPool1d() in PyTorch." Super Kai (Kazuya Ito) | Sciencx [Online]. Available: https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/. [Accessed: ]
rf:citation
» MaxPool1d() in PyTorch | Super Kai (Kazuya Ito) | Sciencx | https://www.scien.cx/2024/09/14/maxpool1d-in-pytorch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.