Skip to content

Instantly share code, notes, and snippets.

@vmarkovtsev
Last active November 27, 2019 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmarkovtsev/41c7e517ee492cd1cc34c191acf79055 to your computer and use it in GitHub Desktop.
Save vmarkovtsev/41c7e517ee492cd1cc34c191acf79055 to your computer and use it in GitHub Desktop.
def save_image(tensor: Union[np.ndarray, tf.Tensor], path: str):
if hasattr(tensor, "numpy"):
tensor = tensor.numpy()
tensor = np.clip(tensor, 0, 255) # <<< this is new
Image.fromarray(np.squeeze(tensor).astype(np.uint8), "RGB").save(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment