Saving Images from predictions in v2?

I’m updating my superres models based on Fastai v2, and I’m stuck on saving the final image.

After predicting, there are obvious clipping issues with the predictions. In v1, the solution was to do the following:

def save_img(img, fn):
  x = np.minimum(np.maximum(image2tensor(, 0), 255).astype(np.uint8)

These functions don’t exist anymore in v1, and PILImage.create(fn) is not doing the trick.

Anyone know what the equivalent solution is for v2?

To directly save a tensor you can use save_image from torchvision.utils. It is straight forward with save_image(image, 'name.png'). If you have float values in your tensor, they should be between 0 and 1, otherwise the image will just be white.

1 Like