Skip to content

Instantly share code, notes, and snippets.

@ProGamerGov
ProGamerGov / replace_vae.py
Last active December 26, 2023 07:15
Replace the VAE in a Stable Diffusion model with a new VAE. Tested on v1.4 & v1.5 SD models
# Script by https://github.com/ProGamerGov
import copy
import torch
# Path to model and VAE files that you want to merge
vae_file_path = "vae-ft-mse-840000-ema-pruned.ckpt"
model_file_path = "v1-5-pruned-emaonly.ckpt"
# Name to use for new model file
@ProGamerGov
ProGamerGov / convert_webp_to_png.py
Created February 12, 2023 21:09
Convert all '.webp' images in a dataset to '.png'
import os
from PIL import Image
def convert_webp_to_png(directory: str, delete_old_webp_images: bool = False):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".webp"):
filepath = os.path.join(root, file)
img = Image.open(filepath)
new_filepath = os.path.splitext(filepath)[0] + ".png"