              logger.debug("Filter Filename: %s, encoding shape: %s", filename, encodings.shape)
              face["encoding"] = encodings
              del face["face"]
  
      def predict(self, face):
          """ Return encodings for given image from vgg_face """
          if face.shape[0] != self.input_size:
              face = self.resize_face(face)
          blob = cv2.dnn.blobFromImage(face,  # pylint: disable=no-member
                                       1.0,
                                       (self.input_size, self.input_size),
                                       [104, 117, 123],
                                       False,
                                       False)
          self.vgg_face.setInput(blob)
          preds = self.vgg_face.forward()[0, :]
          return preds
  
      def resize_face(self, face):
          """ Resize incoming face to model_input_size """
          if face.shape[0] < self.input_size:
              interpolation = cv2.INTER_CUBIC  # pylint:disable=no-member
          else:
              interpolation = cv2.INTER_AREA  # pylint:disable=no-member
  
          face = cv2.resize(face,  # pylint:disable=no-member
                            dsize=(self.input_size, self.input_size),
                            interpolation=interpolation)
          return face
  
      def check(self, detected_face):
          """ Check the extracted Face """
          logger.trace("Checking face with FaceFilter")
          distances = {"filter": list(), "nfilter": list()}
          encodings = self.predict(detected_face.aligned_face)
 
</s> remove 

class VGGFace():
    """ Temporary drop-in replacement for face_recognition.face_encodings """
    # TODO: Replace with GPU bound keras-vgg-face
    def __init__(self):
        git_model_id = 7
        model_filename = ["vgg_face_v1.caffemodel", "vgg_face_v1.prototxt"]
        self.input_size = 224
        self.model = self.get_model(git_model_id, model_filename)

    @staticmethod
    def get_model(git_model_id, model_filename):
        """ Check if model is available, if not, download and unzip it """
        root_path = os.path.abspath(os.path.dirname(sys.argv[0]))
        cache_path = os.path.join(root_path, "plugins", "extract", ".cache")
        model = GetModel(model_filename, cache_path, git_model_id).model_path
        vgg_face = cv2.dnn.readNetFromCaffe(model[1], model[0])  # pylint: disable=no-member
        vgg_face.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)  # pylint: disable=no-member
        return vgg_face

    def predict(self, face):
        """ Return face encodings from vgg_face """
        if face.shape[0] != self.input_size:
            face = self.resize_face(face)
        blob = cv2.dnn.blobFromImage(face,  # pylint: disable=no-member
                                     1.0,
                                     (self.input_size, self.input_size),
                                     [104, 117, 123],
                                     False,
                                     False)
        logger.trace("vgg_face input shape: %s", blob.shape)
        self.model.setInput(blob)
        preds = self.model.forward()[0, :]
        logger.trace("vgg_face encoding shape: %s", preds.shape)
        return preds

    def resize_face(self, face):
        """ Resize incoming face to model_input_size """
        if face.shape[0] < self.input_size:
            interpolation = cv2.INTER_CUBIC  # pylint:disable=no-member
        else:
            interpolation = cv2.INTER_AREA  # pylint:disable=no-member

        face = cv2.resize(face,  # pylint:disable=no-member
                          dsize=(self.input_size, self.input_size),
                          interpolation=interpolation)
        return face

    @staticmethod
    def find_cosine_similiarity(source_face, test_face):
        """ Find the cosine similarity between a source face and a test face """
        logger.trace("source_face shape: %s, test_face shape: %s",
                     source_face.shape, test_face.shape)
        var_a = np.matmul(np.transpose(source_face), test_face)
        var_b = np.sum(np.multiply(source_face, source_face))
        var_c = np.sum(np.multiply(test_face, test_face))
        retval = 1 - (var_a / (np.sqrt(var_b) * np.sqrt(var_c)))
        logger.debug("Similarity: %s", retval)
        return retval
 </s> add  </s> remove             encodings = self.predict(face["face"])
 </s> add             encodings = self.vgg_face.predict(face["face"])
 </s> remove         encodings = self.predict(detected_face.aligned_face)
 </s> add         encodings = self.vgg_face.predict(detected_face.aligned_face)
 </s> remove             similarity = self.find_cosine_similiarity(filt["encoding"], encodings)
 </s> add             similarity = self.vgg_face.find_cosine_similiarity(filt["encoding"], encodings)
 </s> remove     # <<< GET MODEL >>> #
    @staticmethod
    def get_model(git_model_id, model_filename):
        """ Check if model is available, if not, download and unzip it """
        root_path = os.path.abspath(os.path.dirname(sys.argv[0]))
        cache_path = os.path.join(root_path, "plugins", "extract", ".cache")
        model = GetModel(model_filename, cache_path, git_model_id).model_path
        vgg_face = cv2.dnn.readNetFromCaffe(model[1], model[0])  # pylint: disable=no-member
        vgg_face.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)  # pylint: disable=no-member
        return vgg_face

 </s> add 
              logger.debug("Filter Filename: %s, encoding shape: %s", filename, encodings.shape)
              face["encoding"] = encodings
              del face["face"]
  


























      def check(self, detected_face):
          """ Check the extracted Face """
          logger.trace("Checking face with FaceFilter")
          distances = {"filter": list(), "nfilter": list()}
          encodings = self.predict(detected_face.aligned_face)
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Fixups

vgg_face: to own module
vgg_face: correct output and normalization
Extract: more aggressive queue sizes
sys_info: Fix cudnn check error on Linux 
lib/face_filter.py