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

Feature Request: Option to dump every K steps result to files #2739

Closed
lockmatrix opened this issue Oct 15, 2022 · 10 comments
Closed

Feature Request: Option to dump every K steps result to files #2739

lockmatrix opened this issue Oct 15, 2022 · 10 comments

Comments

@lockmatrix
Copy link

lockmatrix commented Oct 15, 2022

Describe the solution you'd like
Feature Request: Option to dump every K steps result to files

Used to help analyze the effect of step number (more than 20) on the image.
Maybe can find some strategy for auto step number by using this.

@lockmatrix lockmatrix changed the title Feature Request: Option to dump every step result to files Feature Request: Option to dump every K steps result to files Oct 15, 2022
@Rhyono
Copy link

Rhyono commented Oct 15, 2022

I believe you're looking for the Script: X/Y plot option. For your particular use case, I believe setting X type Seed with a static seed, then Y type as Steps. In the Steps, you'd set your steps such as 20-100 [10]

That would give you a grid (plus the raw images in output) showing the effects of step every 10 steps.

@lockmatrix
Copy link
Author

lockmatrix commented Oct 15, 2022

I believe you're looking for the Script: X/Y plot option.

Will X/Y plot option reduce the repeated calculation process?
I dont need the grid plot feature, I can compare image myself.

@hd-x
Copy link

hd-x commented Oct 15, 2022

I think you want this script https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts#saving-steps-of-the-sampling-process

@asaucedev
Copy link

I believe you're looking for the Script: X/Y plot option.

Will X/Y plot option reduce the repeated calculation process? I dont need the grid plot feature, I can compare image myself.

The reason this isn't a default feature is that step 40 of a 100 step generation is not the same result as step 40 of a 40 step generation

@cmp-nct
Copy link

cmp-nct commented Oct 15, 2022

I believe you're looking for the Script: X/Y plot option.

Will X/Y plot option reduce the repeated calculation process? I dont need the grid plot feature, I can compare image myself.

The reason this isn't a default feature is that step 40 of a 100 step generation is not the same result as step 40 of a 40 step generation

The step 20/40 is also not the same as 20/100 according to preview snapshots.
Do you happen to know why ?

@asaucedev
Copy link

asaucedev commented Oct 15, 2022

My assumption is that there's some kind of parabolic curve to the math applied, where either towards the beginning, towards the end, or both, the processing scales differently. I don't know for certain.

Later edit: this is incorrect, and step count is the number of operations the denoising is broken down into
(e.g. 10 step tries to do 10% of the final result at a time, 50 step tries to do 2% at a time)

@aleksusklim
Copy link

Do you happen to know why ?

#1113 (comment)

@lockmatrix
Copy link
Author

lockmatrix commented Oct 16, 2022

I think you want this script https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts#saving-steps-of-the-sampling-process

this is what I need:

import os.path

import modules.scripts as scripts
import gradio as gr

from modules import sd_samplers, shared
from modules.processing import Processed, process_images


class Script(scripts.Script):
    def title(self):
        return "Save steps of the sampling process to files"

    def ui(self, is_img2img):
        path = gr.Textbox(label="Save images to path")
        start_save_step = gr.Textbox(label="Save images from step K", value="20")
        save_every_step = gr.Textbox(label="Save images every N steps", value="3")
        return [path, start_save_step, save_every_step]

    def run(self, p, path, start_save_step, save_every_step):
        index = [0]
        start_save_step = int(start_save_step)
        save_every_step = int(save_every_step)

        def store_latent(x):
            if index[0] >= start_save_step and (index[0] - start_save_step) % save_every_step == 0:
                image = shared.state.current_image = sd_samplers.sample_to_image(x)
                image.save(os.path.join(path, f"sample-{index[0]:05}.png"))
            index[0] += 1
            fun(x)

        fun = sd_samplers.store_latent
        sd_samplers.store_latent = store_latent

        try:
            proc = process_images(p)
        finally:
            sd_samplers.store_latent = fun

        return Processed(p, proc.images, p.seed, "")

While it seem dont work when use batch size > 1, it can only dump first image in the batch.

@lockmatrix
Copy link
Author

This is same with #1026
But I think this feature is still useful for debugging hyper params.

kevinschaul added a commit to kevinschaul/stable-diffusion-webui that referenced this issue Dec 5, 2022
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 added a commit to kevinschaul/stable-diffusion-webui that referenced this issue Dec 6, 2022
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
@ClashSAN
Copy link
Collaborator

#5905 (comment)

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

No branches or pull requests

7 participants