I am in the early stage of learning Stable Diffusion
.
Motivation:
I would like to generate real object picture from line art like this.
I found that I need to use ControlNet
. However, when I download majicMIX realistic
. It does not support ControlNet
which I can input image to it.
Here is my attempt.
from diffusers import StableDiffusionPipeline, Stable
import torch
torch.manual_seed(111)
device = torch.device("mps") if torch.backends.mps.is_available() else torch.device("cpu")
pipe = StableDiffusionPipeline.from_ckpt("majicmixRealistic_v5.safetensors", load_safety_checker=False).to(device)
prompt = "A photo of rough collie, best quality"
negative_prompt: str = "low quality"
guidance_scale = 1
eta = 0.0
result = pipe(
prompt, num_inference_steps=30, num_images_per_prompt=8,
guidance_scale=1, negative_prompt=negative_prompt)
for idx, image in enumerate(result.images):
image.save(f"character_{guidance_scale}_{eta}_{idx}.png")
But I can't use this model
with ControlNet
. Because it is checkpoint
.
Next on I use StableDiffusionImg2ImgPipeline
. This one I can put text
and image
together, but I can't use ControlNet
.
"""
https://huggingface.co/docs/diffusers/using-diffusers/img2img
"""
import torch
from diffusers import StableDiffusionImg2ImgPipeline
from diffusers.utils import load_image
device = "mps" if torch.backends.mps.is_available() else "cpu"
pipe = StableDiffusionImg2ImgPipeline.from_ckpt("majicmixRealistic_v5.safetensors").to(
device
)
url = "../try_image_to_image/c.jpeg"
init_image = load_image(url)
prompt = "A woman, realistic color photo, high quality"
generator = torch.Generator(device=device).manual_seed(1024)
strengths = [0.3, 0.35, 0.4, 0.45, 0.5]
guidance_scales = [1, 2, 3, 4, 5, 6, 7, 8]
num_inference_steps = 100
print(f"Total run: {len(strengths) * len(guidance_scales)}")
for strength in strengths:
for guidance_scale in guidance_scales:
# image= pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5, generator=generator).images[0]
image = pipe(
prompt=prompt, image=init_image, strength=strength, guidance_scale=guidance_scale,
generator=generator, num_inference_steps=num_inference_steps).images[0]
image.save(f"images/3rd_{strength}_{guidance_scale}.png")
Question:
How to use ContronNet
with majicmix-realistic
?