|
|
|
from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler |
|
import time |
|
import os |
|
from huggingface_hub import HfApi |
|
|
|
import torch |
|
import sys |
|
from pathlib import Path |
|
import requests |
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
path = sys.argv[1] |
|
|
|
api = HfApi() |
|
start_time = time.time() |
|
pipe = StableDiffusionPipeline.from_ckpt(path, torch_dtype=torch.float16) |
|
import ipdb; ipdb.set_trace() |
|
|
|
pipe = pipe.to("cuda") |
|
|
|
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for TIMESTEP_TYPE in ["trailing", "leading"]: |
|
for RESCALE_BETAS_ZEROS_SNR in [True, False]: |
|
for GUIDANCE_RESCALE in [0,0, 0.7]: |
|
|
|
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing=TIMESTEP_TYPE, rescale_betas_zero_snr=RESCALE_BETAS_ZEROS_SNR) |
|
generator = torch.Generator(device="cpu").manual_seed(0) |
|
images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=4, num_inference_steps=40, guidance_rescale=GUIDANCE_RESCALE).images |
|
|
|
for i, image in enumerate(images): |
|
file_name = f"bb_{i}_{TIMESTEP_TYPE}_{str(int(RESCALE_BETAS_ZEROS_SNR))}_{GUIDANCE_RESCALE}" |
|
path = os.path.join(Path.home(), "images", f"{file_name}.png") |
|
image.save(path) |
|
|
|
api.upload_file( |
|
path_or_fileobj=path, |
|
path_in_repo=path.split("/")[-1], |
|
repo_id="patrickvonplaten/images", |
|
repo_type="dataset", |
|
) |
|
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png") |
|
|