diff --git a/docs/features/CLI.md b/docs/features/CLI.md index f68379891d..1f861d45cb 100644 --- a/docs/features/CLI.md +++ b/docs/features/CLI.md @@ -85,6 +85,7 @@ overridden on a per-prompt basis (see [List of prompt arguments](#list-of-prompt | `--from_file ` | | `None` | Read list of prompts from a file. Use `-` to read from standard input | | `--model ` | | `stable-diffusion-1.4` | Loads model specified in configs/models.yaml. Currently one of "stable-diffusion-1.4" or "laion400m" | | `--full_precision` | `-F` | `False` | Run in slower full-precision mode. Needed for Macintosh M1/M2 hardware and some older video cards. | +| `--png_compression <0-9>` | `-z<0-9>` | 6 | Select level of compression for output files, from 0 (no compression) to 9 (max compression) | | `--web` | | `False` | Start in web server mode | | `--host ` | | `localhost` | Which network interface web server should listen on. Set to 0.0.0.0 to listen on any. | | `--port ` | | `9090` | Which port web server should listen for requests on. | @@ -153,6 +154,7 @@ Here are the invoke> command that apply to txt2img: | --seed | -S | None | Set the random seed for the next series of images. This can be used to recreate an image generated previously.| | --sampler | -A| k_lms | Sampler to use. Use -h to get list of available samplers. | | --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 | +| `--png_compression <0-9>` | `-z<0-9>` | 6 | Select level of compression for output files, from 0 (no compression) to 9 (max compression) | | --grid | -g | False | Turn on grid mode to return a single image combining all the images generated by this prompt | | --individual | -i | True | Turn off grid mode (deprecated; leave off --grid instead) | | --outdir | -o | outputs/img_samples | Temporarily change the location of these images | diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index 229d92b657..293d93d5a8 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -378,6 +378,14 @@ class Args(object): default='stable-diffusion-1.4', help='Indicates which diffusion model to load. (currently "stable-diffusion-1.4" (default) or "laion400m")', ) + model_group.add_argument( + '--png_compression','-z', + type=int, + default=6, + choices=range(0,9), + dest='png_compression', + help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.' + ) model_group.add_argument( '--sampler', '-A', @@ -649,6 +657,14 @@ class Args(object): dest='save_intermediates', help='Save every nth intermediate image into an "intermediates" directory within the output directory' ) + render_group.add_argument( + '--png_compression','-z', + type=int, + default=6, + choices=range(0,10), + dest='png_compression', + help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.' + ) img2img_group.add_argument( '-I', '--init_img', diff --git a/ldm/invoke/pngwriter.py b/ldm/invoke/pngwriter.py index feee907d7f..8f38e1add0 100644 --- a/ldm/invoke/pngwriter.py +++ b/ldm/invoke/pngwriter.py @@ -33,13 +33,13 @@ class PngWriter: # saves image named _image_ to outdir/name, writing metadata from prompt # returns full path of output - def save_image_and_prompt_to_png(self, image, dream_prompt, name, metadata=None): + def save_image_and_prompt_to_png(self, image, dream_prompt, name, metadata=None, compress_level=6): path = os.path.join(self.outdir, name) info = PngImagePlugin.PngInfo() info.add_text('Dream', dream_prompt) if metadata: info.add_text('sd-metadata', json.dumps(metadata)) - image.save(path, 'PNG', pnginfo=info) + image.save(path, 'PNG', pnginfo=info, compress_level=compress_level) return path def retrieve_metadata(self,img_basename): diff --git a/ldm/invoke/readline.py b/ldm/invoke/readline.py index 4dd4abf14f..309a7c55a1 100644 --- a/ldm/invoke/readline.py +++ b/ldm/invoke/readline.py @@ -53,6 +53,7 @@ COMMANDS = ( '--log_tokenization','-t', '--hires_fix', '--inpaint_replace','-r', + '--png_compression','-z', '!fix','!fetch','!history','!search','!clear', '!models','!switch','!import_model','!edit_model' ) diff --git a/ldm/modules/diffusionmodules/util.py b/ldm/modules/diffusionmodules/util.py index 60b4d8a028..3d08fb89fd 100644 --- a/ldm/modules/diffusionmodules/util.py +++ b/ldm/modules/diffusionmodules/util.py @@ -64,7 +64,8 @@ def make_ddim_timesteps( ): if ddim_discr_method == 'uniform': c = num_ddpm_timesteps // num_ddim_timesteps - ddim_timesteps = np.asarray(list(range(0, num_ddpm_timesteps, c))) + # ddim_timesteps = np.asarray(list(range(0, num_ddpm_timesteps, c))) + ddim_timesteps = (np.arange(0, num_ddim_timesteps) * c).astype(int) elif ddim_discr_method == 'quad': ddim_timesteps = ( ( @@ -81,8 +82,8 @@ def make_ddim_timesteps( # assert ddim_timesteps.shape[0] == num_ddim_timesteps # add one to get the final alpha values right (the ones from first scale to data during sampling) -# steps_out = ddim_timesteps + 1 - steps_out = ddim_timesteps + steps_out = ddim_timesteps + 1 + # steps_out = ddim_timesteps if verbose: print(f'Selected timesteps for ddim sampler: {steps_out}') diff --git a/scripts/invoke.py b/scripts/invoke.py index 49ec2e19c9..8ea71c0de5 100644 --- a/scripts/invoke.py +++ b/scripts/invoke.py @@ -273,6 +273,7 @@ def main_loop(gen, opt, infile): model_hash = gen.model_hash, ), name = filename, + compress_level = opt.png_compression, ) # update rfc metadata