假设我有一个图像,我想通过grid_sample或从torch.nn.functional库中插值,将其分辨率降到一半。我为这两种情况选择了mode ='bilinear'
。
对于grid_sample,我将执行以下操作:
dh = torch.linspace(-1,1, h/2)
dw = torch.linspace(-1,1, w/2)
mesh, meshy = torch.meshgrid((dh,dw))
grid = torch.stack.((meshy,meshx),2)
grid = grid.unsqueeze(0) #add batch dim
x_downsampled = torch.nn.functional.grid_sample(img, grid, mode='bilinear')
对于插值,我会:
x_downsampled = torch.nn.functional.interpolate(img, size=(h/2,w/2), mode='bilinear')
这两种方法有什么不同?哪一个更适合我的例子?
发布于 2022-11-24 07:08:03
简洁第二。Grid_sample更适合于非均匀插值.
https://stackoverflow.com/questions/72373545
复制相似问题