Following the above post, starting from where you make tensor_image. To cast tensor_image safely back into numpy with values being within 0-255, I’d use torchvision's ToPILImage and from there go into numpy, as so:
(note that tensor_to_image was set equal to ToPILImage() in the second cell in the above post.

image1128×1107 205 KB


image1095×971 163 KB