Skip to content

Commit 37c921d

Browse files
committed
documentation enhancements
1 parent 4f72cb4 commit 37c921d

File tree

3 files changed

+219
-18
lines changed

3 files changed

+219
-18
lines changed

docs/features/CLI.md

Lines changed: 182 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,188 @@ dream> q
4141
<img src="../assets/dream-py-demo.png"/>
4242
</p>
4343

44-
The `dream>` prompt's arguments are pretty much identical to those used in the Discord bot, except you don't need to type "!dream" (it doesn't
45-
hurt if you do). A significant change is that creation of individual images is now the default unless --grid (-g) is given.
44+
The `dream>` prompt's arguments are pretty much identical to those
45+
used in the Discord bot, except you don't need to type "!dream" (it
46+
doesn't hurt if you do). A significant change is that creation of
47+
individual images is now the default unless --grid (-g) is given. A
48+
full list is given in [List of prompt arguments]
49+
(#list-of-prompt-arguments).
4650

47-
For backward compatibility, the -i switch is recognized. For command-line help type -h (or --help) at the dream> prompt.
51+
# Arguments
4852

49-
The script itself also recognizes a series of command-line switches that will change important global defaults, such as the directory for
53+
The script itself also recognizes a series of command-line switches
54+
that will change important global defaults, such as the directory for
5055
image outputs and the location of the model weight files.
56+
57+
## List of arguments recognized at the command line:
58+
59+
These command-line arguments can be passed to dream.py when you first
60+
run it from the Windows, Mac or Linux command line. Some set defaults
61+
that can be overridden on a per-prompt basis (see [List of prompt
62+
arguments] (#list-of-prompt-arguments). Others
63+
64+
| Argument | Shortcut | Default | Description |
65+
|--------------------|------------|---------------------|--------------|
66+
| --help | -h | | Print a concise help message. |
67+
| --outdir <path> | -o<path> | outputs/img_samples | Location for generated images. |
68+
| --prompt_as_dir | -p | False | Name output directories using the prompt text. |
69+
| --from_file <path> | | None | Read list of prompts from a file. Use "-" to read from standard input |
70+
| --model <modelname>| | stable-diffusion-1.4| Loads model specified in configs/models.yaml. Currently one of "stable-diffusion-1.4" or "laion400m"|
71+
| --full_precision | -F | False | Run in slower full-precision mode. Needed for Macintosh M1/M2 hardware and some older video cards. |
72+
| --web | | False | Start in web server mode |
73+
| --host <ip addr> | | localhost | Which network interface web server should listen on. Set to 0.0.0.0 to listen on any. |
74+
| --port <port> | | 9090 | Which port web server should listen for requests on. |
75+
| --config <path> | | configs/models.yaml | Configuration file for models and their weights. |
76+
| --iterations <int> | -n<int> | 1 | How many images to generate per prompt. |
77+
| --grid | -g | False | Save all image series as a grid rather than individually. |
78+
| --sampler <sampler>| -A<sampler>| k_lms | Sampler to use. Use -h to get list of available samplers. |
79+
| --seamless | | False | Create interesting effects by tiling elements of the image. |
80+
| --embedding_path <path>| | None | Path to pre-trained embedding manager checkpoints, for custom models |
81+
| --gfpgan_dir | | src/gfpgan | Path to where GFPGAN is installed. |
82+
| --gfpgan_model_path| | experiments/pretrained_models/GFPGANv1.3.pth| Path to GFPGAN model file, relative to --gfpgan_dir. |
83+
| --device <device> | -d<device>| torch.cuda.current_device() | Device to run SD on, e.g. "cuda:0" |
84+
85+
These arguments are deprecated but still work:
86+
87+
| Argument | Shortcut | Default | Description |
88+
|--------------------|------------|---------------------|--------------|
89+
| --weights <path> | | None | Pth to weights file; use `--model stable-diffusion-1.4` instead |
90+
| --laion400m | -l | False | Use older LAION400m weights; use `--model=laion400m` instead |
91+
92+
**A note on path names:** On Windows systems, you may run into
93+
problems when passing the dream script standard backslashed path
94+
names because the Python interpreter treats "\" as an escape.
95+
You can either double your slashes (ick): C:\\path\\to\\my\\file, or
96+
use Linux/Mac style forward slashes (better): C:/path/to/my/file.
97+
98+
## List of prompt arguments
99+
100+
After the dream.py script initializes, it will present you with a
101+
**dream>** prompt. Here you can enter information to generate images
102+
from text (txt2img), to embellish an existing image or sketch
103+
(img2img), or to selectively alter chosen regions of the image
104+
(inpainting).
105+
106+
### This is an example of txt2img:
107+
108+
~~~~
109+
dream> waterfall and rainbow -W640 -H480
110+
~~~~
111+
112+
This will create the requested image with the dimensions 640 (width)
113+
and 480 (height).
114+
115+
Here are the dream> command that apply to txt2img:
116+
117+
| Argument | Shortcut | Default | Description |
118+
|--------------------|------------|---------------------|--------------|
119+
| "my prompt" | | | Text prompt to use. The quotation marks are optional. |
120+
| --width <int> | -W<int> | 512 | Width of generated image |
121+
| --height <int> | -H<int> | 512 | Height of generated image |
122+
| --iterations <int> | -n<int> | 1 | How many images to generate from this prompt |
123+
| --steps <int> | -s<int> | 50 | How many steps of refinement to apply |
124+
| --cfg_scale <float>| -C<float> | 7.5 | How "hard to try" to match image to prompt|
125+
| --seed <int> | -S<int> | None | Set the random seed for the next series of images. This can be used to recreate an image generated previously.|
126+
| --sampler <sampler>| -A<sampler>| k_lms | Sampler to use. Use -h to get list of available samplers. |
127+
| --grid | -g | False | Turn on grid mode to return a single image combining all the images generated by this prompt |
128+
| --individual | -i | True | Turn off grid mode (deprecated; leave off --grid instead) |
129+
| --outdir <path> | -o<path> | outputs/img_samples | Temporarily change the location of these images |
130+
| --seamless | | False | Activate seamless tiling for interesting effects |
131+
| --log_tokenization | -t | False | Display a color-coded list of the parsed tokens derived from the prompt |
132+
| --skip_normalization| -x | False | Weighted subprompts will not be normalized. See [Weighted Prompts](./OTHER.md#**Weighted Prompts**) |
133+
| --upscale <int> <float> | -U <int> <float> | -U 1 0.75| Upscale image by magnification factor (2, 4), and set strength of upscaling (0.0-1.0). If strength not set, will default to 0.75. |
134+
| --gfpgan_strength <float> | -G <float> | -G0 | Fix faces using the GFPGAN algorithm; argument indicates how hard the algorithm should try (0.0-1.0) |
135+
| --save_original | -save_orig| False | When upscaling or fixing faces, this will cause the original image to be saved rather than replaced. |
136+
| --variation <float> |-v<float>| 0.0 | Add a bit of noise (0.0=none, 1.0=high) to the image in order to generate a series of variations. Usually used in combination with -S<seed> and -n<int> to generate a series a riffs on a starting image. See [Variations](./VARIATIONS.md). |
137+
| --with_variations <pattern> | -V<pattern>| None | Combine two or more variations. See [Variations](./VARIATIONS.md) for now to use this. |
138+
139+
Note that the width and height of the image must be multiples of
140+
64. You can provide different values, but they will be rounded down to
141+
the nearest multiple of 64.
142+
143+
144+
### This is an example of img2img:
145+
146+
~~~~
147+
dream> waterfall and rainbow -I./vacation-photo.png -W640 -H480 --fit
148+
~~~~
149+
150+
This will modify the indicated vacation photograph by making it more
151+
like the prompt. Results will vary greatly depending on what is in the
152+
image. We also ask to --fit the image into a box no bigger than
153+
640x480. Otherwise the image size will be identical to the provided
154+
photo and you may run out of memory if it is large.
155+
156+
In addition to the command-line options recognized by txt2img, img2img
157+
accepts additional options:
158+
159+
| Argument | Shortcut | Default | Description |
160+
|--------------------|------------|---------------------|--------------|
161+
| --init_img <path> | -I<path> | None | Path to the initialization image |
162+
| --fit | -F | False | Scale the image to fit into the specified -H and -W dimensions |
163+
| --strength <float> | -s<float> | 0.75 | How hard to try to match the prompt to the initial image. Ranges from 0.0-0.99, with higher values replacing the initial image completely.|
164+
165+
### This is an example of inpainting:
166+
167+
~~~~
168+
dream> waterfall and rainbow -I./vacation-photo.png -M./vacation-mask.png -W640 -H480 --fit
169+
~~~~
170+
171+
This will do the same thing as img2img, but image alterations will
172+
only occur within transparent areas defined by the mask file specified
173+
by -M. You may also supply just a single initial image with the areas
174+
to overpaint made transparent, but you must be careful not to destroy
175+
the pixels underneath when you create the transparent areas. See
176+
[Inpainting](./INPAINTING.md) for details.
177+
178+
inpainting accepts all the arguments used for txt2img and img2img, as
179+
well as the --mask (-M) argument:
180+
181+
| Argument | Shortcut | Default | Description |
182+
|--------------------|------------|---------------------|--------------|
183+
| --init_mask <path> | -M<path> | None |Path to an image the same size as the initial_image, with areas for inpainting made transparent.|
184+
185+
186+
# Command-line editing and completion
187+
188+
If you are on a Macintosh or Linux machine, the command-line offers
189+
convenient history tracking, editing, and command completion.
190+
191+
- To scroll through previous commands and potentially edit/reuse them, use the up and down cursor keys.
192+
- To edit the current command, use the left and right cursor keys to position the cursor, and then backspace, delete or insert characters.
193+
- To move to the very beginning of the command, type CTRL-A (or command-A on the Mac)
194+
- To move to the end of the command, type CTRL-E.
195+
- To cut a section of the command, position the cursor where you want to start cutting and type CTRL-K.
196+
- To paste a cut section back in, position the cursor where you want to paste, and type CTRL-Y
197+
198+
Windows users can get similar, but more limited, functionality if they
199+
launch dream.py with the "winpty" program:
200+
201+
~~~
202+
> winpty python scripts\dream.py
203+
~~~
204+
205+
On the Mac and Linux platforms, when you exit dream.py, the last 1000
206+
lines of your command-line history will be saved. When you restart
207+
dream.py, you can access the saved history using the up-arrow key.
208+
209+
In addition, limited command-line completion is installed. In various
210+
contexts, you can start typing your command and press tab. A list of
211+
potential completions will be presented to you. You can then type a
212+
little more, hit tab again, and eventually autocomplete what you want.
213+
214+
When specifying file paths using the one-letter shortcuts, the CLI
215+
will attempt to complete pathnames for you. This is most handy for the
216+
-I (init image) and -M (init mask) paths. To initiate completion, start
217+
the path with a slash ("/") or "./". For example:
218+
219+
~~~
220+
dream> zebra with a mustache -I./test-pictures<TAB>
221+
-I./test-pictures/Lincoln-and-Parrot.png -I./test-pictures/zebra.jpg -I./test-pictures/madonna.png
222+
-I./test-pictures/bad-sketch.png -I./test-pictures/man_with_eagle/
223+
~~~
224+
225+
You can then type "z", hit tab again, and it will autofill to "zebra.jpg".
226+
227+
More text completion features (such as autocompleting seeds) are on their way.
228+

docs/features/IMG2IMG.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
# **Image-to-Image**
22

3-
This script also provides an img2img feature that lets you seed your creations with an initial drawing or photo. This is a really cool feature that tells stable diffusion to build the prompt on top of the image you provide, preserving the original's basic shape and layout. To use it, provide the `--init_img` option as shown here:
3+
This script also provides an img2img feature that lets you seed your
4+
creations with an initial drawing or photo. This is a really cool
5+
feature that tells stable diffusion to build the prompt on top of the
6+
image you provide, preserving the original's basic shape and
7+
layout. To use it, provide the `--init_img` option as shown here:
48

59
```
610
dream> "waterfall and rainbow" --init_img=./init-images/crude_drawing.png --strength=0.5 -s100 -n4
711
```
812

9-
The `--init_img (-I)` option gives the path to the seed picture. `--strength (-f)` controls how much the original will be modified, ranging from `0.0` (keep the original intact), to `1.0` (ignore
10-
the original completely). The default is `0.75`, and ranges from `0.25-0.75` give interesting results.
13+
The `--init_img (-I)` option gives the path to the seed
14+
picture. `--strength (-f)` controls how much the original will be
15+
modified, ranging from `0.0` (keep the original intact), to `1.0`
16+
(ignore the original completely). The default is `0.75`, and ranges
17+
from `0.25-0.75` give interesting results.
1118

12-
You may also pass a `-v<count>` option to generate count variants on the original image. This is done by passing the first generated image back into img2img the requested number of times. It generates interesting variants.
19+
You may also pass a `-v<count>` option to generate count variants on
20+
the original image. This is done by passing the first generated image
21+
back into img2img the requested number of times. It generates
22+
interesting variants.
1323

14-
If the initial image contains transparent regions, then Stable Diffusion will only draw within the transparent regions, a process
15-
called "inpainting". However, for this to work correctly, the color information underneath the transparent needs to be preserved, not erased. See [Creating Transparent Images For Inpainting](./INPAINTING.md#creating-transparent-regions-for-inpainting) for details.
24+
If the initial image contains transparent regions, then Stable
25+
Diffusion will only draw within the transparent regions, a process
26+
called "inpainting". However, for this to work correctly, the color
27+
information underneath the transparent needs to be preserved, not
28+
erased. See [Creating Transparent Images For
29+
Inpainting](./INPAINTING.md#creating-transparent-regions-for-inpainting)
30+
for details.

docs/features/OTHER.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ For example consider this prompt:
8383
tabby cat:0.25 white duck:0.75 hybrid
8484
```
8585

86-
This will tell the sampler to invest 25% of its effort on the tabby cat aspect of the image and 75% on the white duck aspect (surprisingly, this example actually works). The prompt weights can
87-
use any combination of integers and floating point numbers, and they do not need to add up to 1.
86+
This will tell the sampler to invest 25% of its effort on the tabby
87+
cat aspect of the image and 75% on the white duck aspect
88+
(surprisingly, this example actually works). The prompt weights can
89+
use any combination of integers and floating point numbers, and they
90+
do not need to add up to 1.
8891

8992
---
9093

@@ -93,22 +96,27 @@ use any combination of integers and floating point numbers, and they do not need
9396
For programmers who wish to incorporate stable-diffusion into other products, this repository includes a simplified API for text to image generation, which lets you create images from a prompt in just three lines of code:
9497

9598
```
96-
from ldm.simplet2i import T2I
97-
model = T2I()
98-
outputs = model.txt2img("a unicorn in manhattan")
99+
from ldm.generate import Generate
100+
g = Generate()
101+
outputs = g.txt2img("a unicorn in manhattan")
99102
```
100103

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

103-
Please see ldm/simplet2i.py for more information. A set of example scripts is coming RSN.
106+
Please see ldm/generate.py for more information. A set of example scripts is coming RSN.
104107

105108
---
106109

107110
## **Preload Models**
108111

109-
In situations where you have limited internet connectivity or are blocked behind a firewall, you can use the preload script to preload the required files for Stable Diffusion to run.
112+
In situations where you have limited internet connectivity or are
113+
blocked behind a firewall, you can use the preload script to preload
114+
the required files for Stable Diffusion to run.
110115

111-
The preload script `scripts/preload_models.py` needs to be run once at least while connected to the internet. In the following runs, it will load up the cached versions of the required files from the `.cache` directory of the system.
116+
The preload script `scripts/preload_models.py` needs to be run once at
117+
least while connected to the internet. In the following runs, it will
118+
load up the cached versions of the required files from the `.cache`
119+
directory of the system.
112120

113121
```
114122
(ldm) ~/stable-diffusion$ python3 ./scripts/preload_models.py

0 commit comments

Comments
 (0)