              if not self.valid_extension(face):
                  continue
              filename = os.path.splitext(face)[0]
              file_extension = os.path.splitext(face)[1]
              index = 0
              original_file = ""
              if not self.dfl:
                  index = int(filename[filename.rindex("_") + 1:])
                  original_file = "{}".format(filename[:filename.rindex("_")])
              yield {"face_fullname": face,
                     "face_name": filename,
                     "face_extension": file_extension,
                     "frame_name": original_file,
                     "face_index": index}
  
      def load_items(self):
          """ Load the face names into dictionary """
          faces = dict()
          for face in self.file_list_sorted:
 
</s> remove             yield {"frame_fullname": frame,
                   "frame_name": filename,
                   "frame_extension": file_extension}
 </s> add             retval = {"frame_fullname": frame,
                      "frame_name": filename,
                      "frame_extension": file_extension}
            logger.trace(retval)
            yield retval </s> remove     def rename_faces(self):
        """ Rename the aligned faces to match their "
            new index in alignments file """
        current_frame = ""
        current_index = 0
        rename_count = 0
        for face in tqdm(self.items.file_list_sorted,
                         desc="Renaming aligned faces",
                         total=self.items.count):

            if face["frame_name"] not in self.removed:
                continue
            current_index, current_frame = self.set_image_index(
                current_index,
                current_frame,
                face["frame_name"])
            if current_index != face["face_index"]:
                rename_count += self.rename_file(face,
                                                 current_frame,
                                                 current_index)

            current_index += 1
        if rename_count == 0:
            logger.info("No files were renamed. Exiting")
            return
        logger.info("%s face(s) were renamed to match with alignments file", rename_count)

    @staticmethod
    def set_image_index(index, current, original):
        """ Set the current processing image and index """
        idx = 0 if current != original else index
        return idx, original

    def rename_file(self, face, frame_name, index):
        """ Rename the selected file """
        old_file = face["face_name"] + face["face_extension"]
        new_file = "{}_{}{}".format(frame_name,
                                    str(index),
                                    face["face_extension"])
        src = os.path.join(self.items.folder, old_file)
        dst = os.path.join(self.items.folder, new_file)
        os.rename(src, dst)
        logger.verbose("Renamed '%s' to '%s'", src, dst)
        return 1

 </s> add  </s> remove         for face in self.faces.file_list_sorted:
 </s> add         for face in tqdm(self.faces.file_list_sorted, desc="Converting DFL Faces"): </s> remove 
    def map_face_names(self, alignments, sorted_alignments, frame):
        """ Map the old and new indexes for face renaming """
        map_faces = list()
        if not self.faces:
            return map_faces
        for idx, alignment in enumerate(alignments):
            idx_new = sorted_alignments.index(alignment)
            mapping = [{"old_name": face["face_fullname"],
                        "new_name": "{}_{}{}".format(frame,
                                                     idx_new,
                                                     face["face_extension"])}
                       for face in self.faces.file_list_sorted
                       if face["frame_name"] == frame
                       and face["face_index"] == idx]
            if not mapping:
                logger.warning("No face image found for frame '%s' at index %s", frame, idx)
            map_faces.extend(mapping)
        return map_faces

    def rename_faces(self, map_faces):
        """ Rename faces
            Done in 2 iterations as two files cannot share the same name """
        temp_ext = ".temp_move"
        for action in ("temp", "final"):
            for face in map_faces:
                old = face["old_name"]
                new = face["new_name"]
                if old == new:
                    continue
                old_file = old if action == "temp" else old + temp_ext
                new_file = old + temp_ext if action == "temp" else new
                src = os.path.join(self.faces.folder, old_file)
                dst = os.path.join(self.faces.folder, new_file)
                os.rename(src, dst)
                if action == "final":
                    logger.verbose("Renamed '%s' to '%s'", old, new)
 </s> add         return reindexed
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
              if not self.valid_extension(face):
                  continue
              filename = os.path.splitext(face)[0]
              file_extension = os.path.splitext(face)[1]
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
            face_hash = hash_image_file(os.path.join(self.folder, face))
            retval = {"face_fullname": face,
                      "face_name": filename,
                      "face_extension": file_extension,
                      "face_hash": face_hash}
            logger.trace(retval)
            yield retval
  
      def load_items(self):
          """ Load the face names into dictionary """
          faces = dict()
          for face in self.file_list_sorted:
keep keep keep keep replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Add Face Hashes to Alignments (#550)

* Convert main scripts to use face hashes

* Alignment tool: Use hashes, add logging, add face rename function

* More logging. Update Manual tool to work with hashing 
tools/lib_alignments/media.py