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

how to replace ddim with dpm-solver in the origin stable diffusion? (img2img) #20

Open
ssxxx1a opened this issue Dec 8, 2022 · 2 comments

Comments

@ssxxx1a
Copy link

ssxxx1a commented Dec 8, 2022

i had tried to replace

z_enc = sampler.stochastic_encode(init_latent, torch.tensor([t_enc]*batch_size).to(device)) 
samples = sampler.decode(z_enc, c, t_enc, unconditional_guidance_scale=opt.scale,
                                                    unconditional_conditioning=uc)

with

noised_sample = sampler.stochastic_encode(init_latent, opt.strength)
samples, _ = sampler.sample(
                                                opt.ddim_steps,
                                                noised_sample.shape[0],
                                                noised_sample.shape[1:],
                                                conditioning=c,
                                                unconditional_guidance_scale=opt.scale,
                                                unconditional_conditioning=uc,
                                                method="multistep",
                                                order=2,
                                                lower_order_final=False,
                                                t_start=sampler.ratio_to_time(opt.strength),
                                                x_T=noised_sample,
                                            )

but the results don' well.(same step not better than ddim) . Is there any other better way?

@ssxxx1a ssxxx1a changed the title how to replace ddim with dpm-solver in the origin stable diffusion? how to replace ddim with dpm-solver in the origin stable diffusion? (img2img) Dec 8, 2022
@wuutiing
Copy link

have you got any solution?

@yuanzhi-zhu
Copy link

Hey,
I think you have to replace the opt.strength with 1-opt.strength in your codes (two places).

e.g. when the strength of input image is 0, it's equivalent to a text2img generation (start from pure noise), then the input time t for stochastic_encode should be 1; and when you set the opt.strength=1, the output should be same to the input image.

PS: I still find that the output of img2img with dpm solver different from ddim. Could you also compare these two methods, if you are able to make dpm solver work?

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