MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / __call__

Method __call__

diffusers/examples/community/bit_diffusion.py:229–264  ·  view source on GitHub ↗
(
        self,
        height: Optional[int] = 256,
        width: Optional[int] = 256,
        num_inference_steps: Optional[int] = 50,
        generator: Optional[torch.Generator] = None,
        batch_size: Optional[int] = 1,
        output_type: Optional[str] = "pil",
        return_dict: bool = True,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

227
228 @torch.no_grad()
229 def __call__(
230 self,
231 height: Optional[int] = 256,
232 width: Optional[int] = 256,
233 num_inference_steps: Optional[int] = 50,
234 generator: Optional[torch.Generator] = None,
235 batch_size: Optional[int] = 1,
236 output_type: Optional[str] = "pil",
237 return_dict: bool = True,
238 **kwargs,
239 ) -> Union[Tuple, ImagePipelineOutput]:
240 latents = torch.randn(
241 (batch_size, self.unet.config.in_channels, height, width),
242 generator=generator,
243 )
244 latents = decimal_to_bits(latents) * self.bit_scale
245 latents = latents.to(self.device)
246
247 self.scheduler.set_timesteps(num_inference_steps)
248
249 for t in self.progress_bar(self.scheduler.timesteps):
250 # predict the noise residual
251 noise_pred = self.unet(latents, t).sample
252
253 # compute the previous noisy sample x_t -> x_t-1
254 latents = self.scheduler.step(noise_pred, t, latents).prev_sample
255
256 image = bits_to_decimal(latents)
257
258 if output_type == "pil":
259 image = self.numpy_to_pil(image)
260
261 if not return_dict:
262 return (image,)
263
264 return ImagePipelineOutput(images=image)

Callers

nothing calls this directly

Calls 8

ImagePipelineOutputClass · 0.90
decimal_to_bitsFunction · 0.85
bits_to_decimalFunction · 0.85
toMethod · 0.45
set_timestepsMethod · 0.45
progress_barMethod · 0.45
stepMethod · 0.45
numpy_to_pilMethod · 0.45

Tested by

no test coverage detected