class_docstr: MTCNN face detection module.
  
  This class loads pretrained P-, R-, and O-nets and returns images cropped to include the face
  only, given raw input images of one of the following types:
      - PIL image or list of PIL images
      - numpy.ndarray (uint8) representing either a single image (3D) or a batch of images (4D).
  Cropped faces can optionally be saved to file
  also.
  
  Keyword Arguments:
      image_size {int} -- Output image size in pixels. The image will be square. (default: {160})
      margin {int} -- Margin to add to bounding box, in terms of pixels in the final image. 
          Note that the application of the margin differs slightly from the davidsandberg/facenet
          repo, which applies the margin to the original image before resizing, making the margin
          dependent on the original image size (this is a bug in davidsandberg/facenet).
          (default: {0})
      min_face_size {int} -- Minimum face size to search for. (default: {20})
      thresholds {list} -- MTCNN face detection thresholds (default: {[0.6, 0.7, 0.7]})
      factor {float} -- Factor used to create a scaling pyramid of face sizes. (default: {0.709})
      post_process {bool} -- Whether or not to post process images tensors before returning.
          (default: {True})
      select_largest {bool} -- If True, if multiple faces are detected, the largest is returned.
          If False, the face with the highest detection probability is returned.
          (default: {True})
      selection_method {string} -- Which heuristic to use for selection. Default None. If
          specified, will override select_largest:
                  "probability": highest probability selected
                  "largest": largest box selected
                  "largest_over_threshold": largest box over a certain probability selected
                  "center_weighted_size": box size minus weighted squared offset from image center
              (default: {None})
      keep_all {bool} -- If True, all detected faces are returned, in the order dictated by the
          select_largest parameter. If a save_path is specified, the first face is saved to that
          path and the remaining faces are saved to <save_path>1, <save_path>2 etc.
          (default: {False})
      device {torch.device} -- The device on which to run neural net passes. Image tensors and
          models are copied to this device before running forward passes. (default: {None})
class_docstr_tok: ["MTCNN","face","detection","module",".","This","class","loads","pretrained","P-",",","R-",",","and","O-nets","and","returns","images","cropped","to","include","the","face","only",",","given","raw","input","images","of","one","of","the","following","types",":","-","PIL","image","or","list","of","PIL","images","-","numpy.ndarray","(","uint8",")","representing","either","a","single","image","(","3D",")","or","a","batch","of","images","(","4D",")",".","Cropped","faces","can","optionally","be","saved","to","file","also",".","Keyword","Arguments",":","image_size","{","int","}","--","Output","image","size","in","pixels",".","The","image","will","be","square",".","(","default",":","{","160","}",")","margin","{","int","}","--","Margin","to","add","to","bounding","box",",","in","terms","of","pixels","in","the","final","image",".","Note","that","the","application","of","the","margin","differs","slightly","from","the","davidsandberg\/facenet","repo",",","which","applies","the","margin","to","the","original","image","before","resizing",",","making","the","margin","dependent","on","the","original","image","size","(","this","is","a","bug","in","davidsandberg\/facenet",")",".","(","default",":","{","0","}",")","min_face_size","{","int","}","--","Minimum","face","size","to","search","for",".","(","default",":","{","20","}",")","thresholds","{","list","}","--","MTCNN","face","detection","thresholds","(","default",":","{","[","0.6",",","0.7",",","0.7","]","}",")","factor","{","float","}","--","Factor","used","to","create","a","scaling","pyramid","of","face","sizes",".","(","default",":","{","0.709","}",")","post_process","{","bool","}","--","Whether","or","not","to","post","process","images","tensors","before","returning",".","(","default",":","{","True","}",")","select_largest","{","bool","}","--","If","True",",","if","multiple","faces","are","detected",",","the","largest","is","returned",".","If","False",",","the","face","with","the","highest","detection","probability","is","returned",".","(","default",":","{","True","}",")","selection_method","{","string","}","--","Which","heuristic","to","use","for","selection",".","Default","None",".","If","specified",",","will","override","select_largest",":","``","probability","''",":","highest","probability","selected","``","largest","''",":","largest","box","selected","``","largest_over_threshold","''",":","largest","box","over","a","certain","probability","selected","``","center_weighted_size","''",":","box","size","minus","weighted","squared","offset","from","image","center","(","default",":","{","None","}",")","keep_all","{","bool","}","--","If","True",",","all","detected","faces","are","returned",",","in","the","order","dictated","by","the","select_largest","parameter",".","If","a","save_path","is","specified",",","the","first","face","is","saved","to","that","path","and","the","remaining","faces","are","saved","to","<","save_path",">","1",",","<","save_path",">","2","etc",".","(","default",":","{","False","}",")","device","{","torch.device","}","--","The","device","on","which","to","run","neural","net","passes",".","Image","tensors","and","models","are","copied","to","this","device","before","running","forward","passes",".","(","default",":","{","None","}",")"]
docstr: Run MTCNN face detection on a PIL image or numpy array. This method performs both
  detection and extraction of faces, returning tensors representing detected faces rather
  than the bounding boxes. To access bounding boxes, see the MTCNN.detect() method below.
  
  Arguments:
      img {PIL.Image, np.ndarray, or list} -- A PIL image, np.ndarray, torch.Tensor, or list.
  
  Keyword Arguments:
      save_path {str} -- An optional save path for the cropped image. Note that when
          self.post_process=True, although the returned tensor is post processed, the saved
          face image is not, so it is a true representation of the face in the input image.
          If `img` is a list of images, `save_path` should be a list of equal length.
          (default: {None})
      return_prob {bool} -- Whether or not to return the detection probability.
          (default: {False})
  
  Returns:
      Union[torch.Tensor, tuple(torch.tensor, float)] -- If detected, cropped image of a face
          with dimensions 3 x image_size x image_size. Optionally, the probability that a
          face was detected. If self.keep_all is True, n detected faces are returned in an
          n x 3 x image_size x image_size tensor with an optional list of detection
          probabilities. If `img` is a list of images, the item(s) returned have an extra 
          dimension (batch) as the first dimension.
  
  Example:
  >>> from facenet_pytorch import MTCNN
  >>> mtcnn = MTCNN()
  >>> face_tensor, prob = mtcnn(img, save_path='face.png', return_prob=True)
