TencentARC/PhotoMaker

TypeError: PhotoMakerIDEncoder_CLIPInsightfaceExtendtoken.forward() missing 1 required positional argument: 'id_embeds'

Closed this issue · 7 comments

测试 photomaker_demo.ipynb 出错了:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 26
     23 if start_merge_step > 30:
     24     start_merge_step = 30
---> 26 images = pipe(
     27     prompt=prompt,
     28     input_id_images=input_id_images,
     29     negative_prompt=negative_prompt,
     30     num_images_per_prompt=num_images_per_prompt,
     31     num_inference_steps=num_steps,
     32     start_merge_step=start_merge_step,
     33     generator=generator,
     34 ).images
     36 # 显示并保存结果
     37 grid = image_grid(images, 1, len(images), size_after_resize=512)   # 缩小图片方便显示

File ~/miniconda3/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File ~/PhotoMaker/photomaker/pipeline.py:708, in PhotoMakerStableDiffusionXLPipeline.__call__(self, prompt, prompt_2, height, width, num_inference_steps, timesteps, sigmas, denoising_end, guidance_scale, negative_prompt, negative_prompt_2, num_images_per_prompt, eta, generator, latents, prompt_embeds, negative_prompt_embeds, pooled_prompt_embeds, negative_pooled_prompt_embeds, ip_adapter_image, ip_adapter_image_embeds, output_type, return_dict, cross_attention_kwargs, guidance_rescale, original_size, crops_coords_top_left, target_size, negative_original_size, negative_crops_coords_top_left, negative_target_size, clip_skip, callback_on_step_end, callback_on_step_end_tensor_inputs, input_id_images, start_merge_step, class_tokens_mask, id_embeds, prompt_embeds_text_only, pooled_prompt_embeds_text_only, **kwargs)
    706     prompt_embeds = self.id_encoder(id_pixel_values, prompt_embeds, class_tokens_mask, id_embeds)
    707 else:
--> 708     prompt_embeds = self.id_encoder(id_pixel_values, prompt_embeds, class_tokens_mask)
    710 bs_embed, seq_len, _ = prompt_embeds.shape
    711 # duplicate text embeddings for each generation per prompt, using mps friendly method

File ~/miniconda3/lib/python3.10/site-packages/torch/nn/modules/module.py:1532, in Module._wrapped_call_impl(self, *args, **kwargs)
   1530     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1531 else:
-> 1532     return self._call_impl(*args, **kwargs)

File ~/miniconda3/lib/python3.10/site-packages/torch/nn/modules/module.py:1541, in Module._call_impl(self, *args, **kwargs)
   1536 # If we don't have any hooks, we want to skip the rest of the logic in
   1537 # this function, and just call forward.
   1538 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1539         or _global_backward_pre_hooks or _global_backward_hooks
   1540         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1541     return forward_call(*args, **kwargs)
   1543 try:
   1544     result = None

TypeError: PhotoMakerIDEncoder_CLIPInsightfaceExtendtoken.forward() missing 1 required positional argument: 'id_embeds'

我也有同样的问题

who can help me

The photomaker_demo.ipynb file hasn't been updated to the latest version yet. You can directly run the scripts in the inference_scripts folder.

so ,must have id_embeds now?I add a id_embeds is ok.

add this into run.py from inference_scripts

import numpy as np
from photomaker import FaceAnalysis2,analyze_faces
face_detector = FaceAnalysis2(providers=['CUDAExecutionProvider'], allowed_modules=['detection', 'recognition'])
face_detector.prepare(ctx_id=0, det_size=(640, 640))
id_embed_list = []

for img in input_id_images:
img = np.array(img)
img = img[:, :, ::-1]
faces = analyze_faces(face_detector, img)
if len(faces) > 0:
id_embed_list.append(torch.from_numpy((faces[0]['embedding'])))

if len(id_embed_list) == 0:
raise ValueError(f"No face detected in input image pool")

id_embeds = torch.stack(id_embed_list)

add this into run.py from inference_scripts

import numpy as np from photomaker import FaceAnalysis2,analyze_faces face_detector = FaceAnalysis2(providers=['CUDAExecutionProvider'], allowed_modules=['detection', 'recognition']) face_detector.prepare(ctx_id=0, det_size=(640, 640)) id_embed_list = []

for img in input_id_images: img = np.array(img) img = img[:, :, ::-1] faces = analyze_faces(face_detector, img) if len(faces) > 0: id_embed_list.append(torch.from_numpy((faces[0]['embedding'])))

if len(id_embed_list) == 0: raise ValueError(f"No face detected in input image pool")

id_embeds = torch.stack(id_embed_list)

It works!
OK!