Stable Diffusion image pa
import torch from diffusers import StableDiffusionPipeline , EulerDiscreteScheduler import matplotlib.pyplot as plt from PIL import Image # Load the pipeline pipe = StableDiffusionPipeline.from_pretrained ( "CompVis/stable-diffusion-v1-4" , torch_dtype=torch.float16 ) pipe = pipe.to ( "cuda" ) # Set a scheduler to include callback pipe.scheduler = EulerDiscreteScheduler.from_config ( pipe.scheduler.config ) # Define the callback to capture intermediate images intermediate_images = [] def save_intermediate_images ( pipeline , step , timestep , extra_inputs ) : """ Callback function to save intermediate images. """ latents = extra_inputs [ "latents" ] # Retrieve the latents from the extra inputs if step == 0 : # Capture the first random latent (noise) with torch.no_grad (): random_latent_image = p...