Skip to content

Add save_intermediate_images script#5464

Closed
kevinschaul wants to merge 1 commit into
AUTOMATIC1111:masterfrom
kevinschaul:save-intermediate-images
Closed

Add save_intermediate_images script#5464
kevinschaul wants to merge 1 commit into
AUTOMATIC1111:masterfrom
kevinschaul:save-intermediate-images

Conversation

@kevinschaul

Copy link
Copy Markdown

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

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 AUTOMATIC1111#1026
See AUTOMATIC1111#2137
See AUTOMATIC1111#2094
See AUTOMATIC1111#2739
See AUTOMATIC1111#4709
@kevinschaul kevinschaul force-pushed the save-intermediate-images branch from a4dc4bb to db31726 Compare December 6, 2022 21:47
@AUTOMATIC1111

Copy link
Copy Markdown
Owner

very nice but this will have to become an extension

@AlUlkesh

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

@guruguruguro

guruguruguro commented Dec 18, 2022

Copy link
Copy Markdown

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?

@AlUlkesh

AlUlkesh commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

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.

@ClashSAN

Copy link
Copy Markdown
Collaborator

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

@ClashSAN ClashSAN closed this Dec 22, 2022
naderkhalil pushed a commit to brevdev/stable-diffusion-webui that referenced this pull request Apr 27, 2023
@pnavitha

Copy link
Copy Markdown

Plz add API support to this extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants