我正在https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html学习文档。
在“参数”部分中,它声明
return_indices -如果是真的话,将返回最大索引和输出。以后对torch.nn.MaxUnpool2d有用
有人能解释一下最大指数是什么意思吗?我相信它是与最大值相对应的指标。如果最大值是唯一的,这是否意味着只返回一个索引?
发布于 2022-02-07 21:26:31
我猜你已经知道max池是怎么工作的了。然后,让我们打印一些结果,以获得更多的见解。
import torch
import torch.nn as nn
pool = nn.MaxPool2d(kernel_size=2, return_indices=True)
input = torch.zeros(1, 1, 4, 4)
input[..., 0, 1] = input[..., 1, 3] = input[..., 2, 2] = input[..., 3, 0] = 1.
print(input)输出
tensor([[[[0., 1., 0., 0.],
[0., 0., 0., 1.],
[0., 0., 1., 0.],
[1., 0., 0., 0.]]]])output, indices = pool(input)
print(output)输出
tensor([[[[1., 1.],
[1., 1.]]]])print(indices)输出
tensor([[[[ 1, 7],
[12, 10]]]])如果您stretch输入张量并使其为1d,您可以看到indices包含每个1值的位置(MaxPool2d的每个窗口的最大值)。正如torch.nn.MaxPool2d文档中所写的,torch.nn.MaxUnpool2d 模块需要使用indices。
MaxUnpool2d以MaxPool2d的输出作为输入,包括最大值的索引,并计算一个部分逆,其中所有非最大值都设置为零。
https://stackoverflow.com/questions/71025321
复制相似问题