Instructions to use stabilityai/sdxl-vae with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use stabilityai/sdxl-vae with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-vae", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Update README.md
#23
by playrth - opened
16 unmodified lines17181920212216 unmodified linesvae = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae")pipe = StableDiffusionPipeline.from_pretrained(model, vae=vae)```## Model[SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9) is a [latent diffusion model](https://arxiv.org/abs/2112.10752), where the diffusion operates in a pretrained,16 unmodified lines171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747516 unmodified linesvae = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae")pipe = StableDiffusionPipeline.from_pretrained(model, vae=vae)```#### How to encode and decode Image example```pyimport torchfrom PIL import Imagefrom diffusers import AutoencoderKLfrom diffusers.image_processor import VaeImageProcessorimport matplotlib.pyplot as pltdevice=torch.device("cuda" if torch.cuda.is_available else "cpu")# Load the pre-trained VAE modelvae = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae")vae.to(device)vae.eval()# Load Image processorimage_processor = VaeImageProcessor()# Load an imageimage = Image.open("Paste Image here")# Preprocess the imageimage_tensor =image_processor.preprocess(image,height=256,width=256,resize_mode="fill").to(device)# Encode the imagewith torch.no_grad():latent_representation = vae.encode(image_tensor).latent_dist.sample()# Decode the latent representation back to imagewith torch.no_grad():reconstructed_image = vae.decode(latent_representation).sample# Convert the decoded tensor to a displayable imagereconstructed_image = reconstructed_image.cpu()reconstructed_image=image_processor.postprocess(reconstructed_image,output_type='pil')reconstructed_image=reconstructed_image[0]# Plot the original and reconstructed images side by sideplt.figure(figsize=(10, 5))# Original imageplt.subplot(1, 2, 1)plt.imshow(image)plt.title("Original Image")plt.axis("off")# Reconstructed imageplt.subplot(1, 2, 2)plt.imshow(reconstructed_image)plt.title("Reconstructed Image")plt.axis("off")plt.show()```## Model[SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9) is a [latent diffusion model](https://arxiv.org/abs/2112.10752), where the diffusion operates in a pretrained,
README.md+53