Package: person-swap
Person SwapInfo how to use system and how models worksChanging the photo (face)4 models (files) are used to change the face:Detector - checks if a face exists in a given photo and cuts it out if it does;Recogniser - extracts the facial features from the cropped photo to be used for the change;Generator - Creates a new face from the facial features of the source face to the facial expression of the target;Mask detector - extracts the facial contour mask during the face change in the source photo (you can use libraries in CV2 anyway), but the model is more accurate as far as I have noticed.Generator operation - the recognition model extracts the identity of the face in the photo (Ts for source or Tt for target).The face change itself is performed by the generator, which consists of:The encoder - extracts the features of the target face;Identity Change Module - transfers the identity extracted from the source image to target photo features;Decoder - reconstructs a modified image of target photo features and source identity.![](docs/img.png)Changing the sound (voice)The paddlespeech library is used, which can use existing or newly developed models for voice replacement. The models used for voice replacement in the project are:Speech to text:Transformer - text is extracted from the source audio;Text to speechPhonetics class - converts text to phonetic data;Encoder - extracts features of the target voice;Acoustic model - matches the features of the source text with the features of the target sound;Vocoder - text features converted to voice by the target voice features.![](docs/voice_schema.png)Changing the video (face and/or voice):Separates the audio of the target video (if it exists);If the source is a video, the first frame containing the person is taken (if the source is a photo, nothing is done);Changes the face in the video (if the source is a photo or video):Repeat over each frame;changing the face in the frame (photo) (as in an ordinary photo);the new frame (target photo with the face of the source) is saved in the list);after iteration, the list of frames is converted into a video;Voice in the video is changed (if the source is a video or audio file):If the target or source did not have a voice - do nothingIf there is only the voice of the target, it is added to the created video;If there is both a source and a target voice - the source's voice is replaced by the target's voice (as in voice replacement).![](docs/video_schema.png)MIT LicenseCopyright (c) 2023 Segal011Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.