Posts

Showing posts from December, 2024

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...

stable diffusion

  ! nvidia-smi ! pip uninstall -y diffusers huggingface_hub ! pip install diffusers transformers ftfy ipywidgets torch import torch from diffusers import StableDiffusionPipeline pipe = StableDiffusionPipeline.from_pretrained ( "CompVis/stable-diffusion-v1-4" , torch_dtype=torch.float16 )   pipe = pipe.to ( "cuda" ) prompt = "plane crash" image = pipe ( prompt ) .images [ 0 ]   # image here is in [PIL format](https://pillow.readthedocs.io/en/stable/) # Now to display an image you can either save it such as: image.save ( f "astronaut_rides_horse.png" ) # or if you're in a google colab you can directly display it with image 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"...