MCPcopy Index your code
hub / github.com/VisionXLab/OF-Diff / sample

Method sample

ldm/models/diffusion/plms.py:59–115  ·  view source on GitHub ↗
(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, ...
               dynamic_threshold=None,
               **kwargs
               )

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

make_scheduleMethod · 0.95
plms_samplingMethod · 0.95

Tested by

no test coverage detected