PhotoMaker icon indicating copy to clipboard operation
PhotoMaker copied to clipboard

Noisy image generations

Open machineminded opened this issue 1 year ago • 6 comments

Hello, I am getting noisy generations and the likeness is not there. Here is my code:

import torch
import os
import sys
sys.path.append('../photomaker')

from diffusers import EulerDiscreteScheduler,  DPMSolverMultistepScheduler, AutoencoderKL
from photomaker import PhotoMakerStableDiffusionXLPipeline
from huggingface_hub import hf_hub_download

import modules.default_pipeline as pipeline

base_model_path = pipeline.model_base.filename
photomaker_ckpt = hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model")

def generate_photomaker(prompt, input_id_images, negative_prompt, steps, seed, width, height, guidance_scale):
    print(f"Using base model: {base_model_path} for PhotoMaker")
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

    pipe = PhotoMakerStableDiffusionXLPipeline.from_single_file(
        base_model_path,
        torch_dtype=torch.bfloat16,
        use_safetensors=True,                
        variant="fp16"
    ).to(device)

    pipe.load_photomaker_adapter(
        os.path.dirname(photomaker_ckpt),
        subfolder="",
        weight_name=os.path.basename(photomaker_ckpt),
        trigger_word="img"
    )

    pipe.id_encoder.to(device)
    
    pipe.scheduler =  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)

    pipe.fuse_lora()

    generator = torch.Generator(device=device).manual_seed(seed)

    images = pipe(
        prompt=prompt,
        input_id_images=input_id_images,
        negative_prompt=negative_prompt,
        num_images_per_prompt=1,
        num_inference_steps=steps,
        width=width,
        height=height,
        start_merge_step=10,
        generator=generator,
        guidance_scale=guidance_scale
    ).images

    return images

image (18)

image

Any idea what might be going on?

image

machineminded avatar Jan 23 '24 20:01 machineminded

I found that you are using dpmsolver. Could you increase the number of steps and try again?

Paper99 avatar Jan 24 '24 15:01 Paper99

Maybe you can also choose to use the quality option

Paper99 avatar Jan 24 '24 15:01 Paper99

Hello. I did more experimenting today, and it appears to be due to my simple prompt and lack of a negative prompt. Apply a prompt from the style seems to resolve it. I will post my findings in the morning. Thank you.

machineminded avatar Jan 25 '24 04:01 machineminded

Cool! Thanks again for your efforts!

Paper99 avatar Jan 25 '24 04:01 Paper99

At this point I'm pretty sure it's just the prompting. I am working on integrating the Fooocus prompt system into the diffusers pipeline. I have combined it with inswapper_128 for some pretty great results 👍👍👍.

image

machineminded avatar Jan 25 '24 16:01 machineminded

It's really cool!

Paper99 avatar Jan 25 '24 16:01 Paper99

It seems like the euler scheduler generates better images than DPM++. I even tried adding euler_at_final but the generations with DPM++ still are noisy. Even with 60+ steps.

DPMSolverMultistepScheduler(algorithm_type="sde-dpmsolver++", euler_at_final=True)

machineminded avatar Jan 27 '24 14:01 machineminded

DPMSolverMultistepScheduler(algorithm_type="sde-dpmsolver++", euler_at_final=True); DPM_hash($sove)=>solution;

akshatbisht22 avatar Feb 06 '24 07:02 akshatbisht22

@machineminded Nice works! Could you please elaborate a bit more on how you combining photomaker with inswapper_128 for these nice photos?

CHELSEA234 avatar Feb 12 '24 21:02 CHELSEA234

@machineminded Nice works! Could you please elaborate a bit more on how you combining photomaker with inswapper_128 for these nice photos?

@CHELSEA234 I am using my fork of Fooocus with Inswapper and Photomaker! Soon instantID will be integrated as well.

To elaborate, I use PhotoMaker to create a likeness "substrate" and then inswapper lays the face on top.

machineminded avatar Feb 13 '24 00:02 machineminded