dpm-solver icon indicating copy to clipboard operation
dpm-solver copied to clipboard

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

Open ssxxx1a opened this issue 2 years ago • 2 comments
trafficstars

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 avatar Dec 08 '22 07:12 ssxxx1a

have you got any solution?

wuutiing avatar Dec 15 '22 09:12 wuutiing

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?

yuanzhi-zhu avatar Dec 16 '22 19:12 yuanzhi-zhu