save_image

Save and Display an Image from a Torch Tensor

Description

Converts a Torch tensor to a normalized RGB image array, saves it as a PNG file, and optionally displays it in the RStudio Viewer pane using grid::grid.raster().

Usage

save_image(img, save_to = "output.png", normalize = TRUE)

Arguments

  • img: A numeric with shape [3, H, W].
  • save_to: File path for the PNG image (default is "output.png").
  • normalize: Logical; whether to normalize pixel values to [0, 1]. Default is TRUE.

Value

Invisibly returns the saved file path.

Examples

save_image(output_tensor, "sample.png")