Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active December 1, 2023 16:58
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/d3e254dae00aa32afd205794018af56c to your computer and use it in GitHub Desktop.
Save garystafford/d3e254dae00aa32afd205794018af56c to your computer and use it in GitHub Desktop.
pipeline = DiffusionPipeline.from_pretrained(
model_name_base,
torch_dtype=torch.float16,
).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,
).to(device)
subject_prompt = """oue, marker rendering of oue electric scooter, concept art,
futuristic cityscape, high contrast, black and white, black marker, marker drawing,
sketch, monochromatic illustration, illustrative, graphic, muted, expressive strokes"""
subject_negative_prompt = """person, people, human, rider, floating objects, colors, text,
words, writing, letters, phrases, trademark, watermark, icon, logo, banner, signature,
username, cropped, cut-off, patterned background"""
refiner_prompt = """sharp, crisp, in-focus, uncropped, high-quality"""
# we don't want a photographic image
refiner_negative_prompt = """photographic, photo, photorealistic, 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_bw_render_square_{seed}.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment