nn.AdaptiveAvgPool1d()

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nn.AdaptiveAvgPool1d is a PyTorch module that performs adaptive average pooling over a 1D input signal. Adaptive average pooling is a form of pooling operation that allows the output size to be specified, rather than a fixed size. This means that the module will dynamically adapt the pooling window size and stride to ensure that the output has the desired size. The input to the module is expected to be a 3D tensor of shape (batch_size, num_channels, input_length), where input_length is the length of the input signal. The module takes a single argument, output_size, which specifies the desired output size as a tuple (output_length,). The output of the module is a 3D tensor of shape (batch_size, num_channels, output_length), where output_length is the specified output size. The adaptive average pooling operation is performed by dividing the input signal into non-overlapping windows of size (input_length / output_length) and computing the average value over each window. The resulting values are then concatenated along the channel dimension to produce the output tensor. Example usage: ``` import torch.nn as nn # Create a 1D input tensor of shape (batch_size, num_channels, input_length) input_tensor = torch.randn(32, 64, 128) # Create an instance of the AdaptiveAvgPool1d module with output size of 10 adaptive_avgpool = nn.AdaptiveAvgPool1d(output_size=(10,)) # Pass the input tensor through the module to obtain the output tensor output_tensor = adaptive_avgpool(input_tensor) # Print the shape of the output tensor print(output_tensor.shape) # Output: torch.Size([32, 64, 10]) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值