Textual inversion
Last updated
Last updated
The StableDiffusionPipeline supports textual inversion, a technique that enables a model like Stable Diffusion to learn a new concept from just a few sample images. This gives you more control over the generated images and allows you to tailor the model towards specific concepts. You can get started quickly with a collection of community created concepts in the Stable Diffusion Conceptualizer.
This guide will show you how to run inference with textual inversion using a pre-learned concept from the Stable Diffusion Conceptualizer. If you’re interested in teaching a model new concepts with textual inversion, take a look at the Textual Inversion training guide.
Login to your Hugging Face account:
Copied
Import the necessary libraries:
Copied
Pick a Stable Diffusion checkpoint and a pre-learned concept from the Stable Diffusion Conceptualizer:
Copied
Now you can load a pipeline, and pass the pre-learned concept to it:
Copied
Create a prompt with the pre-learned concept by using the special placeholder token <cat-toy>
, and choose the number of samples and rows of images you’d like to generate:
Copied
Then run the pipeline (feel free to adjust the parameters like num_inference_steps
and guidance_scale
to see how they affect image quality), save the generated images and visualize them with the helper function you created at the beginning:
Copied