Skip to content

Commit 6cc5604

Browse files
authored
documentation enhancements (#1603)
- Add documentation for the Hugging Face concepts library and TI embedding. - Fixup index.md to point to each of the feature documentation files, including ones that are pending.
1 parent 45e51ba commit 6cc5604

File tree

9 files changed

+159
-24
lines changed

9 files changed

+159
-24
lines changed

docs/assets/concepts/image1.png

122 KB
Loading

docs/assets/concepts/image2.png

127 KB
Loading

docs/assets/concepts/image3.png

99.3 KB
Loading

docs/assets/concepts/image4.png

112 KB
Loading

docs/assets/concepts/image5.png

107 KB
Loading

docs/features/CLI.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ value, we are insisting on a more stringent classification.
269269
invoke> a piece of cake -I /path/to/breakfast.png -tm bagel 0.6
270270
```
271271

272+
### Custom Styles and Subjects
273+
274+
You can load and use hundreds of community-contributed Textual
275+
Inversion models just by typing the appropriate trigger phrase. Please
276+
see [Concepts Library](CONCEPTS.md) for more details.
277+
272278
# Other Commands
273279

274280
The CLI offers a number of commands that begin with "!".

docs/features/CONCEPTS.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: The Hugging Face Concepts Library and Importing Textual Inversion files
3+
---
4+
5+
# :material-file-document: Concepts Library
6+
7+
## Using Textual Inversion Files
8+
9+
Textual inversion (TI) files are small models that customize the output of
10+
Stable Diffusion image generation. They can augment SD with
11+
specialized subjects and artistic styles. They are also known as
12+
"embeds" in the machine learning world.
13+
14+
Each TI file introduces one or more vocabulary terms to the SD
15+
model. These are known in InvokeAI as "triggers." Triggers are often,
16+
but not always, denoted using angle brackets as in
17+
"<trigger-phrase>". The two most common type of TI files that you'll
18+
encounter are `.pt` and `.bin` files, which are produced by different
19+
TI training packages. InvokeAI supports both formats, but its [built-in
20+
TI training system](TEXTUAL_INVERSION.md) produces `.pt`.
21+
22+
The [Hugging Face company](https://huggingface.co/sd-concepts-library)
23+
has amassed a large ligrary of >800 community-contributed TI files
24+
covering a broad range of subjects and styles. InvokeAI has built-in
25+
support for this library which downloads and merges TI files
26+
automatically upon request. You can also install your own or others'
27+
TI files by placing them in a designated directory.
28+
29+
### An Example
30+
31+
Here are a few examples to illustrate how it works. All these images
32+
were generated using the command-line client and the Stable Diffusion
33+
1.5 model:
34+
35+
Japanese gardener
36+
<br>
37+
<img src="../assets/concepts/image1.png">
38+
39+
Japanese gardener &lt;ghibli-face&gt;
40+
<br>
41+
<img src="../assets/concepts/image2.png">
42+
43+
Japanese gardener &lt;hoi4-leaders&gt;
44+
<br>
45+
<img src="../assets/concepts/image3.png">
46+
47+
Japanese gardener &lt;cartoona-animals&gt;
48+
<br>
49+
<img src="../assets/concepts/image4.png">
50+
51+
You can also combine styles and concepts:
52+
53+
A portrait of &lt;alf&gt; in &lt;cartoona-animal&gt; style
54+
<br>
55+
<img src="../assets/concepts/image5.png">
56+
57+
## Using a Hugging Face Concept
58+
59+
Hugging Face TI concepts are downloaded and installed automatically as
60+
you require them. This requires your machine to be connected to the
61+
Internet. To find out what each concept is for, you can browse the
62+
[Hugging Face concepts
63+
library](https://huggingface.co/sd-concepts-library) and look at
64+
examples of what each concept produces.
65+
66+
When you have an idea of a concept you wish to try, go to the
67+
command-line client (CLI) and type a "&lt;" character and the beginning
68+
of the Hugging Face concept name you wish to load. Press the Tab key,
69+
and the CLI will show you all matching concepts. You can also type "&lt;"
70+
and Tab to get a listing of all ~800 concepts, but be prepared to
71+
scroll up to see them all! If there is more than one match you can
72+
continue to type and Tab until the concept is completed.
73+
74+
For example if you type "&lt;x" and Tab, you'll be prompted with the completions:
75+
76+
```
77+
<xatu2> <xatu> <xbh> <xi> <xidiversity> <xioboma> <xuna> <xyz>
78+
```
79+
80+
Now type "id" and press Tab. It will be autocompleted to
81+
"&lt;xidiversity&gt;" because this is a unique match.
82+
83+
Finish your prompt and generate as usual. You may include multiple
84+
concept terms in the prompt.
85+
86+
If you have never used this concept before, you will see a message
87+
that the TI model is being downloaded and installed. After this, the
88+
concept will be saved locally (in the `models/sd-concepts-library`
89+
directory) for future use.
90+
91+
Several steps happen during downloading and
92+
installation, including a scan of the file for malicious code. Should
93+
any errors occur, you will be warned and the concept will fail to
94+
load. Generation will then continue treating the trigger term as a
95+
normal string of characters (e.g. as literal "&lt;ghibli-face&gt;").
96+
97+
Currently auto-installation of concepts is a feature only available on
98+
the command-line client. Support for the WebUI is a work in progress.
99+
100+
## Installing your Own TI Files
101+
102+
You may install any number of `.pt` and `.bin` files simply by copying
103+
them into the `embeddings` directory of the InvokeAI runtime directory
104+
(usually `invokeai` in your home directory). You may create
105+
subdirectories in order to organize the files in any way you wish. Be
106+
careful not to overwrite one file with another. For example, TI files
107+
generated by the Hugging Face toolkit share the named
108+
`learned_embedding.bin`. You can use subdirectories to keep them
109+
distinct.
110+
111+
At startup time, InvokeAI will scan the `embeddings` directory and
112+
load any TI files it finds there. At startup you will see a message
113+
similar to this one:
114+
115+
```
116+
>> Current embedding manager terms: *, <HOI4-Leader>, <princess-knight>
117+
```
118+
119+
Note the "*" trigger term. This is a placeholder term that many early
120+
TI tutorials taught people to use rather than a more descriptive
121+
term. Unfortunately, if you have multiple TI files that all use this
122+
term, only the first one loaded will be triggered by use of the term.
123+
124+
To avoid this problem, you can use the `merge_embeddings.py` script to
125+
merge two or more TI files together. If it encounters a collision of
126+
terms, the script will prompt you to select new terms that do not
127+
collide. See [Textual Inversion](TEXTUAL_INVERSION.md) for details.
128+
129+
## Further Reading
130+
131+
Please see [the repository](https://github.com/rinongal/textual_inversion) and
132+
associated paper for details and limitations.

docs/features/OTHER.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,6 @@ outputs = g.txt2img("a unicorn in manhattan")
133133

134134
Outputs is a list of lists in the format [filename1,seed1],[filename2,seed2]...].
135135

136-
Please see ldm/generate.py for more information. A set of example scripts is coming RSN.
136+
Please see the documentation in ldm/generate.py for more information.
137137

138138
---
139-
140-
## **Preload Models**
141-
142-
In situations where you have limited internet connectivity or are blocked behind a firewall, you can
143-
use the preload script to preload the required files for Stable Diffusion to run.
144-
145-
The preload script `scripts/preload_models.py` needs to be run once at least while connected to the
146-
internet. In the following runs, it will load up the cached versions of the required files from the
147-
`.cache` directory of the system.
148-
149-
```bash
150-
(invokeai) ~/stable-diffusion$ python3 ./scripts/preload_models.py
151-
preloading bert tokenizer...
152-
Downloading: 100%|██████████████████████████████████| 28.0/28.0 [00:00<00:00, 49.3kB/s]
153-
Downloading: 100%|██████████████████████████████████| 226k/226k [00:00<00:00, 2.79MB/s]
154-
Downloading: 100%|██████████████████████████████████| 455k/455k [00:00<00:00, 4.36MB/s]
155-
Downloading: 100%|██████████████████████████████████| 570/570 [00:00<00:00, 477kB/s]
156-
...success
157-
preloading kornia requirements...
158-
Downloading: "https://github.com/DagnyT/hardnet/raw/master/pretrained/train_liberty_with_aug/checkpoint_liberty_with_aug.pth" to /u/lstein/.cache/torch/hub/checkpoints/checkpoint_liberty_with_aug.pth
159-
100%|███████████████████████████████████████████████| 5.10M/5.10M [00:00<00:00, 101MB/s]
160-
...success
161-
```

docs/index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ You wil need one of the following:
119119
```bash
120120
(invokeai) ~/InvokeAI$ python scripts/invoke.py --full_precision
121121
```
122+
## :octicons-gift-24: InvokeAI Features
123+
124+
- [The InvokeAI Web Interface](features/WEB.md)
125+
- [WebGUI hotkey reference guide](features/WEBUIHOTKEYS.md)
126+
- [WebGUI Unified Canvas for Img2Img, inpainting and outpainting](features/UNIFIED_CANVAS.md)
127+
128+
- [The Command Line Interace](features/CLI.md)
129+
- [Image2Image](features/IMG2IMG.md)
130+
- [Inpainting][(features/INPAINTING.md)
131+
- [Outpainting](features/OUTPAINTING.md)
132+
- [Adding custom styles and subjects](features/CONCEPTS.md)
133+
- [Upscaling and Face Reconstruction](features/POSTPROCESS.md)
134+
135+
- [Generating Variations](features/VARIATIONS.md)
136+
137+
- [Prompt Engineering](features/PROMPTS.md)
138+
139+
- Miscellaneous
140+
- [Embiggen upscaling](features/EMBIGGEN.md)
141+
- [Other](features/OTHER.md)
122142

123143
## :octicons-log-16: Latest Changes
124144

0 commit comments

Comments
 (0)