pytorch: MaxUnpool2d 与 Upsampling

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)

 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值