# AI : Faceswap : Sorting & Grouping Applies clustering algorithm (e.g., hierarchical clustering or k-means) or distance metric (e.g., cosine similarity) to group similar faces. ``` -s|--sort-by METHOD # rename files -g|--group-by METHOD # move files into bin -k|--keep # copy files instead of moving them ``` > [!NOTE] > If you only specify a group method, the sort method will be set to that group method. (You can sort without grouping, but you can't group without sorting.) ## Methods ``` blur : faces by blurriness blur-fft : faces by fft filtered blurriness distance : faces by the estimated distance of the alignments from an 'average' face This can be useful for eliminating misaligned faces. Sorts from most like an average face to least like an average face. face : faces using VGG Face2 by face similarity This uses a pairwise clustering algorithm to check the distances between 512 features on every face in your set and order them appropriately. face-cnn : faces by their landmarks face-cnn-dissim : like 'face-cnn' but sorts by dissimilarity yaw : faces by Yaw (rotation left to right) pitch : faces by Pitch (rotation up and down) roll : faces by Roll (rotation) Aligned faces should have a roll value close to zero. The further the Roll value from zero the higher liklihood the face is misaligned. hist : faces by their color histogram hist-dissim : like 'hist' but sorts by dissimilarity color-gray : images by the average intensity of the converted grayscale color channel color-black : images by their number of black pixels Useful when faces are near borders and a large part of the image is black. color-luma : images by the average intensity of the converted Y color channel Bright lighting and oversaturated images will be ranked first. color-green : images by the average intensity of the converted Cg color channel Green images will be ranked first and red images will be last. color-orange : images by the average intensity of the converted Co color channel Orange images will be ranked first and blue images will be last. size : images by their size in the original frame Faces further from the camera and from lower resolution sources will be sorted first, whilst faces closer to the camera and from higher resolution sources will be sorted last. UPDATE: It's actually the opposite! ``` ## Grouping ``` -b|--bins # 1-100; number of bins for grouping -t|--threshold # -1-10; control the strength of grouping (-1 = let Faceswap choose) ``` ``` face, face-cnn, face-cnn-dissim, hist, hist-dissim Use --threshold: face-cnn 7.2 should be enough, with 4 being very discriminating hist 0.3 should be enough, with 0.2 being very discriminating face between 0.1 (more bins) to 0.5 (fewer bins) should be about right color-black, color-gray, color-luma, color-green, color-orange Each image is allocated to a bin by the percentage of color pixels that appear in the image. yaw, pitch, roll Each image is allocated to a bin by the number of degrees the face is orientated from center. blur, blur-fft, distance, size The minimum and maximum values are taken for the chosen sort metric. The bins are then populated with the results from the group sorting. ```