docstr_tok: ["Run","MTCNN","face","detection","on","a","PIL","image","or","numpy","array",".","This","method","performs","both","detection","and","extraction","of","faces",",","returning","tensors","representing","detected","faces","rather","than","the","bounding","boxes",".","To","access","bounding","boxes",",","see","the","MTCNN.detect","(",")","method","below",".","Arguments",":","img","{","PIL.Image",",","np.ndarray",",","or","list","}","--","A","PIL","image",",","np.ndarray",",","torch.Tensor",",","or","list",".","Keyword","Arguments",":","save_path","{","str","}","--","An","optional","save","path","for","the","cropped","image",".","Note","that","when","self.post_process=True",",","although","the","returned","tensor","is","post","processed",",","the","saved","face","image","is","not",",","so","it","is","a","true","representation","of","the","face","in","the","input","image",".","If","`","img","`","is","a","list","of","images",",","`","save_path","`","should","be","a","list","of","equal","length",".","(","default",":","{","None","}",")","return_prob","{","bool","}","--","Whether","or","not","to","return","the","detection","probability",".","(","default",":","{","False","}",")","Returns",":","Union","[","torch.Tensor",",","tuple","(","torch.tensor",",","float",")","]","--","If","detected",",","cropped","image","of","a","face","with","dimensions","3","x","image_size","x","image_size",".","Optionally",",","the","probability","that","a","face","was","detected",".","If","self.keep_all","is","True",",","n","detected","faces","are","returned","in","an","n","x","3","x","image_size","x","image_size","tensor","with","an","optional","list","of","detection","probabilities",".","If","`","img","`","is","a","list","of","images",",","the","item","(","s",")","returned","have","an","extra","dimension","(","batch",")","as","the","first","dimension",".","Example",":",">",">",">","from","facenet_pytorch","import","MTCNN",">",">",">","mtcnn","=","MTCNN","(",")",">",">",">","face_tensor",",","prob","=","mtcnn","(","img",",","save_path='face.png","'",",","return_prob=True",")"]
code: def forward(self, img, save_path=None, return_prob=False):
      """Run MTCNN face detection on a PIL image or numpy array. This method performs both
      detection and extraction of faces, returning tensors representing detected faces rather
      than the bounding boxes. To access bounding boxes, see the MTCNN.detect() method below.
  
      Arguments:
          img {PIL.Image, np.ndarray, or list} -- A PIL image, np.ndarray, torch.Tensor, or list.
  
      Keyword Arguments:
          save_path {str} -- An optional save path for the cropped image. Note that when
              self.post_process=True, although the returned tensor is post processed, the saved
              face image is not, so it is a true representation of the face in the input image.
              If `img` is a list of images, `save_path` should be a list of equal length.
              (default: {None})
          return_prob {bool} -- Whether or not to return the detection probability.
              (default: {False})
  
      Returns:
          Union[torch.Tensor, tuple(torch.tensor, float)] -- If detected, cropped image of a face
              with dimensions 3 x image_size x image_size. Optionally, the probability that a
              face was detected. If self.keep_all is True, n detected faces are returned in an
              n x 3 x image_size x image_size tensor with an optional list of detection
              probabilities. If `img` is a list of images, the item(s) returned have an extra
              dimension (batch) as the first dimension.
  
      Example:
      >>> from facenet_pytorch import MTCNN
      >>> mtcnn = MTCNN()
      >>> face_tensor, prob = mtcnn(img, save_path='face.png', return_prob=True)
      """
  
      # Detect faces
      batch_boxes, batch_probs, batch_points = self.detect(
          img, landmarks=True
      )
      # Select faces
      if not self.keep_all:
          batch_boxes, batch_probs, batch_points = self.select_boxes(
              batch_boxes,
              batch_probs,
              batch_points,
              img,
              method=self.selection_method,
          )
      # Extract faces
      faces = self.extract(img, batch_boxes, save_path)
  
      if return_prob:
          return faces, batch_probs
      else:
          return faces
  
imports: import torch
  from torch import nn
  import numpy
  import os
  from .utils.detect_face import detect_face, extract_face
label_desc: Use image node_id 2 for calling the MTCNN obj's underlying member method code with example usage: obj.forward(img, save_path, return_prob) and returns: faces,  batch_probs, faces