Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active December 1, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/92cee6a6c6717424dd27d79bcaa91730 to your computer and use it in GitHub Desktop.
Save garystafford/92cee6a6c6717424dd27d79bcaa91730 to your computer and use it in GitHub Desktop.
from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline
device = "cuda" # cpu or cuda
pipeline = DiffusionPipeline.from_pretrained(
model_name_base,
torch_dtype=torch.float16,
).to(device)
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
model_name_refiner,
torch_dtype=torch.float16,
).to(device)
# optional descriptive terms: sleek, futuristic, metallic, colorful, urban
subject_prompt = """photo of an electric scooter, modern, daytime, vivid 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"""
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=80,
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/base_model_scooter_photo_square_{seed}.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment