如何在Pytorch中不使用变换定义高度和宽度来放大图像?('-- upscale _factor',type=int,required=True,help=“超分辨率放大因子”)
发布于 2019-02-20 01:24:11
这可能会完成这项工作
transforms.Compose([transforms.resize(ImageSize*Scaling_Factor)])发布于 2019-02-20 03:17:04
如果我理解正确,您只想通过指定因子f (而不是指定目标宽度和高度)来对张量x进行上采样,您可以尝试这样做:
from torch.nn.modules.upsampling import Upsample
m = Upsample(scale_factor=f, mode='nearest')
x_upsampled = m(x)注意,Upsample允许多种插值模式,例如mode='nearest'或mode='bilinear'
发布于 2019-09-16 00:55:47
这里有一个有趣的例子:
input = torch.tensor([[1.,2.],[3.,4.]])
input=input[None]
input=input[None]
output = nn.functional.interpolate(input, scale_factor=2, mode='nearest')
print(output)输出:
tensor([[[[1., 1., 2., 2.],
[1., 1., 2., 2.],
[3., 3., 4., 4.],
[3., 3., 4., 4.]]]])https://stackoverflow.com/questions/54771426
复制相似问题