Skip to content

Commit

Permalink
Merge branch 'development' of github.com:invoke-ai/InvokeAI into deve…
Browse files Browse the repository at this point in the history
…lopment
  • Loading branch information
lstein committed Oct 18, 2022
2 parents 3b25902 + 1c2bd27 commit c974c95
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/features/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ overridden on a per-prompt basis (see [List of prompt arguments](#list-of-prompt
| `--from_file <path>` | | `None` | Read list of prompts from a file. Use `-` to read from standard input |
| `--model <modelname>` | | `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 <ip addr>` | | `localhost` | Which network interface web server should listen on. Set to 0.0.0.0 to listen on any. |
| `--port <port>` | | `9090` | Which port web server should listen for requests on. |
Expand Down Expand Up @@ -153,6 +154,7 @@ Here are the invoke> command that apply to txt2img:
| --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.|
| --sampler <sampler>| -A<sampler>| 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 <path> | -o<path> | outputs/img_samples | Temporarily change the location of these images |
Expand Down
16 changes: 16 additions & 0 deletions ldm/invoke/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ def _create_arg_parser(self):
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',
Expand Down Expand Up @@ -649,6 +657,14 @@ def _create_dream_cmd_parser(self):
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',
Expand Down
4 changes: 2 additions & 2 deletions ldm/invoke/pngwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def unique_prefix(self):

# 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):
Expand Down
1 change: 1 addition & 0 deletions ldm/invoke/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'--log_tokenization','-t',
'--hires_fix',
'--inpaint_replace','-r',
'--png_compression','-z',
'!fix','!fetch','!history','!search','!clear',
'!models','!switch','!import_model','!edit_model'
)
Expand Down
7 changes: 4 additions & 3 deletions ldm/modules/diffusionmodules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
(
Expand All @@ -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}')
Expand Down
1 change: 1 addition & 0 deletions scripts/invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def image_writer(image, seed, upscaled=False, first_seed=None, use_prefix=None):
model_hash = gen.model_hash,
),
name = filename,
compress_level = opt.png_compression,
)

# update rfc metadata
Expand Down

0 comments on commit c974c95

Please sign in to comment.