faceswap icon indicating copy to clipboard operation
faceswap copied to clipboard

add max scale option

Open aopsr opened this issue 1 year ago • 1 comments

This PR adds the option to set a max scale parameter in conversion. Max scale is defined at the maximum ratio of the longest edge of any face's original_roi in the source frame to the model output size.

Example 1: Let max scale be 2 and model have a 256px output size. Image contains a face that is 768x400 px. Max ratio = 768/256 = 3. Therefore, the image will be scaled by 2/3 before pasting the predicted face.

Example 2: Let max scale be 1.5 and model have a 512px output size. Image contains a face that is 400x300 px. Max ratio = 400/512 < 1. Therefore, the image will not be scaled.

Example 3: Let max scale be 0 (default). The image will not be scaled.

Setting max_scale to a number less than 2 produces results that are far more realistic visually when the model resolution is small relative to dest.

This feature checks if the input is a folder of images, not a video, before applying the appropriate transformations. Video frames will need (trivial) further work to be compatible with variable resolution frames. However, it does not make sense to generate a video from different resolution frames. Therefore, this feature was not included.

aopsr avatar Sep 12 '22 19:09 aopsr

Hello @aopsr! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 437:1: W293 blank line contains whitespace

Line 137:1: W293 blank line contains whitespace

Line 789:100: E501 line too long (156 > 99 characters)

Line 248:100: E501 line too long (198 > 99 characters) Line 253:52: E128 continuation line under-indented for visual indent Line 254:52: E128 continuation line under-indented for visual indent Line 255:52: E128 continuation line under-indented for visual indent Line 256:52: E128 continuation line under-indented for visual indent Line 257:52: E128 continuation line under-indented for visual indent Line 257:100: E501 line too long (104 > 99 characters)

Line 814:1: W293 blank line contains whitespace Line 829:54: E231 missing whitespace after ','

Line 774:1: W293 blank line contains whitespace

pep8speaks avatar Sep 12 '22 19:09 pep8speaks

Sorry I have sat on this for so long. I am unsure of the value add here.

If I am understanding correctly, the final output image is resized based on the size of the output of the model. If this is the case, then I have the following reservations:

  • Faceswap is mostly used for videos, which would not be covered by this PR, so would be adding an option for a very limited use case
  • The resizing of images can be done fairly easily on either the original images fed to Faceswap or on the final output images generated from Faceswap. It could be argued (in the latter case) that it is preferable to see the swapped output before making a judgement call on whether the image should be resized.
  • The only potential benefit is if you are swapping onto lots of images of lots of different sizes, as otherwise 'output scaling' can achieve much the same effect

torzdf avatar Oct 24 '22 13:10 torzdf

Yes exactly, the inspiration behind the PR was a folder of 1000+ HQ photos, each with a different size face. Some had a small face and the original resolution could be preserved without pixelation of the swap. Others were close-up and would benefit from resizing before swapping. This PR would allow faceswap to resize each image precisely.

This PR doesn't need to be merged if you feel it is not marginally beneficial - the code base has changed quite a bit since this PR was opened anyways and would need some adjusting.

aopsr avatar Oct 24 '22 23:10 aopsr

I do appreciate the PR, and the work you have put in, but I am going to close this one off. I feel yours is quite the edge case, and I'm not convinced that there would be considerable benefit to adjusting the scale of the image prior to swapping, vs resizing the image after the swap has occurred (although I do appreciate that this might be quite an unwieldy task when you are working with 1000s of images).

Ultimately I need to balance benefit to the project against my time needed to support any features.

Thank you again for the PR, and please do not be put off from contributing in the future.

torzdf avatar Nov 01 '22 10:11 torzdf