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

The results are blurry images with vanilla ddpm

Open AidenLsz opened this issue 1 year ago • 2 comments

Dear authors, Thank you for generously sharing your great work! I used dpm-solver to accelerate vanilla ddpm for image purification.And if I set timesteps OF DDPM as 500,with my pretrained model,I can gradually reverse the image to one that's close to the original one: image However,when I used dpm-solver,the results are blurry: image

Settings: 512*512 celebahq; betas are from 0.0001 to 01004004 with 500 steps,so x_start=1,x_end=1/500; self.model:the same one in your responsitory,whose path is "dpm-solver/examples/ddpm_and_guided-diffusion/models /diffusion.py"

noise_schedule = NoiseScheduleVP(schedule='discrete', betas=self.betas) model_fn = model_wrapper( self.model, noise_schedule, model_type="noise", model_kwargs={}, guidance_type="uncond" )

self.dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver++") x_sample = self.dpm_solver.sample( x, steps=20, order=3, skip_type="time_uniform", method="singlestep" I tried singlestep,multistep,steps ranging [10,1000],orders as 1,2 or 3.Nothing worked. Thanks for your kind help!

AidenLsz avatar Mar 09 '24 14:03 AidenLsz

What's the training loss of your model?

LuChengTHU avatar Mar 09 '24 22:03 LuChengTHU

What's the training loss of your model?

Thanks for your quick response! The loss is the squared difference between the predicted noise and the real noise added in step t-1; I used the pretrained model of this repo,which claims that it's a copy from SDEdit.So it should be trained with code below from this PyTorch implementation for training the model according to its readme:(comments are added by me)

def noise_estimation_loss(model,
                          x0: torch.Tensor, //image used for training
                          t: torch.LongTensor, //timestep
                          e: torch.Tensor,// random noise having shape of x0
                          b: torch.Tensor, //self.betas
keepdim=False):
    a = (1-b).cumprod(dim=0).index_select(0, t).view(-1, 1, 1, 1)
    x = x0 * a.sqrt() + e * (1.0 - a).sqrt()// image after adding t steps of noise
    output = model(x, t.float()) //the predicted noise added by step t-1
    if keepdim:
        return (e - output).square().sum(dim=(1, 2, 3))//the difference between predicted noise and real noise
    else:
        return (e - output).square().sum(dim=(1, 2, 3)).mean(dim=0)

loss_registry = {
    'simple': noise_estimation_loss,
}

ps:I found this copy in SDEdit‘s issuse because the pretrained model in it cannot be accessed,and it worked fine in vanilla DDPM as a NOISE PREDICTION MODEL. Thanks again for your kind help!It means a lot to me!

AidenLsz avatar Mar 10 '24 05:03 AidenLsz