xout_size =x4.shape[2]
yout_size = x4.shape[3]
xc = torch.linspace(-1, 1, yout_size).repeat(xout_size, 1)
yc = torch.linspace(-1, 1, xout_size).view(-1, 1).repeat(1, yout_size)
grid = torch.cat((xc.unsqueeze(2), yc.unsqueeze(2)), 2)
grid = grid.unsqueeze_(0).repeat(self.MiniBatch, 1, 1, 1)

image_small = F.grid_sample(x, grid)


x4 is an out of shape (M,1,x,y) from a conv2d
I have the version cloned form Github.