Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mask importing to the mask tool #1376

Merged
merged 6 commits into from
Mar 12, 2024
Merged

Conversation

torzdf
Copy link
Collaborator

@torzdf torzdf commented Mar 12, 2024

This PR adds the ability to import masks into faceswap alignment files/PNG Headers for extracted faces.

Masks can be imported/exported as either the stored 'face-aligned' mask, or as a full-frame mask for the entire frame/image

Export masks

Masks can be exported from faceswap for editing in external tools. They will be output as either aligned face masks, or as full frame masks, depending on what type of input (frames or faces) that you feed the mask tool, and which works best for your workflow.

  • Set input to either the frames you wish to export masks from or to the extracted faces folder
  • Set the input-type to correspond with whether you are passing frames in, or a folder of faces
    • The exported masks will correspond directly to the selected input-type
  • Select the mask type (masker) that you wish to export
  • Set processing to output
  • Set the output-folder to the destination to export the masks to

Exported masks will be placed in the output folder as single channel (grayscale) images, and will be named correctly for importing (after editing)

Import masks

Masks can be imported, after editing/creation in external tools. Masks can be created in most image formats, but will ultimately be stored internally as single-channel 8-bit grayscale images.

Note: batch-mode is not supported for mask import

  • Set input to either the frames you wish to import masks for or to the extracted faces folder
  • Optionally specify an alignments file location
    • recommended if the input-type is faces, to ensure that your imported masks also get updated to your alignments file
  • Set the input-type to correspond with whether you are passing frames in, or a folder of faces
    • The masks that you are importing must be of the same type as the source input. IE: If you have selected the input type as frames the masks that you are importing must also be annotated for the full frame
  • Select the masker as custom
    • This is a security step to make sure that you do not accidentally overwrite any other mask types that you may have annotated
    • Imported masks will always be stored as the custom mask type
  • Set processing to import
  • Set mask-path to the folder that contains the masks you wish to import
    • If your input/source is a folder of images (be it frames or faces) then the filename of the masks must be exactly the same as the filenames within your source folder (excluding the file extension)
    • If your input is a video file, then the masks can be named anything you please, but the filename must end with the frame number (excluding the file extension)
      • Frame numbering must start at 1 (that is, the first frame in any video file must be 1 and not 0)
      • The frame number can be separated from the rest of the filename by any non-numeric character (or the filename can just be the frame number, with no other text)
      • The frame number can be padded with any number of zeros
  • Set the centering that you wish to store the masks at. Unless you are masking for full-head swaps, then face will always be the correct choice here
  • Set the storage-size that you wish faceswap to store the masks at. Generally, masks do not need to be stored at a very high resolution. By default this is 128px, which works fine for most use cases. You can store custom masks at a higher resolution, but this will lead to larger filesizes, and may lead to longer processing times (when training or converting)

@torzdf torzdf merged commit 7a16f75 into deepfakes:staging Mar 12, 2024
5 of 11 checks passed
@torzdf torzdf deleted the mask_import branch April 16, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant