Saving Image in tensor array as jpg or png
I am trying to detect the face using mtcnn. The main aim is to detect face, crop and save the cropped image as jpg or png file type.  The code implemented is below.
from facenet_pytorch import MTCNN
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt
img = Image.open(&quot;example.jpg&quot;)
mtcnn = MTCNN(margin=20, keep_all=True, post_process=False)
faces = mtcnn(img)
print(faces.shape)

This gives the shape
torch.Size([1, 3, 160, 160])

How to save this cropped portion as jpg file.

torch.save(faces, &quot;faces.torch&quot;)

that wont be saved as an image, if you want to save it as an image:
img = Image.fromarray(faces.cpu().detach().numpy()[0])
img.save(&quot;faces.png&quot;)

