AUTOMATIC1111/stable-diffusion-webui

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

lockmatrix opened this issue ยท 10 comments

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.

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.

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.

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

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 ?

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)

Do you happen to know why ?

#1113 (comment)

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.

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