pytorch函数AdaptiveMaxPool2d

class torch.nn.AdaptiveMaxPool2d(output_size, return_indices=False)

对输入信号,提供2维的自适应最大池化操作 对于任何输入大小的输入,可以将输出尺寸指定为H*W,但是输入和输出特征的数目不会变化。
可以用来实现全局平均最大池化层output_size=1

参数:
output_size: 输出信号的尺寸,可以用(H,W)表示HW的输出,也可以使用数字H表示HH大小的输出
return_indices: 如果设置为True,会返回输出的索引。对 nn.MaxUnpool2d有用,默认值是False

m = torch.nn.AdaptiveMaxPool2d((5,7))
input = torch.autograd.Variable(torch.randn(1, 64, 8, 9))
# target output size of 7x7 (square)
print(m(input).shape)
m = torch.nn.AdaptiveMaxPool2d(7)
input = torch.autograd.Variable(torch.randn(1, 64, 10, 9))
output = m(input)
print(output.shape)
input = torch.autograd.Variable(torch.randn(1, 2, 3, 2))
m = torch.nn.AdaptiveAvgPool2d(1)
output = m(input)
print(input)
print(output,output.shape)

torch.Size([1, 64, 5, 7])
torch.Size([1, 64, 7, 7])
tensor([[[[ 0.1300, -0.0319],
          [-1.9817, -0.0691],
          [ 0.5286,  2.1709]],

         [[ 0.2248,  0.4539],
          [-1.0164,  1.1421],
          [-0.0045, -0.1006]]]])
tensor([[[[0.1244]],

         [[0.1165]]]]) torch.Size([1, 2, 1, 1])

  • 5
    点赞
  • 12
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

小白827

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值