Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/diffusers_doc/en/textual_inversion_inference.ipynb
Views: 2542
Textual inversion
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:
Import the necessary libraries, and create a helper function to visualize the generated images:
Pick a Stable Diffusion checkpoint and a pre-learned concept from the Stable Diffusion Conceptualizer:
Now you can load a pipeline, and pass the pre-learned concept to it:
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:
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: