Denorm an image in Fastai v1

Fastai 0.7 had a convenient function, called denorm(), that took as input an image in tensor form and converted it to a format suitable for display by MatPlotlib. The following short function does the same in Fastai v1. The function performs two tasks:

  1. Denormalizes the image

  2. Transposes the image from a (3, m, n) format to a (mx, n, 3)

    def denorm_img (model, img):
    # Denorm image in Tensor form and convert it to a format (m x n x3) for display by MatPlotLib
    ima = model.denorm(img)
    return np.transpose(ima, (1, 2, 0))