(self,
S,
batch_size,
shape,
conditioning=None,
callback=None,
normals_sequence=None,
img_callback=None,
quantize_x0=False,
eta=0.,
mask=None,
x0=None,
temperature=1.,
noise_dropout=0.,
score_corrector=None,
corrector_kwargs=None,
verbose=True,
x_T=None,
log_every_t=100,
unconditional_guidance_scale=1.,
unconditional_conditioning=None,
# this has to come in the same format as the conditioning, # e.g. as encoded tokens, ...
**kwargs
)
| 54 | |
| 55 | @torch.no_grad() |
| 56 | def sample(self, |
| 57 | S, |
| 58 | batch_size, |
| 59 | shape, |
| 60 | conditioning=None, |
| 61 | callback=None, |
| 62 | normals_sequence=None, |
| 63 | img_callback=None, |
| 64 | quantize_x0=False, |
| 65 | eta=0., |
| 66 | mask=None, |
| 67 | x0=None, |
| 68 | temperature=1., |
| 69 | noise_dropout=0., |
| 70 | score_corrector=None, |
| 71 | corrector_kwargs=None, |
| 72 | verbose=True, |
| 73 | x_T=None, |
| 74 | log_every_t=100, |
| 75 | unconditional_guidance_scale=1., |
| 76 | unconditional_conditioning=None, |
| 77 | # this has to come in the same format as the conditioning, # e.g. as encoded tokens, ... |
| 78 | **kwargs |
| 79 | ): |
| 80 | if conditioning is not None: |
| 81 | if isinstance(conditioning, dict): |
| 82 | cbs = conditioning[list(conditioning.keys())[0]].shape[0] |
| 83 | if cbs != batch_size: |
| 84 | print(f"Warning: Got {cbs} conditionings but batch-size is {batch_size}") |
| 85 | else: |
| 86 | if conditioning.shape[0] != batch_size: |
| 87 | print(f"Warning: Got {conditioning.shape[0]} conditionings but batch-size is {batch_size}") |
| 88 | |
| 89 | self.make_schedule(ddim_num_steps=S, ddim_eta=eta, verbose=verbose) |
| 90 | # sampling |
| 91 | C, H, W = shape |
| 92 | size = (batch_size, C, H, W) |
| 93 | print(f'Data shape for DDIM sampling is {size}, eta {eta}') |
| 94 | |
| 95 | samples, intermediates = self.ddim_sampling(conditioning, size, |
| 96 | callback=callback, |
| 97 | img_callback=img_callback, |
| 98 | quantize_denoised=quantize_x0, |
| 99 | mask=mask, x0=x0, |
| 100 | ddim_use_original_steps=False, |
| 101 | noise_dropout=noise_dropout, |
| 102 | temperature=temperature, |
| 103 | score_corrector=score_corrector, |
| 104 | corrector_kwargs=corrector_kwargs, |
| 105 | x_T=x_T, |
| 106 | log_every_t=log_every_t, |
| 107 | unconditional_guidance_scale=unconditional_guidance_scale, |
| 108 | unconditional_conditioning=unconditional_conditioning, |
| 109 | **kwargs |
| 110 | ) |
| 111 | return samples, intermediates |
| 112 | |
| 113 | @torch.no_grad() |
no test coverage detected