stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

Add save_intermediate_images script

Open kevinschaul opened this issue 2 years ago • 1 comments

Combines a few different scripts in various GitHub issues with some useful added features:

  • This script is set to scripts.AlwaysVisible, meaning it can be run in combination with other scripts
  • Intermediate images are saved using the same filename structure as the final images, in a subdirectory called "intermediates". The custom script in the wiki overwrites your intermediate images each time you generate new images
  • Allows you to save every N images (defaults to 5)
  • Allows you to save either denoised or noisy intermediate images

See #1026 See #2137 See #2094 See #2739 See #4709

kevinschaul avatar Dec 05 '22 23:12 kevinschaul

very nice but this will have to become an extension

AUTOMATIC1111 avatar Dec 10 '22 07:12 AUTOMATIC1111

This is a very useful functionality! I'm not sure if this is currently being converted to an extension, but if so I think there is a small bug in the current code. This:

save_image(image, os.path.join(p.outpath_samples, "intermediates"), f"{current_step:02}", seed=p.seed, p=p)

gives me filenames like 15-0000-4092713123.0-[prompt_spaces].png

I believe this would solve the issue:

save_image(image, os.path.join(p.outpath_samples, "intermediates"), f"{current_step:02}", seed=p.seed, prompt=p.prompt, p=p)

AlUlkesh avatar Dec 15 '22 00:12 AlUlkesh

I put Kevin's work into an extension and made a few changes:

  • put the UI in an Accordion
  • save all intermediates into their own subdirectory
  • include the prompt in the filename

Any thoughts?

https://github.com/AlUlkesh/sd_save_intermediate_images

AlUlkesh avatar Dec 16 '22 00:12 AlUlkesh

https://github.com/AlUlkesh/sd_save_intermediate_images

usefully. seems there's no export with ddim sampler. is it ok or just for me?

Any thoughts?

how about intermediate subfolder names correspond to index number of currently generated image instead of a sequence from zero? like xxxxx.image-filename-pattern-from-settings. => xxxxxx folder. or more odd way "last generated index number"+1 if there's no way to accure current number.

include the prompt in the filename

large prompts cropped and mostly useless, especially for large path. how about determine name from settings instead?

guruguruguro avatar Dec 18 '22 21:12 guruguruguro

Good suggestions, thanks.

Turns out DDIM and PLMS use VanillaStableDiffusionSampler, while the others use KDiffusionSampler. It looks like VanillaStableDiffusionSampler doesn't have callback-capabilities, so I'm not sure it's possible.

I'll look into them.

Update: Since the number-prefix of the final file is not determined before saving it, I'm repeating the logic in my script now. This is for filenames and folder names. That should make it a lot easier to correlate the immediate with the final image.

AlUlkesh avatar Dec 20 '22 14:12 AlUlkesh

it is now an extension: https://github.com/AlUlkesh/sd_save_intermediate_images

ClashSAN avatar Dec 22 '22 09:12 ClashSAN

Plz add API support to this extension

pnavitha avatar Apr 11 '24 10:04 pnavitha