diff --git a/docs/features/OTHER.md b/docs/features/OTHER.md index 6aab5282756..0c478c0bfe5 100644 --- a/docs/features/OTHER.md +++ b/docs/features/OTHER.md @@ -71,6 +71,20 @@ combination of integers and floating point numbers, and they do not need to add --- +## Filename Format + +The argument `--fnformat` allows to specify the filename of the image. Supported wildcards are all arguments what can be set such as + `perlin`, `seed`, `threshold`, `height`, `width`, `gfpgan_strength`, `sampler_name`, `steps`, `model`, `upscale`, `prompt`, `cfg_scale`, `prefix`. + +The following prompt +```bash +dream> a red car --steps 25 -C 9.8 --perlin 0.1 --fnformat {prompt}_steps.{steps}_cfg.{cfg_scale}_perlin.{perlin}.png +``` + +generates a file with the name: `outputs/img-samples/a red car_steps.25_cfg.9.8_perlin.0.1.png` + +--- + ## Thresholding and Perlin Noise Initialization Options Two new options are the thresholding (`--threshold`) and the perlin noise initialization (`--perlin`) options. Thresholding limits the range of the latent values during optimization, which helps combat oversaturation with higher CFG scale values. Perlin noise initialization starts with a percentage (a value ranging from 0 to 1) of perlin noise mixed into the initial noise. Both features allow for more variations and options in the course of generating images. diff --git a/ldm/dream/args.py b/ldm/dream/args.py index 20632861220..cbb7093f096 100644 --- a/ldm/dream/args.py +++ b/ldm/dream/args.py @@ -216,6 +216,7 @@ def dream_prompt_str(self,**kwargs): switches.append(f'-W {a["width"]}') switches.append(f'-H {a["height"]}') switches.append(f'-C {a["cfg_scale"]}') + switches.append(f'--fnformat {a["fnformat"]}') if a['perlin'] > 0: switches.append(f'--perlin {a["perlin"]}') if a['threshold'] > 0: @@ -590,6 +591,12 @@ def _create_dream_cmd_parser(self): type=float, help='Perlin noise scale (0.0 - 1.0) - add perlin noise to the initialization instead of the usual gaussian noise.', ) + render_group.add_argument( + '--fnformat', + default='{prefix}.{seed}.png', + type=str, + help='Overwrite the filename format. You can use any argument as wildcard enclosed in curly braces. Default is {prefix}.{seed}.png', + ) render_group.add_argument( '--grid', '-g', @@ -788,7 +795,7 @@ def metadata_dumps(opt, # remove any image keys not mentioned in RFC #266 rfc266_img_fields = ['type','postprocessing','sampler','prompt','seed','variations','steps', - 'cfg_scale','threshold','perlin','step_number','width','height','extra','strength'] + 'cfg_scale','threshold','perlin','fnformat','step_number','width','height','extra','strength'] rfc_dict ={} diff --git a/scripts/dream.py b/scripts/dream.py index cd0d7c33b4b..dddbbdc85ca 100644 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -458,7 +458,17 @@ def prepare_image_metadata( if postprocessed and opt.save_original: filename = choose_postprocess_name(opt,prefix,seed) else: - filename = f'{prefix}.{seed}.png' + wildcards = dict(opt.__dict__) + wildcards['prefix'] = prefix + wildcards['seed'] = seed + try: + filename = opt.fnformat.format(**wildcards) + except KeyError as e: + print(f'The filename format contains an unknown key \'{e.args[0]}\'. Will use \'{{prefix}}.{{seed}}.png\' instead') + filename = f'{prefix}.{seed}.png' + except IndexError as e: + print(f'The filename format is broken or complete. Will use \'{{prefix}}.{{seed}}.png\' instead') + filename = f'{prefix}.{seed}.png' if opt.variation_amount > 0: first_seed = first_seed or seed