如何使用F.interpolate调整PyTorch中所有4个尺寸(NCHW)的大小?

2024-04-24 10:58:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在试图找出如何在张量中调整批次、通道、高度和宽度维度的大小。目前,我可以调整通道、高度和宽度尺寸,但批次尺寸保持不变

x = torch.ones(3,4,64,64)

x = F.interpolate(x.unsqueeze(0), size=(3,4,4), mode="trilinear").squeeze(0)

x.size() # (3,3,4,4) # batch dimension has not been resized.
# I need x to be resized so that it has a size of: (1,3,4,4)


# Is this a good idea?
x = x.permute(1,0,2,3)
x = F.interpolate(x.unsqueeze(0), size=(1, x.size(2), x.size(3)), mode="trilinear").squeeze(0)
x = x.permute(1,0,2,3)

x.size() # (1,3,4,4)

我应该排列张量来调整批次维度的大小吗?或者以某种方式对其进行迭代


Tags: size宽度高度mode尺寸batchonestorch
1条回答
网友
1楼 · 发布于 2024-04-24 10:58:00

这似乎让我可以调整批次维度的大小:

x = x.permute(1,0,2,3)
x = F.interpolate(x.unsqueeze(0), size=(1, x.size(2), x.size(3)), mode="trilinear").squeeze(0)
x = x.permute(1,0,2,3)

相关问题 更多 >