machineminded / Fooocus-inswapper

Focus on prompting and generating with an inswapper integration
GNU General Public License v3.0
76 stars 16 forks source link

inswapper does not fail gracefully when targeted index in UI is higher than number of faces detected in the image. #19

Open ujl123 opened 7 months ago

ujl123 commented 7 months ago

Read Troubleshoot

[x] I confirm that I have read the Troubleshoot guide before making this issue.

Describe the problem When you try to target a face index that is greater than the actual number of faces detected, This is very easy to replicate. If you are swapping an image with x numbers of faces, in " Target Image Index " set it to a number greater than x.

Proposal: This should instead skip and move on to the next task rather than throwing an error and halting.

Full Console Log Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}} inswapper-shape: [1, 3, 128, 128] Source faces: 1 Target faces: 2 Replacing specific face(s) in the target image with specific face(s) from the source image Traceback (most recent call last): File "C:\Fooocus inswapper\Fooocus-inswapper\modules\async_worker.py", line 860, in worker handler(task) File "C:\Fooocus inswapper\Fooocus-inswapper\venv\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "C:\Fooocus inswapper\Fooocus-inswapper\venv\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(args, **kwargs) File "C:\Fooocus inswapper\Fooocus-inswapper\modules\async_worker.py", line 812, in handler imgs = perform_face_swap(imgs, inswapper_source_image, inswapper_target_image_index) File "C:\Fooocus inswapper\Fooocus-inswapper\modules\face_swap.py", line 14, in perform_face_swap result_image = process([source_image], item, "-1", f"{int(inswapper_target_image_index)}", "../inswapper/checkpoints/inswapper_128.onnx") File "C:\Fooocus inswapper\Fooocus-inswapper\inswapper\swapper.py", line 179, in process raise ValueError(f"Target index {target_index} is higher than the number of faces in the target image") ValueError: Target index 2 is higher than the number of faces in the target image

machineminded commented 7 months ago

Thanks for the report. Been meaning to get this one recorded as an issue and resolved. Should be an easy enough fix.

machineminded commented 7 months ago

In general I think index out of bounds errors need addressed because sometimes inswapper is enabled, but there is not a face to swap so it fails.