Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save_intermediate_images script #5464

Closed

Conversation

kevinschaul
Copy link

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
Owner

very nice but this will have to become an extension

@AlUlkesh
Copy link
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
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
Copy link

guruguruguro commented Dec 18, 2022

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
Copy link
Contributor

AlUlkesh commented Dec 20, 2022

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
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
Netherquark pushed a commit to Netherquark/stable-diffusion-webui that referenced this pull request Apr 9, 2024
@pnavitha
Copy link

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