mindspore-lab / mindone

one for all, Optimal generator with No Exception
Apache License 2.0
328 stars 62 forks source link

feat(diffusers/loaders): add loaders for controlnet, ti and etc. #516

Closed sageyou closed 1 week ago

sageyou commented 4 weeks ago

What does this PR do?

add loaders: autoencoders, controlnet, single_file, ip_adapter, textual_inversion.

We provides an easy-to-use LoaderMixin API to load adapter weights

Textual inversion is very similar to DreamBooth and it can also personalize a diffusion model to generate certain concepts (styles, objects) from just a few images. Now you can load the textual inversion embeddings with the load_textual_inversion() method and generate some images. Let’s load sd-concepts-library/gta5-artwork embeddings and you’ll need to include the special word in your prompt to trigger it:

from mindone.diffusers import StableDiffusionPipeline
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") 
pipeline.load_textual_inversion("gta5-artwork/")
prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, <gta5-artwork> style"
image = pipeline(prompt=prompt)[0][0]
image.save("textual_gta5.png")

IP-Adapter is a lightweight adapter that enables image prompting for any diffusion model. To start, load a Stable Diffusion checkpoint,then load the IP-Adapter h94/IP-Adapter weights and add it to the pipeline with theload_ip_adapter() method. Once loaded, you can use the pipeline with an image and text prompt to guide the image generation process:

from mindone.diffusers import StableDiffusionPipeline
from mindone.diffusers.utils import load_image
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="models", weight_name="ip-adapter_sd15.safetensors")
image=load_image("https://huggingface.co/datasets/huggingface/documentationimages/resolve/main/diffusers/load_neg_embed.png")
image = pipeline(
    prompt='best quality, high quality, wearing sunglasses',
    ip_adapter_image=image,
    negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
    num_inference_steps=50,
)[0][0]
image.save("ipadapter.png")

Try it out!

Fixes # (issue)

Adds # (feature)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.

@xxx