当前位置:网站首页>Unpool(nn.MaxUnpool2d)

Unpool(nn.MaxUnpool2d)

2022-07-05 02:01:00 hxxjxw

Unpooling As an up sampling method , And pooling It looks like the opposite operation , We have three ways , The first is Nearest Neighbor, Is to copy the same data 4 Four times the expansion effect , The second is ”Bed of Nails”, Keep the data in the upper left corner of the corresponding position , Then fill the rest 0, As shown in the figure below .

 

  The third way is Max Unpooling, For some network models , The structure of up sampling and down sampling is often symmetrical , We can take samples under Max Pooling Record the position of the maximum value , When sampling, restore the maximum value to its corresponding position , Then fill the rest of the positions 0, As shown in the figure below .

  In this way, the information can be restored to the greatest extent .

import torch
from torch import nn

pool = nn.MaxPool2d(2, stride=2, return_indices=True)
unpool = nn.MaxUnpool2d(2, stride=2)
input = torch.tensor([[[[ 1.,  2,  3,  4],
                        [ 5,  6,  7,  8],
                        [ 9, 10, 11, 12],
                        [13, 14, 15, 16]]]])

output, indices = pool(input)
result = unpool(output, indices)
print(result)

# It's fine too unpool The result of size and input Different 
result = unpool(output, indices, output_size=torch.Size([1, 1, 5, 5]))
print(result)

 

原网站

版权声明
本文为[hxxjxw]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141001021755.html