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

Try dynamic thresholding #3962

Closed
wants to merge 13 commits into from
Closed

Conversation

dtan3847
Copy link

Adding dynamic thresholding by Birch-san: https://github.com/Birch-san/stable-diffusion/tree/dynamic-thresholding-6
Feature request here: #3268

Not ready to merge since settings are hardcoded right now. It'd be faster if someone else familiar with the UI could help with that, but I can probably do it.

Thresholding not implemented for VanillaStableDiffusionSamplers DDIM/PLMS.
@dtan3847
Copy link
Author

Added UI to the main txt2img, img2img (not settings). The thresholding is not implemented for DDIM/PLMS samplers.

Weird horizontal lines appear during generation which makes me think something's not right.

@Novapone
Copy link

Novapone commented Nov 5, 2022

Any update on this?

@dtan3847
Copy link
Author

dtan3847 commented Nov 6, 2022

The generated images don't have artifacts, but during generation there are horizontal stripes of the same color which seem to be affecting the output. It's especially apparent when the actual CFG and mimic CFG are far apart. I'm not sure if this is inherent to the method or a bug introduced when I added it to this repository, but I don't have time to debug it.

@dtan3847 dtan3847 closed this Nov 12, 2022
@Novapone
Copy link

Why closed? Was really looking forward to this feature.

@dtan3847
Copy link
Author

I don't have time for it, and it's better not to leave hope. Maybe someone else will pick it up.

David Tan added 8 commits December 10, 2022 17:02
Prompt combination with AND, etc. still does not work
Also, include generation params in image depending on threshold_enable.
Latent normalization still happens even if threshold percentile = 1.
@dtan3847 dtan3847 reopened this Dec 12, 2022
@dtan3847 dtan3847 marked this pull request as ready for review December 12, 2022 01:06
@dtan3847
Copy link
Author

I made some time and fixed the horizontal line issue, moved "threshold percentile" into settings, made it compatible with prompt combination (AND, OR), and fixed the "paste previous prompt" button not working. There should be no issues now.

Clicking the "paste previous prompt" button twice erases the negative prompt and hides the rows, but that seems like a seaprate issue.

For those curious about what the horizontal line thing was, the shape of "cond" was incorrect, so it wasn't being flattened properly.

@jnpatrick99
Copy link

jnpatrick99 commented Dec 12, 2022

Wow, looks exciting!

But so far it didn't do anything on my end. How do I enable this mode? I noticed that threshold_enable is False? Maybe that's the case? I also don't see "threshold percentile" in my Settings. Thank you

Update: Nevermind! I found it, it's called "Latent fix" :-)

Update2: Works pretty cool on my end btw, no more "image overheating" on high CFG scales.

@AUTOMATIC1111
Copy link
Owner

I haven't been able to get good results with this. For example, this is image generated with CFG 20:
grid-0004

CFG 20 with latent fix mimic scale 5:
grid-0005

Just CFG 5:
grid-0003

Other params are in pnginfo.

@x-legion
Copy link

I haven't been able to get good results with this. For example, this is image generated with CFG 20: grid-0004

CFG 20 with latent fix mimic scale 5: grid-0005

Just CFG 5: grid-0003

Other params are in pnginfo.

00176-397772896-a portrait painting of daenerys targaryen queen in fantastic dress next to a dragon, embellished crystal and gemstones, medium s
00098-3213045619-dreamlikeart_Necromancer_Sorceress_in_center_fantasy_magic_undercut_hairstyle_dark_light_night_intricate_elegant_sharp_fo
00216-1266552592-8k portrait of beautiful young woman with brown hair dissolving, intricate, elegant, highly detailed, majestic, digital photogra
00215-2421104348-8k portrait of beautiful young woman with brown hair dissolving, intricate, elegant, highly detailed, majestic, digital photogra
00214-3534048388-3_4 portrait gorgeous asian emporer concubine geisha warrior wearing a black and tyrian silk kimono, golden hour edgy, gritty, c
00212-3561220656-3_4 portrait gorgeous asian emporer concubine geisha warrior wearing a black and tyrian silk kimono, golden hour edgy, gritty, c
I am getting incredible results from this . Using my own mix https://huggingface.co/faisalhr1997/sd_1.6/resolve/main/sd%201.6%20dream%20remix.ckpt
Parameters should be in the png info. And cfg 30 mimic 6.5.

@dtan3847
Copy link
Author

I haven't been able to get good results with this. For example, this is image generated with CFG 20: ...

I'm not sure why it gets so washed out. Maybe the difference between actual CFG and mimic CFG cannot be too big.

I tried redoing it but with mimic scale 11 and it looks decent, (7ab762a7 anything-v3 pruned fp16, plus vae):
remake-attempt

@AUTOMATIC1111
Copy link
Owner

Looking at the code, most of the work is done in _dynthresh function. I added combine_denoised(self, x_out, conds_list, uncond, cond_scale) function to the CFGDenoiser, so this should make it quite a lot easier to override the current functionality with what this PR does. As it modifies the UI, I'd prefer if it was added as an extension so that people who want it can enable it.

@dtan3847
Copy link
Author

Yeah, I can work on making it an extension.

@mykeehu
Copy link
Contributor

mykeehu commented Jan 1, 2023

I'm also looking forward to this extension, because it would help a lot to generate better images

@x-legion
Copy link

x-legion commented Jan 6, 2023

@dtan3847 any progress?

@dtan3847
Copy link
Author

dtan3847 commented Jan 6, 2023

@dtan3847 any progress?

No progress, life and covid got in the way

@mcmonkey4eva
Copy link
Contributor

mcmonkey4eva commented Jan 27, 2023

As the original author of this PR is unable to continue work, I went ahead myself to build an extension based on it: https://github.com/mcmonkeyprojects/sd-dynamic-thresholding

@mykeehu
Copy link
Contributor

mykeehu commented Jan 28, 2023

@mcmonkey4eva this turned out great! What would be nice is to have the parameters embedded in the image and TXT for reproduction - if it can be done.
This is the best setup I've found so far, the faces are nicely done without any restoration!
image

I hope @AUTOMATIC1111 will add it to the extension list.

@mcmonkey4eva
Copy link
Contributor

Update your webui, you're very far behind. For further issues post @ https://github.com/mcmonkeyprojects/sd-dynamic-thresholding/issues

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.

None yet

8 participants