Using doodles and diffusers to expand your imagination

Exploring stable diffusion’s img2img transformation with a colab notebook

One of the creatures I created with my nephew’s sea monster drawing :D

In a normal text-to-image run of Stable Diffusion, we feed the model some random noise. The model assumes, though, that this input is actually a piece of artwork that just had a bunch of noise added.

So, using the text prompt as a source of “hints” for what the (supposed) original looked like, it does its best to recover an image from the static. It does this over a bunch of steps (e.g., 50), gradually removing a little more noise each time.

With img2img, we do actually bury a real image (the one you provide) under a bunch of noise. And this causes Stable Diffusion to “recover” something that looks much closer to the one you supplied.

with autocast("cuda"):
image = pipe(prompt=prompt, init_image=init_img, strength=0.9, guidance_scale=7.5, generator=generator).images[0]
device = "cuda"
model_path = "CompVis/stable-diffusion-v1-4"

pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
model_path,
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=True
)
pipe = pipe.to(device)
def generate_image_by_strength(_strength, _img):
with autocast("cuda"):
image = pipe(prompt=prompt, init_image=_img, strength=_strength, guidance_scale=7.5, generator=generator).images[0]
display(f"Image at strength {_strength}")
display(image)
interval = 1/30
strength=0
while strength<=1:
display({strength})
generate_image_by_strength(strength, img)
strength += interval
strength = round(strength,2)
index = 0
strength=0.60
while index<30:
generate_image_by_strength(strength, img)
index += 1

--

--

Building. Author of “Feeling Great About My Butt.” Previously: Creators @Medium, Product @embedly, Research @NECSI. http://whichlight.com.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kawandeep Virdee

Building. Author of “Feeling Great About My Butt.” Previously: Creators @Medium, Product @embedly, Research @NECSI. http://whichlight.com.