This commit implements several improvements to the face swapping pipeline,
focusing on enhancing output quality and providing optimizations for performance.
Key changes include:
1. **Upgraded Face Swapping Model:**
* Switched from `inswapper_128_fp16.onnx` to the full-precision `inswapper_128.onnx` model. This is expected to provide higher fidelity face swaps.
* Updated the model download logic in `modules/processors/frame/face_swapper.py` accordingly.
2. **Optimized Face Enhancement (GFPGAN):**
* Modified `modules/processors/frame/face_enhancer.py` to set the `upscale` parameter for `GFPGANer` from `1` to `2`. This can improve the detail and perceived quality of faces processed by the enhancer.
3. **Improved Color Matching for Swapped Faces:**
* Implemented statistical color transfer in `modules/processors/frame/face_swapper.py`. This matches the color profile of the swapped face region to the original target face's region, leading to more seamless and natural blending.
* This feature is controlled by a new (assumed) global flag `statistical_color_correction`.
4. **Optimized Mouth Masking Logic:**
* Reduced default `forehead_extension_factor` in `create_face_mask` from `5.0` to `2.5` for slightly faster mask computation.
* Reduced default `mouth_mask_blur_kernel_size` in `create_lower_mouth_mask` from `(15, 15)` to `(9, 9)` to speed up this blur operation.
* These parameters are now fetched using `getattr` to allow future configuration via global variables (e.g., `modules.globals.forehead_extension_factor`).
5. **Performance Analysis & Other Considerations:**
* Identified model inference (swapper, enhancer) as primary GPU workloads.
* Noted that mouth masking (CPU-bound) and the new color correction add overhead. Making these features optional (which they are, via global flags like `mouth_mask` and `statistical_color_correction`) is important for you to balance quality and performance.
* Reviewed face detection usage and found it to be reasonably efficient for the modular pipeline structure.
These changes aim to significantly improve the visual quality of the face swaps and provide some performance tuning options.
Followed the `README` but ran into some errors running it locally. Made a few tweaks and got it working on my M3 PRO. Found this PR (Failing to run on Apple Silicon Mac M3) and thought improving the instructions might help others. Hope this helps!
great tool guys, thx a lot
- Add explicit checks for face detection results (source and target faces).
- Handle cases when face embeddings are not available, preventing AttributeError.
- Provide meaningful log messages for easier debugging in future scenarios.
Made changes for apple silicon.
Or getting
ERROR: Could not find a version that satisfies the requirement torch==2.5.1+cu118 (from versions: 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 2.5.0, 2.5.1, 2.6.0)
ERROR: No matching distribution found for torch==2.5.1+cu118