White background fill with affine_grid and grid_sample

I am trying to use torch.nn.function.affine_grid and grid sample functionalities for a Spatial Transformer. After the affine transformation the the image has black regions near the edges due to the shifting and rotation of the original image. Is there some way to define the fill value instead of having a default black fill in the empty regions. (like in the attatched image)

Screenshot from 2020-03-17 20-09-00

You could set padding_mode="border" in F.grid_sample, where “border” defines the value you would like to use for out-of-grid locations.