For example, I want upsample my image with scale_factor 1.5.
Do you need this transform to be differentiable, or just to use it as part of the data loading?
If you are referring to upsampling using http://pytorch.org/docs/nn.html#upsamplingbilinear2d then you can upsample by a non-int scale_factor by directly providing the output size. For example:
import torch
import torch.nn as nn
from torch.autograd import Variable
inp = Variable(torch.randn(10, 3, 24, 24))
m = nn.UpsamplingBilinear2d(size=(55, 55))
out = m(inp)
print(out.size())
I need it to be differentiable, as I am doing a pixel-to-pixel task which requires the output size is different with the input size.
Thanks. Is this operation differentiable?
yes it is differentiable. all operators in torch.nn
are differentiable.
I see.
Thanks for the reply.
This appears to give an error saying that the upsampled size is not divisible by the original size when done with UpsampleNearest2d rather than UpsampleBilinear2d
I am also getting same error. can someone help.
Thanks