Skip to content

Commit c974c95

Browse files
committed
Merge branch 'development' of github.com:invoke-ai/InvokeAI into development
2 parents 3b25902 + 1c2bd27 commit c974c95

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

docs/features/CLI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ overridden on a per-prompt basis (see [List of prompt arguments](#list-of-prompt
8585
| `--from_file <path>` | | `None` | Read list of prompts from a file. Use `-` to read from standard input |
8686
| `--model <modelname>` | | `stable-diffusion-1.4` | Loads model specified in configs/models.yaml. Currently one of "stable-diffusion-1.4" or "laion400m" |
8787
| `--full_precision` | `-F` | `False` | Run in slower full-precision mode. Needed for Macintosh M1/M2 hardware and some older video cards. |
88+
| `--png_compression <0-9>` | `-z<0-9>` | 6 | Select level of compression for output files, from 0 (no compression) to 9 (max compression) |
8889
| `--web` | | `False` | Start in web server mode |
8990
| `--host <ip addr>` | | `localhost` | Which network interface web server should listen on. Set to 0.0.0.0 to listen on any. |
9091
| `--port <port>` | | `9090` | Which port web server should listen for requests on. |
@@ -153,6 +154,7 @@ Here are the invoke> command that apply to txt2img:
153154
| --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.|
154155
| --sampler <sampler>| -A<sampler>| k_lms | Sampler to use. Use -h to get list of available samplers. |
155156
| --hires_fix | | | Larger images often have duplication artefacts. This option suppresses duplicates by generating the image at low res, and then using img2img to increase the resolution |
157+
| `--png_compression <0-9>` | `-z<0-9>` | 6 | Select level of compression for output files, from 0 (no compression) to 9 (max compression) |
156158
| --grid | -g | False | Turn on grid mode to return a single image combining all the images generated by this prompt |
157159
| --individual | -i | True | Turn off grid mode (deprecated; leave off --grid instead) |
158160
| --outdir <path> | -o<path> | outputs/img_samples | Temporarily change the location of these images |

ldm/invoke/args.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ def _create_arg_parser(self):
378378
default='stable-diffusion-1.4',
379379
help='Indicates which diffusion model to load. (currently "stable-diffusion-1.4" (default) or "laion400m")',
380380
)
381+
model_group.add_argument(
382+
'--png_compression','-z',
383+
type=int,
384+
default=6,
385+
choices=range(0,9),
386+
dest='png_compression',
387+
help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.'
388+
)
381389
model_group.add_argument(
382390
'--sampler',
383391
'-A',
@@ -649,6 +657,14 @@ def _create_dream_cmd_parser(self):
649657
dest='save_intermediates',
650658
help='Save every nth intermediate image into an "intermediates" directory within the output directory'
651659
)
660+
render_group.add_argument(
661+
'--png_compression','-z',
662+
type=int,
663+
default=6,
664+
choices=range(0,10),
665+
dest='png_compression',
666+
help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.'
667+
)
652668
img2img_group.add_argument(
653669
'-I',
654670
'--init_img',

ldm/invoke/pngwriter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def unique_prefix(self):
3333

3434
# saves image named _image_ to outdir/name, writing metadata from prompt
3535
# returns full path of output
36-
def save_image_and_prompt_to_png(self, image, dream_prompt, name, metadata=None):
36+
def save_image_and_prompt_to_png(self, image, dream_prompt, name, metadata=None, compress_level=6):
3737
path = os.path.join(self.outdir, name)
3838
info = PngImagePlugin.PngInfo()
3939
info.add_text('Dream', dream_prompt)
4040
if metadata:
4141
info.add_text('sd-metadata', json.dumps(metadata))
42-
image.save(path, 'PNG', pnginfo=info)
42+
image.save(path, 'PNG', pnginfo=info, compress_level=compress_level)
4343
return path
4444

4545
def retrieve_metadata(self,img_basename):

ldm/invoke/readline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'--log_tokenization','-t',
5454
'--hires_fix',
5555
'--inpaint_replace','-r',
56+
'--png_compression','-z',
5657
'!fix','!fetch','!history','!search','!clear',
5758
'!models','!switch','!import_model','!edit_model'
5859
)

ldm/modules/diffusionmodules/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def make_ddim_timesteps(
6464
):
6565
if ddim_discr_method == 'uniform':
6666
c = num_ddpm_timesteps // num_ddim_timesteps
67-
ddim_timesteps = np.asarray(list(range(0, num_ddpm_timesteps, c)))
67+
# ddim_timesteps = np.asarray(list(range(0, num_ddpm_timesteps, c)))
68+
ddim_timesteps = (np.arange(0, num_ddim_timesteps) * c).astype(int)
6869
elif ddim_discr_method == 'quad':
6970
ddim_timesteps = (
7071
(
@@ -81,8 +82,8 @@ def make_ddim_timesteps(
8182

8283
# assert ddim_timesteps.shape[0] == num_ddim_timesteps
8384
# add one to get the final alpha values right (the ones from first scale to data during sampling)
84-
# steps_out = ddim_timesteps + 1
85-
steps_out = ddim_timesteps
85+
steps_out = ddim_timesteps + 1
86+
# steps_out = ddim_timesteps
8687

8788
if verbose:
8889
print(f'Selected timesteps for ddim sampler: {steps_out}')

scripts/invoke.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def image_writer(image, seed, upscaled=False, first_seed=None, use_prefix=None):
273273
model_hash = gen.model_hash,
274274
),
275275
name = filename,
276+
compress_level = opt.png_compression,
276277
)
277278

278279
# update rfc metadata

0 commit comments

Comments
 (0)