face module apply style

This commit is contained in:
Vladimir Mandic
2024-02-03 12:41:52 -05:00
parent df9b509aca
commit ace8c3d33d
5 changed files with 10 additions and 12 deletions
-4
View File
@@ -12,11 +12,7 @@
## TODO for Dev merge
- update docs
- face apply style
- embeddings disappear
- control reference mode
- control init image same as control, separate init image
- control t2i-adapter with ip-adapter
## Update for 2023-02-02
+1
View File
@@ -107,6 +107,7 @@ class Script(scripts.Script):
input_images[i] = Image.open(image['name'])
source_image = input_images[0]
processing.process_init(p)
if mode == 'FaceID': # faceid runs as ipadapter in its own pipeline
from modules.face.faceid import face_id
from modules.face.insightface import get_app
-1
View File
@@ -32,7 +32,6 @@ def face_id(p: processing.StableDiffusionProcessing, app, source_image: Image.Im
shared.log.error(f'FaceID download failed: model={model} file={ip_ckpt}')
return None
processing.process_init(p)
if override:
shared.sd_model.scheduler = diffusers.DDIMScheduler(
num_train_timesteps=1000,
+4 -2
View File
@@ -34,8 +34,9 @@ def instant_id(p: processing.StableDiffusionProcessing, app, source_image, stren
shared.log.debug(f'InstantID face: score={face.det_score:.2f} gender={"female" if face.gender==0 else "male"} age={face.age} bbox={face.bbox}')
shared.log.debug(f'InstantID loading: model={REPO_ID}')
face_adapter = hf.hf_hub_download(repo_id=REPO_ID, filename="ip-adapter.bin")
if controlnet_model is None:
if controlnet_model is None or not cache:
controlnet_model = ControlNetModel.from_pretrained(REPO_ID, subfolder="ControlNetModel", torch_dtype=devices.dtype, cache_dir=shared.opts.diffusers_dir)
controlnet_model.to(devices.device, devices.dtype)
processing.process_init(p)
@@ -57,12 +58,13 @@ def instant_id(p: processing.StableDiffusionProcessing, app, source_image, stren
shared.sd_model.load_ip_adapter_instantid(face_adapter, scale=strength)
shared.sd_model.set_ip_adapter_scale(strength)
if not ((shared.opts.diffusers_model_cpu_offload or shared.cmd_opts.medvram) or (shared.opts.diffusers_seq_cpu_offload or shared.cmd_opts.lowvram)):
print('HERE1')
shared.sd_model.to(shared.device, devices.dtype) # move pipeline if needed, but don't touch if its under automatic managment
# pipeline specific args
orig_prompt_attention = shared.opts.prompt_attention
shared.opts.data['prompt_attention'] = 'Fixed attention' # otherwise need to deal with class_tokens_mask
p.task_args['prompt'] = p.prompt # override all logic
p.task_args['prompt'] = p.all_prompts[0] # override all logic
p.task_args['image_embeds'] = face_emb
p.task_args['image'] = face_kps
p.task_args['controlnet_conditioning_scale'] = float(conditioning)
+5 -5
View File
@@ -18,14 +18,14 @@ def photo_maker(p: processing.StableDiffusionProcessing, input_images, trigger,
# validate prompt
trigger_ids = shared.sd_model.tokenizer.encode(trigger) + shared.sd_model.tokenizer_2.encode(trigger)
prompt_ids1 = shared.sd_model.tokenizer.encode(p.prompt)
prompt_ids2 = shared.sd_model.tokenizer_2.encode(p.prompt)
prompt_ids1 = shared.sd_model.tokenizer.encode(p.all_prompts[0])
prompt_ids2 = shared.sd_model.tokenizer_2.encode(p.all_prompts[0])
for t in trigger_ids:
if prompt_ids1.count(t) != 1:
shared.log.error(f'PhotoMaker: trigger word not matched in prompt: {trigger} ids={trigger_ids} prompt={p.prompt} ids={prompt_ids1}')
shared.log.error(f'PhotoMaker: trigger word not matched in prompt: {trigger} ids={trigger_ids} prompt={p.all_prompts[0]} ids={prompt_ids1}')
return None
if prompt_ids2.count(t) != 1:
shared.log.error(f'PhotoMaker: trigger word not matched in prompt: {trigger} ids={trigger_ids} prompt={p.prompt} ids={prompt_ids1}')
shared.log.error(f'PhotoMaker: trigger word not matched in prompt: {trigger} ids={trigger_ids} prompt={p.all_prompts[0]} ids={prompt_ids1}')
return None
# create new pipeline
@@ -49,7 +49,7 @@ def photo_maker(p: processing.StableDiffusionProcessing, input_images, trigger,
shared.opts.data['prompt_attention'] = 'Fixed attention' # otherwise need to deal with class_tokens_mask
p.task_args['input_id_images'] = input_images
p.task_args['start_merge_step'] = int(start * p.steps)
p.task_args['prompt'] = p.prompt # override all logic
p.task_args['prompt'] = p.all_prompts[0] # override all logic
photomaker_path = hf.hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model", cache_dir=shared.opts.diffusers_dir)
shared.log.debug(f'PhotoMaker: model={photomaker_path} images={len(input_images)} trigger={trigger} args={p.task_args}')