Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Torch Resize Tensor

How do I resize a Tensor in Torch? Methods documented in https://github.com/torch/torch7/blob/master/doc/tensor.md#resizing do not seem to work.

images = image.load('image.png',1,'float')
print(images:size()) 
-- result: 224x224 [torch.LongStorage of size 2] 

images.resize(torch.FloatTensor(224,224,1,1))
print(images:size()) 
-- result: 224x224 [torch.LongStorage of size 2] 
-- expected: 224x224x1x1 [torch.LongStorage of size 4]

Why doesn't this approach work?

like image 651
Simon Avatar asked Apr 03 '15 15:04

Simon


1 Answers

You need to do:

images:resize(...)

What you did:

images.resize(...)

images.resize does not pass the current tensor as the first argument.

images:resize(...) is equivalent to images.resize(images, ...)

like image 194
smhx Avatar answered Sep 21 '22 18:09

smhx