          input directory.
          Relevant cli arguments: -k, -l
          :return: function reference
          """
          if log_changes:
              if keep_original:
                  def process_file(src, dst, changes):
                      """ Process file method if logging changes
                          and keeping original """
                      copyfile(src, dst)
                      changes[src] = dst
  
              else:
                  def process_file(src, dst, changes):
                      """ Process file method if logging changes
                          and not keeping original """
                      os.rename(src, dst)
                      changes[src] = dst
  
          else:
              if keep_original:
                  def process_file(src, dst, changes):  # pylint: disable=unused-argument
                      """ Process file method if not logging changes
                          and keeping original """
                      copyfile(src, dst)
  
              else:
                  def process_file(src, dst, changes):  # pylint: disable=unused-argument
                      """ Process file method if not logging changes
                          and not keeping original """
                      os.rename(src, dst)
          return process_file
  
      @staticmethod
      def set_renaming_method(log_changes):
          """ Set the method for renaming files """
          if log_changes:
              def renaming(src, output_dir, i, changes):
                  """ Rename files  method if logging changes """
                  src_basename = os.path.basename(src)
  
                  __src = os.path.join(output_dir,
                                       f"{i:05d}_{src_basename}")
                  dst = os.path.join(
                      output_dir,
                      f"{i:05d}{os.path.splitext(src_basename)[1]}")
                  changes[src] = dst
                  return __src, dst
          else:
              def renaming(src, output_dir, i, changes):  # pylint: disable=unused-argument
                  """ Rename files method if not logging changes """
                  src_basename = os.path.basename(src)
  
                  src = os.path.join(output_dir,
                                     f"{i:05d}_{src_basename}")
                  dst = os.path.join(
                      output_dir,
                      f"{i:05d}{os.path.splitext(src_basename)[1]}")
                  return src, dst
          return renaming
  
      @staticmethod
      def get_avg_score_hist(img1, references):
          """ Return the average histogram score between a face and
              reference image """
 
</s> remove     @staticmethod
    def set_process_file_method(log_changes, keep_original):
        """
        Assigns the final file processing method based on whether changes are
        being logged and whether the original files are being kept in the
        input directory.
        Relevant cli arguments: -k, -l
        :return: function reference
 </s> add         These are files which are sorted but not binned, so just the filename gets updated </s> remove     # Final process methods
    def final_process_rename(self, img_list):
        """ Rename the files """
        output_dir = self._args.output_dir

        process_file = self.set_process_file_method(self._args.log_changes,
                                                    self._args.keep_original)

        # Make sure output directory exists
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        description = (
            "Copying and Renaming" if self._args.keep_original
            else "Moving and Renaming"
        )

        for i in tqdm(range(0, len(img_list)),
                      desc=description,
                      leave=False,
                      file=sys.stdout):
            src = img_list[i] if isinstance(img_list[i], str) else img_list[i][0]
            src_basename = os.path.basename(src)

            dst = os.path.join(output_dir, f"{i:05d}_{src_basename}")
            try:
                process_file(src, dst, self.changes)
            except FileNotFoundError as err:
                logger.error(err)
                logger.error('fail to rename %s', src)

        for i in tqdm(range(0, len(img_list)),
                      desc=description,
                      file=sys.stdout):
            renaming = self.set_renaming_method(self._args.log_changes)
            fname = img_list[i] if isinstance(img_list[i], str) else img_list[i][0]
            src, dst = renaming(fname, output_dir, i, self.changes)

            try:
                os.rename(src, dst)
            except FileNotFoundError as err:
                logger.error(err)
                logger.error('fail to rename %s', format(src))

        if self._args.log_changes:
            self.write_to_log(self.changes)

    def final_process_folders(self, bins):
        """ Move the files to folders """
        output_dir = self._args.output_dir
 </s> add         if sort_method != "none" and group_method != "none" and group_method != sort_method:
            grouper = self._processes[group_method](self._args, is_group=True)
            retval = SortMultiMethod(self._args, sorter, grouper)
            logger.debug("Got sorter + grouper: %s (%s, %s)", retval, sorter, grouper) </s> remove                 dst = os.path.join(output_dir, str(i), src_basename)
                try:
                    process_file(src, dst, self.changes)
                except FileNotFoundError as err:
                    logger.error(err)
                    logger.error("Failed to move '%s' to '%s'", src, dst)
 </s> add             retval = sorter </s> remove     @staticmethod
    def get_avg_score_hist(img1, references):
        """ Return the average histogram score between a face and
            reference image """
        scores = []
        for img2 in references:
            score = cv2.compareHist(img1, img2, cv2.HISTCMP_BHATTACHARYYA)
            scores.append(score)
        return sum(scores) / len(scores)
 </s> add         description = f"{'Copying' if self._args.keep_original else 'Moving'} and renaming"
        for idx, source in enumerate(tqdm(self._sorter.sorted_filelist,
                                          desc=description,
                                          file=sys.stdout,
                                          leave=False)):
            dest = os.path.join(output_dir, f"{idx:06d}_{os.path.basename(source)}") </s> remove         process_file = self.set_process_file_method(self._args.log_changes,
                                                    self._args.keep_original)

        # First create new directories to avoid checking
        # for directory existence in the moving loop
        logger.info("Creating group directories.")
        for i in range(len(bins)):
            directory = os.path.join(output_dir, str(i))
            if not os.path.exists(directory):
                os.makedirs(directory)

        description = (
            "Copying into Groups" if self._args.keep_original
            else "Moving into Groups"
        )

        logger.info("Total groups found: %s", len(bins))
        for i in tqdm(range(len(bins)), desc=description, file=sys.stdout):
            for j in range(len(bins[i])):
                src = bins[i][j]
                src_basename = os.path.basename(src)
 </s> add         else:
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
          input directory.
          Relevant cli arguments: -k, -l
          :return: function reference
          """
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
        output_dir = self._args.output_dir
        os.makedirs(output_dir, exist_ok=True)
  
      @staticmethod
      def get_avg_score_hist(img1, references):
          """ Return the average histogram score between a face and
              reference image """
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 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 replace replace replace replace keep keep keep keep keep
 Overhaul sort:
  - Standardize image data reading and writing
  - Optimize loading (just one pass required)
  - Make all sort groups binnable (to greater or lesser results)
  - Add sort by pitch
  - Deprecate multiple options
  - linting, docs + locales 
tools/sort/sort.py