How to normalize a feature map to use for grid_sample

I have a feature map size of Bx3xDxHxW, the range is from 0 to 1. I want to use it as flow field and input to grid_sample function. As the document said

grid specifies the sampling pixel locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1] . For example, values x = -1, y = -1 is the left-top pixel of input , and values x = 1, y= 1 is the right-bottom pixel of input

So, How can I normalize the feature map to range [-1,1] to use as grid? Thanks

This is what I did

spatial_gds = torch.rand(1,2,3,3,3)
print (spatial_gds)

_, _, D, H, W = spatial_gds.size()
grids = [torch.cumsum(spatial_gds[:, i, ...], dim=i+2)
         for i in range(2)]
#print(grids)
grids_norm = torch.stack([(grid/dim)*2-1. for dim, grid in zip([D,H,W], grids)], dim=4)
print(grids_norm)