CoolFace
Modelpublic

diffusers/tools

sourceHugging Facecreativeml-openrail-mupdated 3y agoView on Hugging Face
11likes28downloads
load_ckpt.py58 linesDownload Raw Back to root
1#!/usr/bin/env python32from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler3import time4import os5from huggingface_hub import HfApi6# from compel import Compel7import torch8import sys9from pathlib import Path10import requests11from PIL import Image12from io import BytesIO13 14path = sys.argv[1]15 16api = HfApi()17start_time = time.time()18pipe = StableDiffusionPipeline.from_ckpt(path, torch_dtype=torch.float16)19import ipdb; ipdb.set_trace()20 21pipe = pipe.to("cuda")22 23prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"24 25# rompts = ["a cat playing with a ball++ in the forest", "a cat playing with a ball++ in the forest", "a cat playing with a ball-- in the forest"]26 27# prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])28 29# generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]30#31# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"32# 33# response = requests.get(url)34# image = Image.open(BytesIO(response.content)).convert("RGB")35# image.thumbnail((768, 768))36#37 38for TIMESTEP_TYPE in ["trailing", "leading"]:39    for RESCALE_BETAS_ZEROS_SNR in [True, False]:40        for GUIDANCE_RESCALE in [0,0, 0.7]:41 42            pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing=TIMESTEP_TYPE, rescale_betas_zero_snr=RESCALE_BETAS_ZEROS_SNR)43            generator = torch.Generator(device="cpu").manual_seed(0)44            images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=4, num_inference_steps=40, guidance_rescale=GUIDANCE_RESCALE).images45 46            for i, image in enumerate(images):47                file_name = f"bb_{i}_{TIMESTEP_TYPE}_{str(int(RESCALE_BETAS_ZEROS_SNR))}_{GUIDANCE_RESCALE}"48                path = os.path.join(Path.home(), "images", f"{file_name}.png")49                image.save(path)50 51                api.upload_file(52                    path_or_fileobj=path,53                    path_in_repo=path.split("/")[-1],54                    repo_id="patrickvonplaten/images",55                    repo_type="dataset",56                )57                print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")58