Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active November 23, 2023 07:28
Show Gist options
  • Select an option

  • Save garystafford/cc7bede777319f90fe5bb38902dd10f6 to your computer and use it in GitHub Desktop.

Select an option

Save garystafford/cc7bede777319f90fe5bb38902dd10f6 to your computer and use it in GitHub Desktop.

Revisions

  1. garystafford revised this gist Nov 23, 2023. 1 changed file with 1 addition and 49 deletions.
    50 changes: 1 addition & 49 deletions fine_tuned_photorealistic_daytime.py
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,3 @@
    from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline
    import torch
    from tqdm.notebook import tqdm

    model_name_base = "stabilityai/stable-diffusion-xl-base-1.0"
    model_name_refiner = "stabilityai/stable-diffusion-xl-refiner-1.0"

    device = "cuda" # cpu or cuda

    pipeline = DiffusionPipeline.from_pretrained(
    model_name_base,
    torch_dtype=torch.float16,
    )
    pipeline.to(device)

    pipeline.load_lora_weights(
    project_name,
    weight_name="pytorch_lora_weights.safetensors"
    )

    refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
    model_name_refiner,
    torch_dtype=torch.float16,
    )
    refiner.to(device)

    subject_prompt = """oue, photo of a oue electric scooter, sleek, smooth curves, colorful,
    daytime, urban, futuristic cityscape"""

    @@ -35,26 +9,4 @@
    ultra sharp detail"""

    refiner_negative_prompt = """low quality, low-resolution, out of focus, blurry,
    grainy, artifacts, defects, jpeg artifacts, noise"""

    for seed in range(10):
    generator = torch.Generator(device).manual_seed(seed)
    base_image = pipeline(
    prompt=f"{subject_prompt}, {refiner_prompt}",
    negative_prompt=f"{subject_negative_prompt}, {refiner_negative_prompt}",
    num_inference_steps=100,
    generator=generator,
    height=1024,
    width=1024,
    output_type="latent",
    ).images[0]

    refined_image = refiner(
    prompt=refiner_prompt,
    negative_prompt=refiner_negative_prompt,
    num_inference_steps=20,
    generator=generator,
    image=base_image,
    ).images[0]

    refined_image.save(f"./generated_images/finetuned_scooter_marker_photo_square_{seed}.png")
    grainy, artifacts, defects, jpeg artifacts, noise"""
  2. garystafford created this gist Nov 23, 2023.
    60 changes: 60 additions & 0 deletions fine_tuned_photorealistic_daytime.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline
    import torch
    from tqdm.notebook import tqdm

    model_name_base = "stabilityai/stable-diffusion-xl-base-1.0"
    model_name_refiner = "stabilityai/stable-diffusion-xl-refiner-1.0"

    device = "cuda" # cpu or cuda

    pipeline = DiffusionPipeline.from_pretrained(
    model_name_base,
    torch_dtype=torch.float16,
    )
    pipeline.to(device)

    pipeline.load_lora_weights(
    project_name,
    weight_name="pytorch_lora_weights.safetensors"
    )

    refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
    model_name_refiner,
    torch_dtype=torch.float16,
    )
    refiner.to(device)

    subject_prompt = """oue, photo of a oue electric scooter, sleek, smooth curves, colorful,
    daytime, urban, futuristic cityscape"""

    subject_negative_prompt = """person, people, human, rider, floating objects, text,
    words, writing, letters, phrases, trademark, watermark, icon, logo, banner, signature,
    username, monochrome, cropped, cut-off, patterned background"""

    refiner_prompt = """ultra-high-definition, photorealistic, 8k uhd, high-quality,
    ultra sharp detail"""

    refiner_negative_prompt = """low quality, low-resolution, out of focus, blurry,
    grainy, artifacts, defects, jpeg artifacts, noise"""

    for seed in range(10):
    generator = torch.Generator(device).manual_seed(seed)
    base_image = pipeline(
    prompt=f"{subject_prompt}, {refiner_prompt}",
    negative_prompt=f"{subject_negative_prompt}, {refiner_negative_prompt}",
    num_inference_steps=100,
    generator=generator,
    height=1024,
    width=1024,
    output_type="latent",
    ).images[0]

    refined_image = refiner(
    prompt=refiner_prompt,
    negative_prompt=refiner_negative_prompt,
    num_inference_steps=20,
    generator=generator,
    image=base_image,
    ).images[0]

    refined_image.save(f"./generated_images/finetuned_scooter_marker_photo_square_{seed}.png")