Upsampling:上采样,被nn.functional.interpolate代替
nn.Upsampling is deprecated. Use nn.functional.interpolate instead.
#-*-coding:utf-8-*-
import torch
import torch.nn as nn
import numpy as np
# pool of non-square window
## In the simplest case, the output value of the layer
# with input size (N,C,H,W)(N, C, H, W)(N,C,H,W),
# output (N,C,Hout,Wout)(N, C, H_{out}, W_{out})(N,C,Hout,Wout) and kernel_size (kH,kW)(kH, kW)(kH,kW) can be precisely described as:
data = np.arange(64).reshape((8,8))
A = torch.Tensor(data.reshape(1,1,8,8))
print('A=',A)
## MAX POOL
maxpool = nn.MaxPool2d((2, 2), stride=(2, 2),return_indices=True)
B,indices = maxpool(A)
print('B=',B)
## Upsample
Upsample = nn.Upsample(scale_factor=2, mode='bilinear')
C = Upsample(B)
print('C=',C)
D = nn.functional.interpolate(B,scale_factor=2, mode='bilinear')
print('D=',D)
### max unpool
maxunpool = nn.MaxUnpool2d(kernel_size=(2,2),stride=(2,2))
E = maxunpool(B,indices)
print('E=',E)