          """ Sort by identity similarity """
          logger.info("Sorting by identity similarity...")
          filename_list, image_list = self._get_images()
  
          logger.info("Calculating face identifiers...")
          preds = np.array([self.vgg_face.predict(img)
                            for img in tqdm(image_list, desc="Calculating...", file=sys.stdout)])
  
          logger.info("Sorting by ward linkage...")
          indices = self.vgg_face.sorted_similarity(preds, method="ward")
          img_list = np.array(filename_list)[indices]
          return img_list
 
</s> remove         filename_list, image_list = self._get_images()
 </s> add  </s> remove         img_list = np.array(filename_list)[indices]
 </s> add         img_list = np.array(filenames)[indices] </s> remove         free_ram = psutil.virtual_memory().free / divider
 </s> add         free_ram = psutil.virtual_memory().available / divider </s> remove     exit(0)
 </s> add     sys.exit(0)
        # TODO This should be set in init
        self._loader = ImagesLoader(self.args.input_dir)

        filenames = []
        preds = np.empty((self._loader.count, 512), dtype="float32")
        for idx, (filename, image) in enumerate(tqdm(self._loader.load(),
                                                     desc="Classifying Faces...",
                                                     total=self._loader.count)):
            filenames.append(filename)
            preds[idx] = self.vgg_face.predict(image)
          """ Sort by identity similarity """
          logger.info("Sorting by identity similarity...")
          filename_list, image_list = self._get_images()
  
        # TODO This should be set in init
        self._loader = ImagesLoader(self.args.input_dir)

        filenames = []
        preds = np.empty((self._loader.count, 512), dtype="float32")
        for idx, (filename, image) in enumerate(tqdm(self._loader.load(),
                                                     desc="Classifying Faces...",
                                                     total=self._loader.count)):
            filenames.append(filename)
            preds[idx] = self.vgg_face.predict(image)
        # TODO This should be set in init
        self._loader = ImagesLoader(self.args.input_dir)

        filenames = []
        preds = np.empty((self._loader.count, 512), dtype="float32")
        for idx, (filename, image) in enumerate(tqdm(self._loader.load(),
                                                     desc="Classifying Faces...",
                                                     total=self._loader.count)):
            filenames.append(filename)
            preds[idx] = self.vgg_face.predict(image)
        # TODO This should be set in init
        self._loader = ImagesLoader(self.args.input_dir)

        filenames = []
        preds = np.empty((self._loader.count, 512), dtype="float32")
        for idx, (filename, image) in enumerate(tqdm(self._loader.load(),
                                                     desc="Classifying Faces...",
                                                     total=self._loader.count)):
            filenames.append(filename)
            preds[idx] = self.vgg_face.predict(image)
  
          logger.info("Sorting by ward linkage...")
          indices = self.vgg_face.sorted_similarity(preds, method="ward")
          img_list = np.array(filename_list)[indices]
          return img_list
keep keep keep keep replace replace replace keep keep keep keep keep
 tools.sort - Optimize sort by face 
tools/sort.py