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

Bug in video swap #9

Open
dxcanh opened this issue Sep 11, 2024 · 3 comments
Open

Bug in video swap #9

dxcanh opened this issue Sep 11, 2024 · 3 comments

Comments

@dxcanh
Copy link

dxcanh commented Sep 11, 2024

I got a bug:
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "C:\daihoc\Lab\filter\face_swap\ApplySwap.py", line 34, in
video_face_swap()
File "C:\daihoc\Lab\filter\face_swap\ApplySwap.py", line 27, in video_face_swap
swapped = f2f.swap_to_face_in_video(faces="caprio", video=vf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\daihoc\Lab\filter\face_swap\core\mixins_video_swap.py", line 63, in swap_to_face_in_video
new_video = VideoFile().from_video_stream(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\media_toolkit\utils\dependency_requirements.py", line 18, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\media_toolkit\core\video\video_file.py", line 181, in from_video_stream
temp_video_file_path = video_from_image_generator(video_gen_wrapper, frame_rate=frame_rate, save_path=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\media_toolkit\utils\dependency_requirements.py", line 18, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\media_toolkit\core\video\video_utils.py", line 138, in video_from_image_generator
for i, img in image_generator:
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\tqdm\std.py", line 1181, in iter
for obj in iterable:
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\media_toolkit\core\video\video_file.py", line 165, in _frame_gen
for frame in video_audio_stream:
File "C:\daihoc\Lab\filter\face_swap\core\mixins_image_swap.py", line 177, in swap_to_face_generator
swapped = self._swap_faces(source_faces, target_faces, target_image, enhance_face_model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\daihoc\Lab\filter\face_swap\core\mixins_image_swap.py", line 136, in _swap_faces
result = self._face_swapper.get(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\insightface\model_zoo\inswapper.py", line 50, in get
latent = source_face.normed_embedding.reshape((1,-1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'normed_embedding'

Can you fix help me :(

@dxcanh
Copy link
Author

dxcanh commented Sep 11, 2024

@w4hns1nn please help me

@w4hns1nn
Copy link
Collaborator

w4hns1nn commented Sep 13, 2024

Hey dxvan.

looks like there's a face embedding missing in the stored faces.
Troubleshoot:

  1. Did you add caprio before to the face embeddings with "f2f.add_face("caprio", "path/to/my_portrait_image.jpg", save=True)"?
  2. Was your face correctly added? Sometimes insightface has problems of detecting faces. You can check if the swap generally works by just swapping one image in the beginning.

Let me know if that solves your issue. Maybe you can attach more of your code? If there's a problem with the video itself consider to send it via wetransfer or on a similar way so that I can look into it.

Nonetheless, I'd like to dive deeper in here, because the error should be catched and a better error message should be presented to the user.

@Kyeonghyeon-Park
Copy link

Dear @w4hns1nn , I have same issues.
I attached my code and console messages.
When I used KH image file with swap_img_to_img function, it works.
Additionally, when I do swap_img_to_img function with KH image file and the specific frame of the video, it works.

The below is my code.

f2f = Face2Face(device_id=0)
embedding = f2f.add_face("KH", r"path_to_source_image.jpg", save=True)
swapped = f2f.swap(media=r"path_to_target_video.mp4", faces="KH")
swapped.save('output.mp4')

I got these kind of messages until the end.

2it [00:00, 3.37it/s]Error in swapping frame 1 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
Error in swapping frame 2 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
4it [00:01, 3.89it/s]Error in swapping frame 3 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
Error in swapping frame 4 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
6it [00:01, 3.97it/s]Error in swapping frame 5 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
Error in swapping frame 6 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
Error in swapping frame 7 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image
Error in swapping frame 8 to KH: 'list' object has no attribute 'normed_embedding'. Skipping image

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

No branches or pull requests

3 participants