python - view() + UpsamplingBilinear2d()
2021/11/25 9:39:53
本文主要是介绍python - view() + UpsamplingBilinear2d(),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import torch from torch import nn # view函数的-1参数的作用在于基于另一参数,自动计算该维度的大小 # view的第一个参数:2 代表的是batch 后面的2,2应该是几行几列的意思,这两个必须一致 # arange(1,9) => 1,2,3,4,5,6,7,8 input = torch.arange(1, 9, dtype=torch.float32).view(2, -1, 2, 2) print(input) # scale_factor : 缩放倍数 # UpsamplingBilinear2d:专门用于2D数据的线性插值算法 m = nn.UpsamplingBilinear2d(scale_factor=3) print(m(input)) # 结果如下所示 # tensor([[[[1., 2.], # [3., 4.]]], # # [[[5., 6.], # [7., 8.]]]]) # tensor([[[[1.0000, 1.2000, 1.4000, 1.6000, 1.8000, 2.0000], # [1.4000, 1.6000, 1.8000, 2.0000, 2.2000, 2.4000], # [1.8000, 2.0000, 2.2000, 2.4000, 2.6000, 2.8000], # [2.2000, 2.4000, 2.6000, 2.8000, 3.0000, 3.2000], # [2.6000, 2.8000, 3.0000, 3.2000, 3.4000, 3.6000], # [3.0000, 3.2000, 3.4000, 3.6000, 3.8000, 4.0000]]], # [[[5.0000, 5.2000, 5.4000, 5.6000, 5.8000, 6.0000], # [5.4000, 5.6000, 5.8000, 6.0000, 6.2000, 6.4000], # [5.8000, 6.0000, 6.2000, 6.4000, 6.6000, 6.8000], # [6.2000, 6.4000, 6.6000, 6.8000, 7.0000, 7.2000], # [6.6000, 6.8000, 7.0000, 7.2000, 7.4000, 7.6000], # [7.0000, 7.2000, 7.4000, 7.6000, 7.8000, 8.0000]]]])
这篇关于python - view() + UpsamplingBilinear2d()的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python