coincheung
(coincheung)
November 13, 2018, 12:31pm
#1
I need to downsample my label tensor from (n, c, W, H) to (n, c, w, h) and my tensor has type of torch.int64 because it is a label tensor. I tried to use F.interpolate(lb, size, mode = 'nearest')
, but it has the result of
RuntimeError: upsample_nearest1d_forward is not implemented for type torch.cuda.LongTensor
So what is the correct way to do this?
ptrblck
November 13, 2018, 1:45pm
#2
Maybe you could just calculate the indices and slice the input tensor directly:
N, C, H, W = 1, 3, 10, 10
h, w = 5, 5
x = torch.randint(0, 10, (N, C, H, W))
iw = torch.linspace(0, W-1, w).long()
ih = torch.linspace(0, H-1, h).long()
x_interp = x[:, :, ih[:, None], iw]
Would that work for you?
coincheung
(coincheung)
November 14, 2018, 2:50am
#3
Yes, good. Thanks a lot !!
srama
(Santhosh Kumar Ramakrishnan)
March 9, 2019, 5:20am
#4
Hi,
Could you explain how this works? I’ve seen advanced indexing and normal slicing. This seems new.
This is basically advanced indexing in dims 2 and 3.
Similar to the numpy example with the difference that I get all values in dim 0 and 1.
srama
(Santhosh Kumar Ramakrishnan)
March 9, 2019, 7:43pm
#6
So it’s basically broadcasting plus advanced indexing. Cool! Thank you.