Autogradable image resize
meijieru
you can look at these Upsampling* modules to resize up: To resize down, you can use AvgPool2d
smth
meijieru
thnkim
apaszke
Has this been implemented yet for float scale factors? Greatly appreciated!
jwin
Jwin, I had the same problem and I solved using a sampling grid: <SCODE>def downsampling(x, size=None, scale_factor=None, mode='nearest'):
	# define size if user has specified scale_factor
	if size is None: size = (int(scale_factor*x.size(2)), int(scale_factor*x.size(3)))
	# create coordinates
	h = torch.arange(0,size[0]) / (size[0]-1) * 2 - 1
	w = torch.arange(0,size[1]) / (size[1]-1) * 2 - 1
	# create grid
	grid = torch.zeros(size[0],size[1],2)
	grid[:,:,0] = w.unsqueeze(0).repeat(size[0],1)
	grid[:,:,1] = h.unsqueeze(0).repeat(size[1],1).transpose(0,1)
	# expand to match batch size
	grid = grid.unsqueeze(0).repeat(x.size(0),1,1,1)
	if x.is_cuda: grid = grid.cuda()
	# do sampling
	return F.grid_sample(x, grid, mode=mode)
<ECODE>
flavio
ndronen
Does anyone have a solution for autogradable general nearest neighbours upsampling?
mariosfourn
ndronen
<SCODE>x = torch.randn(1, 3, 24, 24)
up = nn.Upsample(size=47, mode='bilinear')
y = up(x)
print(y.shape)
> torch.Size([1, 3, 47, 47])
<ECODE>
ptrblck
Is there any plan to support ‘nearest’ ? As in many dense estimation task, a edge preserving property is important, using bilinear  downsample will hurt that property…
chenchr
solsol
ptrblck
Got it. Thanks a lot
solsol