Libtorch: resize function

(Riddick Gao) #1

How can I resize a tensor to a smaller size in libtorch? such as {1, 3, 704, 704} -> {1, 3, 224, 224}. I have tried the tensor.resize_( {1, 3, 224, 224}) method. But I found that it just returned a small region(224x224) of original image. please help me . thanks.

(Thomas V) #2

You probably want interpolation?

Best regards


(Riddick Gao) #3

Yes, I want to do the down sampling。Does libtorch have any down sampling method? thanks

(Thomas V) #4

Yes, what is it that interpolate is lacking for your purpose?

a = torch.arange(1_486_848.).view(1, 3, 704, 704)
b = torch.nn.functional.interpolate(a, size=(224, 224))

Best regards


(Riddick Gao) #5

thanks. But I am using libtorch with C++ API. I cannot find the interpolate fuction in libtorch.

(Riddick Gao) #6

I find the torch::grid_sampler() in libtorch. And it works! Thanks for your help。 :)

1 Like