  
  # faceswap imports
  from lib.serializer import get_serializer_from_filename
  from lib.align import AlignedFace, DetectedFace
  from lib.image import FacesLoader, read_image
  from lib.utils import FaceswapError
  from plugins.extract.recognition.vgg_face2_keras import VGGFace2 as VGGFace
  from plugins.extract.pipeline import Extractor, ExtractMedia
  
  logger = logging.getLogger(__name__)  # pylint: disable=invalid-name
 
</s> remove #: tools/sort/cli.py:82 tools/sort/cli.py:109 tools/sort/cli.py:121
#: tools/sort/cli.py:132
 </s> add #: tools/sort/cli.py:85 tools/sort/cli.py:112 tools/sort/cli.py:124
#: tools/sort/cli.py:135 </s> remove         faces.extend(deepcopy(self._faces_at_frame_index(idx)))
 </s> add         # aligned_face cannot be deep copied, so remove and recreate
        to_copy = self._faces_at_frame_index(idx)
        for face in to_copy:
            face.aligned = None
        copied = deepcopy(to_copy)

        for old_face, new_face in zip(to_copy, copied):
            old_face.load_aligned(None)
            new_face.load_aligned(None)

        faces.extend(copied) </s> remove         face.mask = self._extractor.get_masks(frame_index, face_index)
 </s> add 
from lib.image import FacesLoader, read_image, read_image_meta_batch
  
  # faceswap imports
  from lib.serializer import get_serializer_from_filename
  from lib.align import AlignedFace, DetectedFace
from lib.image import FacesLoader, read_image, read_image_meta_batch
  from lib.utils import FaceswapError
  from plugins.extract.recognition.vgg_face2_keras import VGGFace2 as VGGFace
  from plugins.extract.pipeline import Extractor, ExtractMedia
  
  logger = logging.getLogger(__name__)  # pylint: disable=invalid-name
keep keep keep keep replace keep keep keep keep keep
 Add Misalignment Detection
  - lib.align.AlignedFace - Add average_distance property (distance from mean_face)
  - tools.manual - Add misaligned Faces filter
  - tools.sort - Add sort by distance (misaligned sort)Add "Misaligned Faces" filter to manual tool 
tools/sort/sort.py