stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

Try dynamic thresholding

Open dtan3847 opened this issue 2 years ago • 7 comments

Adding dynamic thresholding by Birch-san: https://github.com/Birch-san/stable-diffusion/tree/dynamic-thresholding-6 Feature request here: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/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.

dtan3847 avatar Oct 30 '22 05:10 dtan3847

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.

dtan3847 avatar Oct 31 '22 01:10 dtan3847

Any update on this?

Novapone avatar Nov 05 '22 18:11 Novapone

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 avatar Nov 06 '22 01:11 dtan3847

Why closed? Was really looking forward to this feature.

Novapone avatar Nov 12 '22 20:11 Novapone

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

dtan3847 avatar Nov 12 '22 20:11 dtan3847

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.

dtan3847 avatar Dec 12 '22 01:12 dtan3847

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.

jnpatrick99 avatar Dec 12 '22 21:12 jnpatrick99

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.

AUTOMATIC1111 avatar Dec 24 '22 08:12 AUTOMATIC1111

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.

x-legion avatar Dec 24 '22 11:12 x-legion

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

dtan3847 avatar Dec 25 '22 03:12 dtan3847

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.

AUTOMATIC1111 avatar Dec 25 '22 05:12 AUTOMATIC1111

Yeah, I can work on making it an extension.

dtan3847 avatar Dec 26 '22 00:12 dtan3847

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

mykeehu avatar Jan 01 '23 10:01 mykeehu

@dtan3847 any progress?

x-legion avatar Jan 06 '23 17:01 x-legion

@dtan3847 any progress?

No progress, life and covid got in the way

dtan3847 avatar Jan 06 '23 23:01 dtan3847

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

mcmonkey4eva avatar Jan 27 '23 02:01 mcmonkey4eva

@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.

mykeehu avatar Jan 28 '23 17:01 mykeehu

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

mcmonkey4eva avatar Apr 08 '23 06:04 mcmonkey4eva