Created
May 11, 2023 15:33
-
-
Save takuma104/82f267a9e0aa6d5581e57a241e5234a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler | |
from torch | |
from PIL import Image | |
def image_grid(imgs, rows, cols): | |
assert len(imgs) == rows*cols | |
w, h = imgs[0].size | |
grid = Image.new('RGB', size=(cols*w, rows*h)) | |
grid_w, grid_h = grid.size | |
for i, img in enumerate(imgs): | |
grid.paste(img, box=(i%cols*w, i//cols*h)) | |
return grid | |
pipe = StableDiffusionPipeline.from_ckpt('https://huggingface.co/gsdf/Counterfeit-V3.0/blob/main/Counterfeit-V3.0_fp16.safetensors', | |
torch_dtype=torch.float16, | |
safety_checker=None).to('cuda') | |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True) | |
pipe.enable_xformers_memory_efficient_attention() | |
prompt = "masterpiece, best quality, 1girl, at dusk" | |
negative_prompt = ("(low quality, worst quality:1.4), (bad anatomy), (inaccurate limb:1.2), " | |
"bad composition, inaccurate eyes, extra digit, fewer digits, (extra arms:1.2), large breasts") | |
import kohya_lora_loader | |
kohya_lora_loader.install_lora_hook(pipe) | |
lora1 = pipe.apply_lora('Light_and_Shadow.safetensors') | |
images = pipe(prompt=prompt, | |
negative_prompt=negative_prompt, | |
width=512, | |
height=768, | |
num_inference_steps=15, | |
num_images_per_prompt=4, | |
generator=torch.Generator(device='cuda').manual_seed(0)).images | |
image_grid(images, 1, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment