          self.get_filter_encodings()
          self.threshold = threshold
          logger.debug("Initialized %s", self.__class__.__name__)
  
      # <<< 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
  
      @staticmethod
      def load_images(reference_file_paths, nreference_file_paths):
          """ Load the images """
          retval = dict()
          for fpath in reference_file_paths:
 
</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         self.vgg_face = self.get_model(git_model_id, model_filename)
 </s> add         self.vgg_face = VGGFace()
 </s> remove     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

 </s> add  </s> remove 
    @staticmethod
    def find_cosine_similiarity(source_face, test_face):
        """ Find the cosine similarity between a source face and a test face """
        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))
        return 1 - (var_a / (np.sqrt(var_b) * np.sqrt(var_c)))
 </s> add  </s> remove             size = 0
 </s> add             # Limit queue size to avoid stacking ram
            size = 32
          self.get_filter_encodings()
          self.threshold = threshold
          logger.debug("Initialized %s", self.__class__.__name__)
  











      @staticmethod
      def load_images(reference_file_paths, nreference_file_paths):
          """ Load the images """
          retval = dict()
          for fpath in reference_file_paths:
keep keep keep keep 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