class torch.nn.UpsamplingBilinear2d(size=None, scale_factor=None)的使用举例

参考链接: class torch.nn.UpsamplingBilinear2d(size=None, scale_factor=None)

在这里插入图片描述

实验举例:

(base) PS C:\Users\chenxuqi> conda activate pytorch_1.7.1_cu102
(pytorch_1.7.1_cu102) PS C:\Users\chenxuqi> python
Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x00000226C1777890>
>>> a = torch.arange(1, 5, dtype=torch.float32).view(1, 1, 2, 2)
>>> a
tensor([[[[1., 2.],
          [3., 4.]]]])
>>> model = torch.nn.UpsamplingBilinear2d(scale_factor=2)
>>> b = model(a)
>>> b.shape
torch.Size([1, 1, 4, 4])
>>> a.shape
torch.Size([1, 1, 2, 2])
>>> a
tensor([[[[1., 2.],
          [3., 4.]]]])
>>> b
tensor([[[[1.0000, 1.3333, 1.6667, 2.0000],
          [1.6667, 2.0000, 2.3333, 2.6667],
          [2.3333, 2.6667, 3.0000, 3.3333],
          [3.0000, 3.3333, 3.6667, 4.0000]]]])
>>>
>>>
>>> model = torch.nn.UpsamplingBilinear2d(size=(3,5))
>>> a
tensor([[[[1., 2.],
          [3., 4.]]]])
>>> a.shape
torch.Size([1, 1, 2, 2])
>>> b = model(a)
>>> b.shape
torch.Size([1, 1, 3, 5])
>>> b
tensor([[[[1.0000, 1.2500, 1.5000, 1.7500, 2.0000],
          [2.0000, 2.2500, 2.5000, 2.7500, 3.0000],
          [3.0000, 3.2500, 3.5000, 3.7500, 4.0000]]]])
>>>
>>>
>>>

实验举例:

Microsoft Windows [版本 10.0.18363.1440]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Users\chenxuqi>conda activate pytorch_1.7.1_cu102

(pytorch_1.7.1_cu102) C:\Users\chenxuqi>python
Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002E60F3E7870>
>>> a = torch.randn(3,4,1024,512,requires_grad=True)
>>> a.shape
torch.Size([3, 4, 1024, 512])
>>> model = torch.nn.UpsamplingBilinear2d(scale_factor=(2,8))
>>> b = model(a)
>>> a.shape,b.shape
(torch.Size([3, 4, 1024, 512]), torch.Size([3, 4, 2048, 4096]))
>>>
>>>
>>> model = torch.nn.UpsamplingBilinear2d(size=(200,300))
>>> a = torch.randn(3,4,1024,512,requires_grad=True)
>>> a.shape
torch.Size([3, 4, 1024, 512])
>>> b = model(a)
>>> a.shape,b.shape
(torch.Size([3, 4, 1024, 512]), torch.Size([3, 4, 200, 300]))
>>>
>>>
>>>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值