Upload extensions using SD-Hub extension
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +86 -0
- extensions/1-sd-dynamic-thresholding/.github/FUNDING.yml +1 -0
- extensions/1-sd-dynamic-thresholding/.github/workflows/publish.yml +21 -0
- extensions/1-sd-dynamic-thresholding/.gitignore +1 -0
- extensions/1-sd-dynamic-thresholding/LICENSE.txt +21 -0
- extensions/1-sd-dynamic-thresholding/README.md +120 -0
- extensions/1-sd-dynamic-thresholding/__init__.py +6 -0
- extensions/1-sd-dynamic-thresholding/__pycache__/dynthres_core.cpython-310.pyc +0 -0
- extensions/1-sd-dynamic-thresholding/__pycache__/dynthres_unipc.cpython-310.pyc +0 -0
- extensions/1-sd-dynamic-thresholding/dynthres_comfyui.py +80 -0
- extensions/1-sd-dynamic-thresholding/dynthres_core.py +167 -0
- extensions/1-sd-dynamic-thresholding/dynthres_unipc.py +111 -0
- extensions/1-sd-dynamic-thresholding/github/cat_demo_1.jpg +0 -0
- extensions/1-sd-dynamic-thresholding/github/comfy_node.png +0 -0
- extensions/1-sd-dynamic-thresholding/github/grid_preview.png +0 -0
- extensions/1-sd-dynamic-thresholding/github/ui.png +0 -0
- extensions/1-sd-dynamic-thresholding/javascript/active.js +68 -0
- extensions/1-sd-dynamic-thresholding/pyproject.toml +13 -0
- extensions/1-sd-dynamic-thresholding/scripts/__pycache__/dynamic_thresholding.cpython-310.pyc +0 -0
- extensions/1-sd-dynamic-thresholding/scripts/dynamic_thresholding.py +270 -0
- extensions/ABG_extension/.gitignore +1 -0
- extensions/ABG_extension/README.md +32 -0
- extensions/ABG_extension/install.py +11 -0
- extensions/ABG_extension/scripts/__pycache__/app.cpython-310.pyc +0 -0
- extensions/ABG_extension/scripts/app.py +183 -0
- extensions/AdverseCleanerExtension/.gitignore +2 -0
- extensions/AdverseCleanerExtension/LICENSE +201 -0
- extensions/AdverseCleanerExtension/README.md +8 -0
- extensions/AdverseCleanerExtension/install.py +12 -0
- extensions/AdverseCleanerExtension/scripts/__pycache__/denoise.cpython-310.pyc +0 -0
- extensions/AdverseCleanerExtension/scripts/denoise.py +74 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/Examples +62 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/Experiments +108 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/LICENSE +674 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/README.md +57 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/scripts/CFG Auto.py +368 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/scripts/CFG Schedule.py +369 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/scripts/__pycache__/CFG Auto.cpython-310.pyc +0 -0
- extensions/CFG-Schedule-for-Automatic1111-SD/scripts/__pycache__/CFG Schedule.cpython-310.pyc +0 -0
- extensions/CFG_Rescale_webui/.gitignore +160 -0
- extensions/CFG_Rescale_webui/LICENSE +21 -0
- extensions/CFG_Rescale_webui/README.md +10 -0
- extensions/CFG_Rescale_webui/scripts/CFGRescale.py +225 -0
- extensions/CFG_Rescale_webui/scripts/__pycache__/CFGRescale.cpython-310.pyc +0 -0
- extensions/DeepShrinkHires.fix/.gitignore +2 -0
- extensions/DeepShrinkHires.fix/scripts/DeepShrinkHires.fix.py +215 -0
- extensions/DeepShrinkHires.fix/scripts/__pycache__/DeepShrinkHires.fix.cpython-310.pyc +0 -0
- extensions/Euler-Smea-Dyn-Sampler/.gitignore +1 -0
- extensions/Euler-Smea-Dyn-Sampler/LICENSE +201 -0
- extensions/Euler-Smea-Dyn-Sampler/README.md +271 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,89 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
extensions/SD-WebUI-BatchCheckpointPrompt/img/grid.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
extensions/a1111-sd-webui-tagcomplete/tags/danbooru2023.csv filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
extensions/advanced_euler_sampler_extension/img/xyz_grid-0000-114514.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
extensions/diffusion-noise-alternatives-webui/images/ColorGrade.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
extensions/diffusion-noise-alternatives-webui/images/GrainCompare.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
extensions/latent-upscale/assets/default.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
extensions/latent-upscale/assets/img2img_latent_upscale_process.png filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
extensions/latent-upscale/assets/nearest-exact-normal1.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
extensions/latent-upscale/assets/nearest-exact-normal2.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
extensions/latent-upscale/assets/nearest-exact-simple1.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
extensions/latent-upscale/assets/nearest-exact-simple2.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
extensions/latent-upscale/assets/nearest-exact-simple8.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
extensions/lazy-pony-prompter/images/ef-showcase.jpg filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
extensions/lazy-pony-prompter/images/lulu.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
extensions/sd-civitai-browser-plus/aria2/lin/aria2 filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
extensions/sd-civitai-browser-plus/aria2/win/aria2.exe filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
extensions/sd-model-organizer/pic/readme/logo.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
extensions/sd-webui-agentattention/samples/xyz_grid-2415-1-desk.png filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
extensions/sd-webui-agentattention/samples/xyz_grid-2417-1-goldfinch,[[:space:]]Carduelis[[:space:]]carduelis.png filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
extensions/sd-webui-agentattention/samples/xyz_grid-2418-1-bell[[:space:]]pepper.png filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
extensions/sd-webui-agentattention/samples/xyz_grid-2419-1-bicycle.png filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
extensions/sd-webui-agentattention/samples/xyz_grid-2428-1-desk.jpg filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
extensions/sd-webui-cads/samples/comparison.png filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
extensions/sd-webui-cads/samples/grid-7069.png filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
extensions/sd-webui-cads/samples/grid-7070.png filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
extensions/sd-webui-cads_step/samples/comparison.png filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
extensions/sd-webui-cads_step/samples/grid-7069.png filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
extensions/sd-webui-cads_step/samples/grid-7070.png filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
extensions/sd-webui-cutoff/images/cover.jpg filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
extensions/sd-webui-cutoff/images/sample-1.png filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
extensions/sd-webui-cutoff/images/sample-2.png filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
extensions/sd-webui-cutoff/images/sample-3.png filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
extensions/sd-webui-cutoff/images/sample-4.png filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
extensions/sd-webui-cutoff/images/sample-4_small.png filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
extensions/sd-webui-cutoff/images/sample-5.png filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
extensions/sd-webui-cutoff/images/sample-5_small.png filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
extensions/sd-webui-dycfg/images/05.png filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
extensions/sd-webui-dycfg/images/09.png filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
extensions/sd-webui-fabric/static/example_2_default.png filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
extensions/sd-webui-fabric/static/example_2_feedback.png filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
extensions/sd-webui-fabric/static/example_3_10.png filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
extensions/sd-webui-fabric/static/example_3_feedback.png filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
extensions/sd-webui-fabric/static/fabric_demo.gif filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
extensions/sd-webui-image-comparison/tab.gif filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
extensions/sd-webui-incantations/images/xyz_grid-2652-1419902843-cinematic[[:space:]]4K[[:space:]]photo[[:space:]]of[[:space:]]a[[:space:]]dog[[:space:]]riding[[:space:]]a[[:space:]]bus[[:space:]]and[[:space:]]eating[[:space:]]cake[[:space:]]and[[:space:]]wearing[[:space:]]headphones.png filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
extensions/sd-webui-incantations/images/xyz_grid-2660-1590472902-A[[:space:]]photo[[:space:]]of[[:space:]]a[[:space:]]lion[[:space:]]and[[:space:]]a[[:space:]]grizzly[[:space:]]bear[[:space:]]and[[:space:]]a[[:space:]]tiger[[:space:]]in[[:space:]]the[[:space:]]woods.jpg filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
extensions/sd-webui-incantations/images/xyz_grid-3040-1-a[[:space:]]puppy[[:space:]]and[[:space:]]a[[:space:]]kitten[[:space:]]on[[:space:]]the[[:space:]]moon.png filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
extensions/sd-webui-incantations/images/xyz_grid-3348-1590472902-A[[:space:]]photo[[:space:]]of[[:space:]]a[[:space:]]lion[[:space:]]and[[:space:]]a[[:space:]]grizzly[[:space:]]bear[[:space:]]and[[:space:]]a[[:space:]]tiger[[:space:]]in[[:space:]]the[[:space:]]woods.jpg filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
extensions/sd-webui-infinite-image-browsing/iib.db filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
extensions/sd-webui-infinite-image-browsing/iib_db_backup/iib.db_2024-07-12[[:space:]]10-46-48 filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
extensions/sd-webui-infinite-image-browsing/iib_db_backup/iib.db_2024-07-12[[:space:]]10-50-48 filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
extensions/sd-webui-infinite-image-browsing/iib_db_backup/iib.db_2024-07-12[[:space:]]13-42-36 filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
extensions/sd-webui-infinite-image-browsing/iib_db_backup/iib.db_2024-07-12[[:space:]]13-46-57 filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
extensions/sd-webui-infinite-image-browsing/iib_db_backup/iib.db_2024-07-12[[:space:]]15-52-14 filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
extensions/sd-webui-llul/images/llul_yuv420p.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
extensions/sd-webui-llul/images/mask_effect.jpg filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
extensions/sd-webui-lora-masks/images/example.02.png filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
extensions/sd-webui-lora-masks/images/example.03.png filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
extensions/sd-webui-matview/images/sample1.jpg filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
extensions/sd-webui-pag/images/xyz_grid-3040-1-a[[:space:]]puppy[[:space:]]and[[:space:]]a[[:space:]]kitten[[:space:]]on[[:space:]]the[[:space:]]moon.png filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
extensions/sd-webui-samplers-scheduler/images/example2.png filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
extensions/sd-webui-samplers-scheduler/images/example3.png filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
extensions/sd-webui-semantic-guidance/samples/comparison.png filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
extensions/sd-webui-semantic-guidance/samples/enhance.jpg filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
extensions/sd-webui-smea/sample.jpg filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
extensions/sd-webui-smea/sample2.jpg filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
extensions/sd-webui-vectorscope-cc/samples/XYZ.jpg filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
extensions/sd-webui-xl_vec/images/crop_top.png filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
extensions/sd-webui-xl_vec/images/mult.png filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
extensions/sd-webui-xl_vec/images/original_size.png filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
extensions/sd_extension-prompt_formatter/Twemoji.Mozilla.ttf filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
extensions/sd_webui_masactrl/resources/img/xyz_grid-0010-1508457017.png filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
extensions/ssasd/images/sample.png filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
extensions/ssasd/images/sample2.png filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
extensions/ssasd/images/sample3.png filter=lfs diff=lfs merge=lfs -text
|
| 111 |
+
extensions/stable-diffusion-webui-composable-lora/readme/changelog_2023-04-08.png filter=lfs diff=lfs merge=lfs -text
|
| 112 |
+
extensions/stable-diffusion-webui-composable-lora/readme/fig11.png filter=lfs diff=lfs merge=lfs -text
|
| 113 |
+
extensions/stable-diffusion-webui-composable-lora/readme/fig12.png filter=lfs diff=lfs merge=lfs -text
|
| 114 |
+
extensions/stable-diffusion-webui-composable-lora/readme/fig13.png filter=lfs diff=lfs merge=lfs -text
|
| 115 |
+
extensions/stable-diffusion-webui-composable-lora/readme/fig8.png filter=lfs diff=lfs merge=lfs -text
|
| 116 |
+
extensions/stable-diffusion-webui-composable-lora/readme/fig9.png filter=lfs diff=lfs merge=lfs -text
|
| 117 |
+
extensions/stable-diffusion-webui-size-travel/img/ddim_advance.png filter=lfs diff=lfs merge=lfs -text
|
| 118 |
+
extensions/stable-diffusion-webui-size-travel/img/ddim_simple.png filter=lfs diff=lfs merge=lfs -text
|
| 119 |
+
extensions/stable-diffusion-webui-size-travel/img/eular_a_advance.png filter=lfs diff=lfs merge=lfs -text
|
| 120 |
+
extensions/stable-diffusion-webui-sonar/img/momentum.png filter=lfs diff=lfs merge=lfs -text
|
| 121 |
+
extensions/stable-diffusion-webui-tripclipskip/images/xy_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
extensions/1-sd-dynamic-thresholding/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
github: mcmonkey4eva
|
extensions/1-sd-dynamic-thresholding/.github/workflows/publish.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Publish to Comfy registry
|
| 2 |
+
on:
|
| 3 |
+
workflow_dispatch:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
paths:
|
| 8 |
+
- "pyproject.toml"
|
| 9 |
+
|
| 10 |
+
jobs:
|
| 11 |
+
publish-node:
|
| 12 |
+
name: Publish Custom Node to registry
|
| 13 |
+
runs-on: ubuntu-latest
|
| 14 |
+
steps:
|
| 15 |
+
- name: Check out code
|
| 16 |
+
uses: actions/checkout@v4
|
| 17 |
+
- name: Publish Custom Node
|
| 18 |
+
uses: Comfy-Org/publish-node-action@main
|
| 19 |
+
with:
|
| 20 |
+
## Add your own personal access token to your Github Repository secrets and reference it here.
|
| 21 |
+
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
extensions/1-sd-dynamic-thresholding/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
extensions/1-sd-dynamic-thresholding/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 Alex "mcmonkey" Goodwin
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
extensions/1-sd-dynamic-thresholding/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stable Diffusion Dynamic Thresholding (CFG Scale Fix)
|
| 2 |
+
|
| 3 |
+
### Concept
|
| 4 |
+
|
| 5 |
+
Extension for [StableSwarmUI](https://github.com/Stability-AI/StableSwarmUI), [ComfyUI](https://github.com/comfyanonymous/ComfyUI), and [AUTOMATIC1111 Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) that enables a way to use higher CFG Scales without color issues.
|
| 6 |
+
|
| 7 |
+
This works by clamping latents between steps. You can read more [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/3962) or [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/3268) or [this tweet](https://twitter.com/Birchlabs/status/1582165379832348672).
|
| 8 |
+
|
| 9 |
+
--------------
|
| 10 |
+
|
| 11 |
+
### Credit
|
| 12 |
+
|
| 13 |
+
The core functionality of this PR was originally developed by [Birch-san](https://github.com/Birch-san) and ported to the WebUI by [dtan3847](https://github.com/dtan3847), then converted to an Auto WebUI extension and given a UI by [mcmonkey4eva](https://github.com/mcmonkey4eva), further development and research done by [mcmonkey4eva](https://github.com/mcmonkey4eva) and JDMLeverton. Ported by ComfyUI by [TwoDukes](https://github.com/TwoDukes) and [mcmonkey4eva](https://github.com/mcmonkey4eva). Ported to StableSwarmUI by [mcmonkey4eva](https://github.com/mcmonkey4eva).
|
| 14 |
+
|
| 15 |
+
--------------
|
| 16 |
+
|
| 17 |
+
### Examples
|
| 18 |
+
|
| 19 |
+

|
| 20 |
+
|
| 21 |
+

|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
--------------
|
| 25 |
+
|
| 26 |
+
### Demo Grid
|
| 27 |
+
|
| 28 |
+
View at <https://sd.mcmonkey.org/dynthresh/>.
|
| 29 |
+
|
| 30 |
+

|
| 31 |
+
|
| 32 |
+
(Was generated via [this YAML config](https://gist.github.com/mcmonkey4eva/fccd29172f44424dfc0217a482c824f6) for the [Infinite Grid Generator](https://github.com/mcmonkeyprojects/sd-infinity-grid-generator-script))
|
| 33 |
+
|
| 34 |
+
--------------
|
| 35 |
+
|
| 36 |
+
### Installation and Usage
|
| 37 |
+
|
| 38 |
+
#### StableSwarmUI
|
| 39 |
+
|
| 40 |
+
- Supported out-of-the-box on default installations.
|
| 41 |
+
- If using a custom installation, just make sure the backend you use has this repo installed per the instructions specific to the backend as written below.
|
| 42 |
+
- It's under the "Display Advanced Options" parameter checkbox.
|
| 43 |
+
|
| 44 |
+
#### Auto WebUI
|
| 45 |
+
|
| 46 |
+
- You must have the [AUTOMATIC1111 Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) already installed and working. Refer to that project's readme for help with that.
|
| 47 |
+
- Open the WebUI, go to to the `Extensions` tab
|
| 48 |
+
- -EITHER- Option **A**:
|
| 49 |
+
- go to the `Available` tab with
|
| 50 |
+
- click `Load from` (with the default list)
|
| 51 |
+
- Scroll down to find `Dynamic Thresholding (CFG Scale Fix)`, or use `CTRL+F` to find it
|
| 52 |
+
- -OR- Option **B**:
|
| 53 |
+
- Click on `Install from URL`
|
| 54 |
+
- Copy/paste this project's URL into the `URL for extension's git repository` textbox: `https://github.com/mcmonkeyprojects/sd-dynamic-thresholding`
|
| 55 |
+
- Click `Install`
|
| 56 |
+
- Restart or reload the WebUI
|
| 57 |
+
- Go to txt2img or img2img
|
| 58 |
+
- Check the `Enable Dynamic Thresholding (CFG Scale Fix)` box
|
| 59 |
+
- Read the info on-page and set the sliders where you want em.
|
| 60 |
+
- Click generate.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
#### ComfyUI
|
| 64 |
+
|
| 65 |
+
- Must have [ComfyUI](https://github.com/comfyanonymous/ComfyUI) already installed and working. Refer to that project's readme for help with that.
|
| 66 |
+
- -EITHER- Option **A**: (TODO: Manager install)
|
| 67 |
+
- -OR- Option **B**:
|
| 68 |
+
- `cd ComfyUI/custom_nodes`
|
| 69 |
+
- `git clone https://github.com/mcmonkeyprojects/sd-dynamic-thresholding`
|
| 70 |
+
- restart ComfyUI
|
| 71 |
+
- Add node `advanced/mcmonkey/DynamicThresholdingSimple` (or `Full`)
|
| 72 |
+
- Link your model to the input, and then link the output model to your KSampler's input
|
| 73 |
+
|
| 74 |
+

|
| 75 |
+
|
| 76 |
+
--------------
|
| 77 |
+
|
| 78 |
+
### Supported Auto WebUI Extensions
|
| 79 |
+
|
| 80 |
+
- This can be configured within the [Infinity Grid Generator](https://github.com/mcmonkeyprojects/sd-infinity-grid-generator-script#supported-extensions) extension, see the readme of that project for details.
|
| 81 |
+
|
| 82 |
+
### ComfyUI Compatibility
|
| 83 |
+
|
| 84 |
+
- This would work with any variant of the `KSampler` node, including custom ones, so long as they do not totally override the internal sampling function (most don't).
|
| 85 |
+
|
| 86 |
+
----------------------
|
| 87 |
+
|
| 88 |
+
### Licensing pre-note:
|
| 89 |
+
|
| 90 |
+
This is an open source project, provided entirely freely, for everyone to use and contribute to.
|
| 91 |
+
|
| 92 |
+
If you make any changes that could benefit the community as a whole, please contribute upstream.
|
| 93 |
+
|
| 94 |
+
### The short of the license is:
|
| 95 |
+
|
| 96 |
+
You can do basically whatever you want, except you may not hold any developer liable for what you do with the software.
|
| 97 |
+
|
| 98 |
+
### The long version of the license follows:
|
| 99 |
+
|
| 100 |
+
The MIT License (MIT)
|
| 101 |
+
|
| 102 |
+
Copyright (c) 2023 Alex "mcmonkey" Goodwin
|
| 103 |
+
|
| 104 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 105 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 106 |
+
in the Software without restriction, including without limitation the rights
|
| 107 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 108 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 109 |
+
furnished to do so, subject to the following conditions:
|
| 110 |
+
|
| 111 |
+
The above copyright notice and this permission notice shall be included in all
|
| 112 |
+
copies or substantial portions of the Software.
|
| 113 |
+
|
| 114 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 115 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 116 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 117 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 118 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 119 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 120 |
+
SOFTWARE.
|
extensions/1-sd-dynamic-thresholding/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import dynthres_comfyui
|
| 2 |
+
|
| 3 |
+
NODE_CLASS_MAPPINGS = {
|
| 4 |
+
"DynamicThresholdingSimple": dynthres_comfyui.DynamicThresholdingSimpleComfyNode,
|
| 5 |
+
"DynamicThresholdingFull": dynthres_comfyui.DynamicThresholdingComfyNode,
|
| 6 |
+
}
|
extensions/1-sd-dynamic-thresholding/__pycache__/dynthres_core.cpython-310.pyc
ADDED
|
Binary file (4.49 kB). View file
|
|
|
extensions/1-sd-dynamic-thresholding/__pycache__/dynthres_unipc.cpython-310.pyc
ADDED
|
Binary file (4.92 kB). View file
|
|
|
extensions/1-sd-dynamic-thresholding/dynthres_comfyui.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .dynthres_core import DynThresh
|
| 2 |
+
|
| 3 |
+
class DynamicThresholdingComfyNode:
|
| 4 |
+
|
| 5 |
+
@classmethod
|
| 6 |
+
def INPUT_TYPES(s):
|
| 7 |
+
return {
|
| 8 |
+
"required": {
|
| 9 |
+
"model": ("MODEL",),
|
| 10 |
+
"mimic_scale": ("FLOAT", {"default": 7.0, "min": 0.0, "max": 100.0, "step": 0.5}),
|
| 11 |
+
"threshold_percentile": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
| 12 |
+
"mimic_mode": (DynThresh.Modes, ),
|
| 13 |
+
"mimic_scale_min": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 100.0, "step": 0.5}),
|
| 14 |
+
"cfg_mode": (DynThresh.Modes, ),
|
| 15 |
+
"cfg_scale_min": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 100.0, "step": 0.5}),
|
| 16 |
+
"sched_val": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01}),
|
| 17 |
+
"separate_feature_channels": (["enable", "disable"], ),
|
| 18 |
+
"scaling_startpoint": (DynThresh.Startpoints, ),
|
| 19 |
+
"variability_measure": (DynThresh.Variabilities, ),
|
| 20 |
+
"interpolate_phi": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
RETURN_TYPES = ("MODEL",)
|
| 25 |
+
FUNCTION = "patch"
|
| 26 |
+
CATEGORY = "advanced/mcmonkey"
|
| 27 |
+
|
| 28 |
+
def patch(self, model, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi):
|
| 29 |
+
|
| 30 |
+
dynamic_thresh = DynThresh(mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, 0, 999, separate_feature_channels == "enable", scaling_startpoint, variability_measure, interpolate_phi)
|
| 31 |
+
|
| 32 |
+
def sampler_dyn_thresh(args):
|
| 33 |
+
input = args["input"]
|
| 34 |
+
cond = input - args["cond"]
|
| 35 |
+
uncond = input - args["uncond"]
|
| 36 |
+
cond_scale = args["cond_scale"]
|
| 37 |
+
time_step = model.model.model_sampling.timestep(args["sigma"])
|
| 38 |
+
time_step = time_step[0].item()
|
| 39 |
+
dynamic_thresh.step = 999 - time_step
|
| 40 |
+
|
| 41 |
+
return input - dynamic_thresh.dynthresh(cond, uncond, cond_scale, None)
|
| 42 |
+
|
| 43 |
+
m = model.clone()
|
| 44 |
+
m.set_model_sampler_cfg_function(sampler_dyn_thresh)
|
| 45 |
+
return (m, )
|
| 46 |
+
|
| 47 |
+
class DynamicThresholdingSimpleComfyNode:
|
| 48 |
+
|
| 49 |
+
@classmethod
|
| 50 |
+
def INPUT_TYPES(s):
|
| 51 |
+
return {
|
| 52 |
+
"required": {
|
| 53 |
+
"model": ("MODEL",),
|
| 54 |
+
"mimic_scale": ("FLOAT", {"default": 7.0, "min": 0.0, "max": 100.0, "step": 0.5}),
|
| 55 |
+
"threshold_percentile": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
RETURN_TYPES = ("MODEL",)
|
| 60 |
+
FUNCTION = "patch"
|
| 61 |
+
CATEGORY = "advanced/mcmonkey"
|
| 62 |
+
|
| 63 |
+
def patch(self, model, mimic_scale, threshold_percentile):
|
| 64 |
+
|
| 65 |
+
dynamic_thresh = DynThresh(mimic_scale, threshold_percentile, "CONSTANT", 0, "CONSTANT", 0, 0, 0, 999, False, "MEAN", "AD", 1)
|
| 66 |
+
|
| 67 |
+
def sampler_dyn_thresh(args):
|
| 68 |
+
input = args["input"]
|
| 69 |
+
cond = input - args["cond"]
|
| 70 |
+
uncond = input - args["uncond"]
|
| 71 |
+
cond_scale = args["cond_scale"]
|
| 72 |
+
time_step = model.model.model_sampling.timestep(args["sigma"])
|
| 73 |
+
time_step = time_step[0].item()
|
| 74 |
+
dynamic_thresh.step = 999 - time_step
|
| 75 |
+
|
| 76 |
+
return input - dynamic_thresh.dynthresh(cond, uncond, cond_scale, None)
|
| 77 |
+
|
| 78 |
+
m = model.clone()
|
| 79 |
+
m.set_model_sampler_cfg_function(sampler_dyn_thresh)
|
| 80 |
+
return (m, )
|
extensions/1-sd-dynamic-thresholding/dynthres_core.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch, math
|
| 2 |
+
|
| 3 |
+
######################### DynThresh Core #########################
|
| 4 |
+
|
| 5 |
+
class DynThresh:
|
| 6 |
+
|
| 7 |
+
Modes = ["Constant", "Linear Down", "Cosine Down", "Half Cosine Down", "Linear Up", "Cosine Up", "Half Cosine Up", "Power Up", "Power Down", "Linear Repeating", "Cosine Repeating", "Sawtooth"]
|
| 8 |
+
Startpoints = ["MEAN", "ZERO"]
|
| 9 |
+
Variabilities = ["AD", "STD"]
|
| 10 |
+
|
| 11 |
+
def __init__(self, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, experiment_mode, max_steps, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi):
|
| 12 |
+
self.mimic_scale = mimic_scale
|
| 13 |
+
self.threshold_percentile = threshold_percentile
|
| 14 |
+
self.mimic_mode = mimic_mode
|
| 15 |
+
self.cfg_mode = cfg_mode
|
| 16 |
+
self.max_steps = max_steps
|
| 17 |
+
self.cfg_scale_min = cfg_scale_min
|
| 18 |
+
self.mimic_scale_min = mimic_scale_min
|
| 19 |
+
self.experiment_mode = experiment_mode
|
| 20 |
+
self.sched_val = sched_val
|
| 21 |
+
self.sep_feat_channels = separate_feature_channels
|
| 22 |
+
self.scaling_startpoint = scaling_startpoint
|
| 23 |
+
self.variability_measure = variability_measure
|
| 24 |
+
self.interpolate_phi = interpolate_phi
|
| 25 |
+
|
| 26 |
+
def interpret_scale(self, scale, mode, min):
|
| 27 |
+
scale -= min
|
| 28 |
+
max = self.max_steps - 1
|
| 29 |
+
frac = self.step / max
|
| 30 |
+
if mode == "Constant":
|
| 31 |
+
pass
|
| 32 |
+
elif mode == "Linear Down":
|
| 33 |
+
scale *= 1.0 - frac
|
| 34 |
+
elif mode == "Half Cosine Down":
|
| 35 |
+
scale *= math.cos(frac)
|
| 36 |
+
elif mode == "Cosine Down":
|
| 37 |
+
scale *= math.cos(frac * 1.5707)
|
| 38 |
+
elif mode == "Linear Up":
|
| 39 |
+
scale *= frac
|
| 40 |
+
elif mode == "Half Cosine Up":
|
| 41 |
+
scale *= 1.0 - math.cos(frac)
|
| 42 |
+
elif mode == "Cosine Up":
|
| 43 |
+
scale *= 1.0 - math.cos(frac * 1.5707)
|
| 44 |
+
elif mode == "Power Up":
|
| 45 |
+
scale *= math.pow(frac, self.sched_val)
|
| 46 |
+
elif mode == "Power Down":
|
| 47 |
+
scale *= 1.0 - math.pow(frac, self.sched_val)
|
| 48 |
+
elif mode == "Linear Repeating":
|
| 49 |
+
portion = (frac * self.sched_val) % 1.0
|
| 50 |
+
scale *= (0.5 - portion) * 2 if portion < 0.5 else (portion - 0.5) * 2
|
| 51 |
+
elif mode == "Cosine Repeating":
|
| 52 |
+
scale *= math.cos(frac * 6.28318 * self.sched_val) * 0.5 + 0.5
|
| 53 |
+
elif mode == "Sawtooth":
|
| 54 |
+
scale *= (frac * self.sched_val) % 1.0
|
| 55 |
+
scale += min
|
| 56 |
+
return scale
|
| 57 |
+
|
| 58 |
+
def dynthresh(self, cond, uncond, cfg_scale, weights):
|
| 59 |
+
mimic_scale = self.interpret_scale(self.mimic_scale, self.mimic_mode, self.mimic_scale_min)
|
| 60 |
+
cfg_scale = self.interpret_scale(cfg_scale, self.cfg_mode, self.cfg_scale_min)
|
| 61 |
+
# uncond shape is (batch, 4, height, width)
|
| 62 |
+
conds_per_batch = cond.shape[0] / uncond.shape[0]
|
| 63 |
+
assert conds_per_batch == int(conds_per_batch), "Expected # of conds per batch to be constant across batches"
|
| 64 |
+
cond_stacked = cond.reshape((-1, int(conds_per_batch)) + uncond.shape[1:])
|
| 65 |
+
|
| 66 |
+
### Normal first part of the CFG Scale logic, basically
|
| 67 |
+
diff = cond_stacked - uncond.unsqueeze(1)
|
| 68 |
+
if weights is not None:
|
| 69 |
+
diff = diff * weights
|
| 70 |
+
relative = diff.sum(1)
|
| 71 |
+
|
| 72 |
+
### Get the normal result for both mimic and normal scale
|
| 73 |
+
mim_target = uncond + relative * mimic_scale
|
| 74 |
+
cfg_target = uncond + relative * cfg_scale
|
| 75 |
+
### If we weren't doing mimic scale, we'd just return cfg_target here
|
| 76 |
+
|
| 77 |
+
### Now recenter the values relative to their average rather than absolute, to allow scaling from average
|
| 78 |
+
mim_flattened = mim_target.flatten(2)
|
| 79 |
+
cfg_flattened = cfg_target.flatten(2)
|
| 80 |
+
mim_means = mim_flattened.mean(dim=2).unsqueeze(2)
|
| 81 |
+
cfg_means = cfg_flattened.mean(dim=2).unsqueeze(2)
|
| 82 |
+
mim_centered = mim_flattened - mim_means
|
| 83 |
+
cfg_centered = cfg_flattened - cfg_means
|
| 84 |
+
|
| 85 |
+
if self.sep_feat_channels:
|
| 86 |
+
if self.variability_measure == 'STD':
|
| 87 |
+
mim_scaleref = mim_centered.std(dim=2).unsqueeze(2)
|
| 88 |
+
cfg_scaleref = cfg_centered.std(dim=2).unsqueeze(2)
|
| 89 |
+
else: # 'AD'
|
| 90 |
+
mim_scaleref = mim_centered.abs().max(dim=2).values.unsqueeze(2)
|
| 91 |
+
cfg_scaleref = torch.quantile(cfg_centered.abs(), self.threshold_percentile, dim=2).unsqueeze(2)
|
| 92 |
+
|
| 93 |
+
else:
|
| 94 |
+
if self.variability_measure == 'STD':
|
| 95 |
+
mim_scaleref = mim_centered.std()
|
| 96 |
+
cfg_scaleref = cfg_centered.std()
|
| 97 |
+
else: # 'AD'
|
| 98 |
+
mim_scaleref = mim_centered.abs().max()
|
| 99 |
+
cfg_scaleref = torch.quantile(cfg_centered.abs(), self.threshold_percentile)
|
| 100 |
+
|
| 101 |
+
if self.scaling_startpoint == 'ZERO':
|
| 102 |
+
scaling_factor = mim_scaleref / cfg_scaleref
|
| 103 |
+
result = cfg_flattened * scaling_factor
|
| 104 |
+
|
| 105 |
+
else: # 'MEAN'
|
| 106 |
+
if self.variability_measure == 'STD':
|
| 107 |
+
cfg_renormalized = (cfg_centered / cfg_scaleref) * mim_scaleref
|
| 108 |
+
else: # 'AD'
|
| 109 |
+
### Get the maximum value of all datapoints (with an optional threshold percentile on the uncond)
|
| 110 |
+
max_scaleref = torch.maximum(mim_scaleref, cfg_scaleref)
|
| 111 |
+
### Clamp to the max
|
| 112 |
+
cfg_clamped = cfg_centered.clamp(-max_scaleref, max_scaleref)
|
| 113 |
+
### Now shrink from the max to normalize and grow to the mimic scale (instead of the CFG scale)
|
| 114 |
+
cfg_renormalized = (cfg_clamped / max_scaleref) * mim_scaleref
|
| 115 |
+
|
| 116 |
+
### Now add it back onto the averages to get into real scale again and return
|
| 117 |
+
result = cfg_renormalized + cfg_means
|
| 118 |
+
|
| 119 |
+
actual_res = result.unflatten(2, mim_target.shape[2:])
|
| 120 |
+
|
| 121 |
+
if self.interpolate_phi != 1.0:
|
| 122 |
+
actual_res = actual_res * self.interpolate_phi + cfg_target * (1.0 - self.interpolate_phi)
|
| 123 |
+
|
| 124 |
+
if self.experiment_mode == 1:
|
| 125 |
+
num = actual_res.cpu().numpy()
|
| 126 |
+
for y in range(0, 64):
|
| 127 |
+
for x in range (0, 64):
|
| 128 |
+
if num[0][0][y][x] > 1.0:
|
| 129 |
+
num[0][1][y][x] *= 0.5
|
| 130 |
+
if num[0][1][y][x] > 1.0:
|
| 131 |
+
num[0][1][y][x] *= 0.5
|
| 132 |
+
if num[0][2][y][x] > 1.5:
|
| 133 |
+
num[0][2][y][x] *= 0.5
|
| 134 |
+
actual_res = torch.from_numpy(num).to(device=uncond.device)
|
| 135 |
+
elif self.experiment_mode == 2:
|
| 136 |
+
num = actual_res.cpu().numpy()
|
| 137 |
+
for y in range(0, 64):
|
| 138 |
+
for x in range (0, 64):
|
| 139 |
+
over_scale = False
|
| 140 |
+
for z in range(0, 4):
|
| 141 |
+
if abs(num[0][z][y][x]) > 1.5:
|
| 142 |
+
over_scale = True
|
| 143 |
+
if over_scale:
|
| 144 |
+
for z in range(0, 4):
|
| 145 |
+
num[0][z][y][x] *= 0.7
|
| 146 |
+
actual_res = torch.from_numpy(num).to(device=uncond.device)
|
| 147 |
+
elif self.experiment_mode == 3:
|
| 148 |
+
coefs = torch.tensor([
|
| 149 |
+
# R G B W
|
| 150 |
+
[0.298, 0.207, 0.208, 0.0], # L1
|
| 151 |
+
[0.187, 0.286, 0.173, 0.0], # L2
|
| 152 |
+
[-0.158, 0.189, 0.264, 0.0], # L3
|
| 153 |
+
[-0.184, -0.271, -0.473, 1.0], # L4
|
| 154 |
+
], device=uncond.device)
|
| 155 |
+
res_rgb = torch.einsum("laxy,ab -> lbxy", actual_res, coefs)
|
| 156 |
+
max_r, max_g, max_b, max_w = res_rgb[0][0].max(), res_rgb[0][1].max(), res_rgb[0][2].max(), res_rgb[0][3].max()
|
| 157 |
+
max_rgb = max(max_r, max_g, max_b)
|
| 158 |
+
print(f"test max = r={max_r}, g={max_g}, b={max_b}, w={max_w}, rgb={max_rgb}")
|
| 159 |
+
if self.step / (self.max_steps - 1) > 0.2:
|
| 160 |
+
if max_rgb < 2.0 and max_w < 3.0:
|
| 161 |
+
res_rgb /= max_rgb / 2.4
|
| 162 |
+
else:
|
| 163 |
+
if max_rgb > 2.4 and max_w > 3.0:
|
| 164 |
+
res_rgb /= max_rgb / 2.4
|
| 165 |
+
actual_res = torch.einsum("laxy,ab -> lbxy", res_rgb, coefs.inverse())
|
| 166 |
+
|
| 167 |
+
return actual_res
|
extensions/1-sd-dynamic-thresholding/dynthres_unipc.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import math
|
| 4 |
+
import traceback
|
| 5 |
+
from modules import shared
|
| 6 |
+
try:
|
| 7 |
+
from modules.models.diffusion import uni_pc
|
| 8 |
+
except Exception as e:
|
| 9 |
+
from modules import unipc as uni_pc
|
| 10 |
+
|
| 11 |
+
######################### UniPC Implementation logic #########################
|
| 12 |
+
|
| 13 |
+
# The majority of this is straight from modules.models/diffusion/uni_pc/sampler.py
|
| 14 |
+
# Unfortunately that's not an easy middle-injection point, so, just copypasta'd it all
|
| 15 |
+
# It's like they designed it to intentionally be as difficult to inject into as possible :(
|
| 16 |
+
# (It has hooks but not in useful locations)
|
| 17 |
+
# I stripped the original comments for brevity.
|
| 18 |
+
# Some never-used code (scheduler modes, noise modes, guidance modes) have been removed as well for brevity.
|
| 19 |
+
# The actual impl comes down to just the last line in particular, and the `before_sample` insert to track step count.
|
| 20 |
+
|
| 21 |
+
class CustomUniPCSampler(uni_pc.sampler.UniPCSampler):
|
| 22 |
+
def __init__(self, model, **kwargs):
|
| 23 |
+
super().__init__(model, *kwargs)
|
| 24 |
+
@torch.no_grad()
|
| 25 |
+
def sample(self, S, batch_size, shape, conditioning=None, callback=None, normals_sequence=None, img_callback=None,
|
| 26 |
+
quantize_x0=False, eta=0., mask=None, x0=None, temperature=1., noise_dropout=0., score_corrector=None,
|
| 27 |
+
corrector_kwargs=None, verbose=True, x_T=None, log_every_t=100, unconditional_guidance_scale=1.,
|
| 28 |
+
unconditional_conditioning=None, **kwargs):
|
| 29 |
+
if conditioning is not None:
|
| 30 |
+
if isinstance(conditioning, dict):
|
| 31 |
+
ctmp = conditioning[list(conditioning.keys())[0]]
|
| 32 |
+
while isinstance(ctmp, list): ctmp = ctmp[0]
|
| 33 |
+
cbs = ctmp.shape[0]
|
| 34 |
+
if cbs != batch_size:
|
| 35 |
+
print(f"Warning: Got {cbs} conditionings but batch-size is {batch_size}")
|
| 36 |
+
|
| 37 |
+
elif isinstance(conditioning, list):
|
| 38 |
+
for ctmp in conditioning:
|
| 39 |
+
if ctmp.shape[0] != batch_size:
|
| 40 |
+
print(f"Warning: Got {cbs} conditionings but batch-size is {batch_size}")
|
| 41 |
+
else:
|
| 42 |
+
if conditioning.shape[0] != batch_size:
|
| 43 |
+
print(f"Warning: Got {conditioning.shape[0]} conditionings but batch-size is {batch_size}")
|
| 44 |
+
C, H, W = shape
|
| 45 |
+
size = (batch_size, C, H, W)
|
| 46 |
+
device = self.model.betas.device
|
| 47 |
+
if x_T is None:
|
| 48 |
+
img = torch.randn(size, device=device)
|
| 49 |
+
else:
|
| 50 |
+
img = x_T
|
| 51 |
+
ns = uni_pc.uni_pc.NoiseScheduleVP('discrete', alphas_cumprod=self.alphas_cumprod)
|
| 52 |
+
model_type = "v" if self.model.parameterization == "v" else "noise"
|
| 53 |
+
model_fn = CustomUniPC_model_wrapper(lambda x, t, c: self.model.apply_model(x, t, c), ns, model_type=model_type, guidance_scale=unconditional_guidance_scale, dt_data=self.main_class)
|
| 54 |
+
self.main_class.step = 0
|
| 55 |
+
def before_sample(x, t, cond, uncond):
|
| 56 |
+
self.main_class.step += 1
|
| 57 |
+
return self.before_sample(x, t, cond, uncond)
|
| 58 |
+
uni_pc_inst = uni_pc.uni_pc.UniPC(model_fn, ns, predict_x0=True, thresholding=False, variant=shared.opts.uni_pc_variant, condition=conditioning, unconditional_condition=unconditional_conditioning, before_sample=before_sample, after_sample=self.after_sample, after_update=self.after_update)
|
| 59 |
+
x = uni_pc_inst.sample(img, steps=S, skip_type=shared.opts.uni_pc_skip_type, method="multistep", order=shared.opts.uni_pc_order, lower_order_final=shared.opts.uni_pc_lower_order_final)
|
| 60 |
+
return x.to(device), None
|
| 61 |
+
|
| 62 |
+
def CustomUniPC_model_wrapper(model, noise_schedule, model_type="noise", model_kwargs={}, guidance_scale=1.0, dt_data=None):
|
| 63 |
+
def expand_dims(v, dims):
|
| 64 |
+
return v[(...,) + (None,)*(dims - 1)]
|
| 65 |
+
def get_model_input_time(t_continuous):
|
| 66 |
+
return (t_continuous - 1. / noise_schedule.total_N) * 1000.
|
| 67 |
+
def noise_pred_fn(x, t_continuous, cond=None):
|
| 68 |
+
if t_continuous.reshape((-1,)).shape[0] == 1:
|
| 69 |
+
t_continuous = t_continuous.expand((x.shape[0]))
|
| 70 |
+
t_input = get_model_input_time(t_continuous)
|
| 71 |
+
if cond is None:
|
| 72 |
+
output = model(x, t_input, None, **model_kwargs)
|
| 73 |
+
else:
|
| 74 |
+
output = model(x, t_input, cond, **model_kwargs)
|
| 75 |
+
if model_type == "noise":
|
| 76 |
+
return output
|
| 77 |
+
elif model_type == "v":
|
| 78 |
+
alpha_t, sigma_t = noise_schedule.marginal_alpha(t_continuous), noise_schedule.marginal_std(t_continuous)
|
| 79 |
+
dims = x.dim()
|
| 80 |
+
return expand_dims(alpha_t, dims) * output + expand_dims(sigma_t, dims) * x
|
| 81 |
+
def model_fn(x, t_continuous, condition, unconditional_condition):
|
| 82 |
+
if t_continuous.reshape((-1,)).shape[0] == 1:
|
| 83 |
+
t_continuous = t_continuous.expand((x.shape[0]))
|
| 84 |
+
if guidance_scale == 1. or unconditional_condition is None:
|
| 85 |
+
return noise_pred_fn(x, t_continuous, cond=condition)
|
| 86 |
+
else:
|
| 87 |
+
x_in = torch.cat([x] * 2)
|
| 88 |
+
t_in = torch.cat([t_continuous] * 2)
|
| 89 |
+
if isinstance(condition, dict):
|
| 90 |
+
assert isinstance(unconditional_condition, dict)
|
| 91 |
+
c_in = dict()
|
| 92 |
+
for k in condition:
|
| 93 |
+
if isinstance(condition[k], list):
|
| 94 |
+
c_in[k] = [torch.cat([
|
| 95 |
+
unconditional_condition[k][i],
|
| 96 |
+
condition[k][i]]) for i in range(len(condition[k]))]
|
| 97 |
+
else:
|
| 98 |
+
c_in[k] = torch.cat([
|
| 99 |
+
unconditional_condition[k],
|
| 100 |
+
condition[k]])
|
| 101 |
+
elif isinstance(condition, list):
|
| 102 |
+
c_in = list()
|
| 103 |
+
assert isinstance(unconditional_condition, list)
|
| 104 |
+
for i in range(len(condition)):
|
| 105 |
+
c_in.append(torch.cat([unconditional_condition[i], condition[i]]))
|
| 106 |
+
else:
|
| 107 |
+
c_in = torch.cat([unconditional_condition, condition])
|
| 108 |
+
noise_uncond, noise = noise_pred_fn(x_in, t_in, cond=c_in).chunk(2)
|
| 109 |
+
#return noise_uncond + guidance_scale * (noise - noise_uncond)
|
| 110 |
+
return dt_data.dynthresh(noise, noise_uncond, guidance_scale, None)
|
| 111 |
+
return model_fn
|
extensions/1-sd-dynamic-thresholding/github/cat_demo_1.jpg
ADDED
|
extensions/1-sd-dynamic-thresholding/github/comfy_node.png
ADDED
|
extensions/1-sd-dynamic-thresholding/github/grid_preview.png
ADDED
|
extensions/1-sd-dynamic-thresholding/github/ui.png
ADDED
|
extensions/1-sd-dynamic-thresholding/javascript/active.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let dynthres_update_enabled = function() {
|
| 2 |
+
return Array.from(arguments);
|
| 3 |
+
};
|
| 4 |
+
|
| 5 |
+
(function(){
|
| 6 |
+
let accordions = {};
|
| 7 |
+
let enabled = {};
|
| 8 |
+
onUiUpdate(() => {
|
| 9 |
+
let accordion_id_prefix = "#dynthres_";
|
| 10 |
+
let extension_checkbox_class = ".dynthres-enabled";
|
| 11 |
+
|
| 12 |
+
dynthres_update_enabled = function() {
|
| 13 |
+
let res = Array.from(arguments);
|
| 14 |
+
let tabname = res[1] ? "img2img" : "txt2img";
|
| 15 |
+
|
| 16 |
+
let checkbox = accordions[tabname]?.querySelector(extension_checkbox_class + ' input');
|
| 17 |
+
checkbox?.dispatchEvent(new Event('change'));
|
| 18 |
+
|
| 19 |
+
return res;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
function attachEnabledButtonListener(checkbox, accordion) {
|
| 23 |
+
let span = accordion.querySelector('.label-wrap span');
|
| 24 |
+
let badge = document.createElement('input');
|
| 25 |
+
badge.type = "checkbox";
|
| 26 |
+
badge.checked = checkbox.checked;
|
| 27 |
+
badge.addEventListener('click', (e) => {
|
| 28 |
+
checkbox.checked = !checkbox.checked;
|
| 29 |
+
badge.checked = checkbox.checked;
|
| 30 |
+
checkbox.dispatchEvent(new Event('change'));
|
| 31 |
+
e.stopPropagation();
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
badge.className = checkbox.className;
|
| 35 |
+
badge.classList.add('primary');
|
| 36 |
+
span.insertBefore(badge, span.firstChild);
|
| 37 |
+
let space = document.createElement('span');
|
| 38 |
+
space.innerHTML = " ";
|
| 39 |
+
span.insertBefore(space, badge.nextSibling);
|
| 40 |
+
|
| 41 |
+
checkbox.addEventListener('change', () => {
|
| 42 |
+
let badge = accordion.querySelector('.label-wrap span input');
|
| 43 |
+
badge.checked = checkbox.checked;
|
| 44 |
+
});
|
| 45 |
+
checkbox.parentNode.style.display = "none";
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if (Object.keys(accordions).length < 2) {
|
| 49 |
+
let accordion = gradioApp().querySelector(accordion_id_prefix + 'txt2img');
|
| 50 |
+
if (accordion) {
|
| 51 |
+
accordions.txt2img = accordion;
|
| 52 |
+
}
|
| 53 |
+
accordion = gradioApp().querySelector(accordion_id_prefix + 'img2img');
|
| 54 |
+
if (accordion) {
|
| 55 |
+
accordions.img2img = accordion;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (Object.keys(accordions).length > 0 && accordions.txt2img && !enabled.txt2img) {
|
| 60 |
+
enabled.txt2img = accordions.txt2img.querySelector(extension_checkbox_class + ' input');
|
| 61 |
+
attachEnabledButtonListener(enabled.txt2img, accordions.txt2img);
|
| 62 |
+
}
|
| 63 |
+
if (Object.keys(accordions).length > 0 && accordions.img2img && !enabled.img2img) {
|
| 64 |
+
enabled.img2img = accordions.img2img.querySelector(extension_checkbox_class + ' input');
|
| 65 |
+
attachEnabledButtonListener(enabled.img2img, accordions.img2img);
|
| 66 |
+
}
|
| 67 |
+
});
|
| 68 |
+
})();
|
extensions/1-sd-dynamic-thresholding/pyproject.toml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "sd-dynamic-thresholding"
|
| 3 |
+
description = "Adds nodes for Dynamic Thresholding, CFG scheduling, and related techniques"
|
| 4 |
+
version = "1.0.0"
|
| 5 |
+
license = "LICENSE"
|
| 6 |
+
|
| 7 |
+
[project.urls]
|
| 8 |
+
Repository = "https://github.com/mcmonkeyprojects/sd-dynamic-thresholding"
|
| 9 |
+
|
| 10 |
+
[tool.comfy]
|
| 11 |
+
PublisherId = "mcmonkey"
|
| 12 |
+
DisplayName = "Dynamic Thresholding"
|
| 13 |
+
Icon = ""
|
extensions/1-sd-dynamic-thresholding/scripts/__pycache__/dynamic_thresholding.cpython-310.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
extensions/1-sd-dynamic-thresholding/scripts/dynamic_thresholding.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
##################
|
| 2 |
+
# Stable Diffusion Dynamic Thresholding (CFG Scale Fix)
|
| 3 |
+
#
|
| 4 |
+
# Author: Alex 'mcmonkey' Goodwin
|
| 5 |
+
# GitHub URL: https://github.com/mcmonkeyprojects/sd-dynamic-thresholding
|
| 6 |
+
# Created: 2022/01/26
|
| 7 |
+
# Last updated: 2023/01/30
|
| 8 |
+
#
|
| 9 |
+
# For usage help, view the README.md file in the extension root, or via the GitHub page.
|
| 10 |
+
#
|
| 11 |
+
##################
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
import torch, traceback
|
| 15 |
+
import dynthres_core
|
| 16 |
+
from modules import scripts, script_callbacks, sd_samplers, sd_samplers_compvis, sd_samplers_common
|
| 17 |
+
try:
|
| 18 |
+
import dynthres_unipc
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"\n\n======\nError! UniPC sampler support failed to load! Is your WebUI up to date?\n(Error: {e})\n======")
|
| 21 |
+
try:
|
| 22 |
+
from modules.sd_samplers_kdiffusion import CFGDenoiserKDiffusion as cfgdenoisekdiff
|
| 23 |
+
IS_AUTO_16 = True
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"\n\n======\nWarning! Using legacy KDiff version! Is your WebUI up to date?\n======")
|
| 26 |
+
from modules.sd_samplers_kdiffusion import CFGDenoiser as cfgdenoisekdiff
|
| 27 |
+
IS_AUTO_16 = False
|
| 28 |
+
|
| 29 |
+
DISABLE_VISIBILITY = True
|
| 30 |
+
|
| 31 |
+
######################### Data values #########################
|
| 32 |
+
MODES_WITH_VALUE = ["Power Up", "Power Down", "Linear Repeating", "Cosine Repeating", "Sawtooth"]
|
| 33 |
+
|
| 34 |
+
######################### Script class entrypoint #########################
|
| 35 |
+
class Script(scripts.Script):
|
| 36 |
+
|
| 37 |
+
def title(self):
|
| 38 |
+
return "Dynamic Thresholding (CFG Scale Fix)"
|
| 39 |
+
|
| 40 |
+
def show(self, is_img2img):
|
| 41 |
+
return scripts.AlwaysVisible
|
| 42 |
+
|
| 43 |
+
def ui(self, is_img2img):
|
| 44 |
+
def vis_change(is_vis):
|
| 45 |
+
return {"visible": is_vis, "__type__": "update"}
|
| 46 |
+
# "Dynamic Thresholding (CFG Scale Fix)"
|
| 47 |
+
dtrue = gr.Checkbox(value=True, visible=False)
|
| 48 |
+
dfalse = gr.Checkbox(value=False, visible=False)
|
| 49 |
+
with gr.Accordion("Dynamic Thresholding (CFG Scale Fix)", open=False, elem_id="dynthres_" + ("img2img" if is_img2img else "txt2img")):
|
| 50 |
+
with gr.Row():
|
| 51 |
+
enabled = gr.Checkbox(value=False, label="Enable Dynamic Thresholding (CFG Scale Fix)", elem_classes=["dynthres-enabled"], elem_id='dynthres_enabled')
|
| 52 |
+
with gr.Group():
|
| 53 |
+
gr.HTML(value=f"View <a style=\"border-bottom: 1px #00ffff dotted;\" href=\"https://github.com/mcmonkeyprojects/sd-dynamic-thresholding/wiki/Usage-Tips\">the wiki for usage tips.</a><br><br>", elem_id='dynthres_wiki_link')
|
| 54 |
+
mimic_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='Mimic CFG Scale', value=7.0, elem_id='dynthres_mimic_scale')
|
| 55 |
+
with gr.Accordion("Advanced Options", open=False, elem_id='dynthres_advanced_opts'):
|
| 56 |
+
with gr.Row():
|
| 57 |
+
threshold_percentile = gr.Slider(minimum=90.0, value=100.0, maximum=100.0, step=0.05, label='Top percentile of latents to clamp', elem_id='dynthres_threshold_percentile')
|
| 58 |
+
interpolate_phi = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Interpolate Phi", value=1.0, elem_id='dynthres_interpolate_phi')
|
| 59 |
+
with gr.Row():
|
| 60 |
+
mimic_mode = gr.Dropdown(dynthres_core.DynThresh.Modes, value="Constant", label="Mimic Scale Scheduler", elem_id='dynthres_mimic_mode')
|
| 61 |
+
cfg_mode = gr.Dropdown(dynthres_core.DynThresh.Modes, value="Constant", label="CFG Scale Scheduler", elem_id='dynthres_cfg_mode')
|
| 62 |
+
mimic_scale_min = gr.Slider(minimum=0.0, maximum=30.0, step=0.5, visible=DISABLE_VISIBILITY, label="Minimum value of the Mimic Scale Scheduler", elem_id='dynthres_mimic_scale_min')
|
| 63 |
+
cfg_scale_min = gr.Slider(minimum=0.0, maximum=30.0, step=0.5, visible=DISABLE_VISIBILITY, label="Minimum value of the CFG Scale Scheduler", elem_id='dynthres_cfg_scale_min')
|
| 64 |
+
sched_val = gr.Slider(minimum=0.0, maximum=40.0, step=0.5, value=4.0, visible=DISABLE_VISIBILITY, label="Scheduler Value", info="Value unique to the scheduler mode - for Power Up/Down, this is the power. For Linear/Cosine Repeating, this is the number of repeats per image.", elem_id='dynthres_sched_val')
|
| 65 |
+
with gr.Row():
|
| 66 |
+
separate_feature_channels = gr.Checkbox(value=True, label="Separate Feature Channels", elem_id='dynthres_separate_feature_channels')
|
| 67 |
+
scaling_startpoint = gr.Radio(["ZERO", "MEAN"], value="MEAN", label="Scaling Startpoint")
|
| 68 |
+
variability_measure = gr.Radio(["STD", "AD"], value="AD", label="Variability Measure")
|
| 69 |
+
def should_show_scheduler_value(cfg_mode, mimic_mode):
|
| 70 |
+
sched_vis = cfg_mode in MODES_WITH_VALUE or mimic_mode in MODES_WITH_VALUE or DISABLE_VISIBILITY
|
| 71 |
+
return vis_change(sched_vis), vis_change(mimic_mode != "Constant" or DISABLE_VISIBILITY), vis_change(cfg_mode != "Constant" or DISABLE_VISIBILITY)
|
| 72 |
+
cfg_mode.change(should_show_scheduler_value, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
|
| 73 |
+
mimic_mode.change(should_show_scheduler_value, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
|
| 74 |
+
enabled.change(
|
| 75 |
+
_js="dynthres_update_enabled",
|
| 76 |
+
fn=None,
|
| 77 |
+
inputs=[enabled, dtrue if is_img2img else dfalse],
|
| 78 |
+
show_progress = False)
|
| 79 |
+
self.infotext_fields = (
|
| 80 |
+
(enabled, lambda d: gr.Checkbox.update(value="Dynamic thresholding enabled" in d)),
|
| 81 |
+
(mimic_scale, "Mimic scale"),
|
| 82 |
+
(separate_feature_channels, "Separate Feature Channels"),
|
| 83 |
+
(scaling_startpoint, lambda d: gr.Radio.update(value=d.get("Scaling Startpoint", "MEAN"))),
|
| 84 |
+
(variability_measure, lambda d: gr.Radio.update(value=d.get("Variability Measure", "AD"))),
|
| 85 |
+
(interpolate_phi, "Interpolate Phi"),
|
| 86 |
+
(threshold_percentile, "Threshold percentile"),
|
| 87 |
+
(mimic_scale_min, "Mimic scale minimum"),
|
| 88 |
+
(mimic_mode, lambda d: gr.Dropdown.update(value=d.get("Mimic mode", "Constant"))),
|
| 89 |
+
(cfg_mode, lambda d: gr.Dropdown.update(value=d.get("CFG mode", "Constant"))),
|
| 90 |
+
(cfg_scale_min, "CFG scale minimum"),
|
| 91 |
+
(sched_val, "Scheduler value"))
|
| 92 |
+
return [enabled, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi]
|
| 93 |
+
|
| 94 |
+
last_id = 0
|
| 95 |
+
|
| 96 |
+
def process_batch(self, p, enabled, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi, batch_number, prompts, seeds, subseeds):
|
| 97 |
+
enabled = getattr(p, 'dynthres_enabled', enabled)
|
| 98 |
+
if not enabled:
|
| 99 |
+
return
|
| 100 |
+
orig_sampler_name = p.sampler_name
|
| 101 |
+
orig_latent_sampler_name = getattr(p, 'latent_sampler', None)
|
| 102 |
+
if orig_sampler_name in ["DDIM", "PLMS"]:
|
| 103 |
+
raise RuntimeError(f"Cannot use sampler {orig_sampler_name} with Dynamic Thresholding")
|
| 104 |
+
if orig_latent_sampler_name in ["DDIM", "PLMS"]:
|
| 105 |
+
raise RuntimeError(f"Cannot use secondary sampler {orig_latent_sampler_name} with Dynamic Thresholding")
|
| 106 |
+
if 'UniPC' in (orig_sampler_name, orig_latent_sampler_name) and p.enable_hr:
|
| 107 |
+
raise RuntimeError(f"UniPC does not support Hires Fix. Auto WebUI silently swaps to DDIM for this, which DynThresh does not support. Please swap to a sampler capable of img2img processing for HR Fix to work.")
|
| 108 |
+
mimic_scale = getattr(p, 'dynthres_mimic_scale', mimic_scale)
|
| 109 |
+
separate_feature_channels = getattr(p, 'dynthres_separate_feature_channels', separate_feature_channels)
|
| 110 |
+
scaling_startpoint = getattr(p, 'dynthres_scaling_startpoint', scaling_startpoint)
|
| 111 |
+
variability_measure = getattr(p, 'dynthres_variability_measure', variability_measure)
|
| 112 |
+
interpolate_phi = getattr(p, 'dynthres_interpolate_phi', interpolate_phi)
|
| 113 |
+
threshold_percentile = getattr(p, 'dynthres_threshold_percentile', threshold_percentile)
|
| 114 |
+
mimic_mode = getattr(p, 'dynthres_mimic_mode', mimic_mode)
|
| 115 |
+
mimic_scale_min = getattr(p, 'dynthres_mimic_scale_min', mimic_scale_min)
|
| 116 |
+
cfg_mode = getattr(p, 'dynthres_cfg_mode', cfg_mode)
|
| 117 |
+
cfg_scale_min = getattr(p, 'dynthres_cfg_scale_min', cfg_scale_min)
|
| 118 |
+
experiment_mode = getattr(p, 'dynthres_experiment_mode', 0)
|
| 119 |
+
sched_val = getattr(p, 'dynthres_scheduler_val', sched_val)
|
| 120 |
+
p.extra_generation_params["Dynamic thresholding enabled"] = True
|
| 121 |
+
p.extra_generation_params["Mimic scale"] = mimic_scale
|
| 122 |
+
p.extra_generation_params["Separate Feature Channels"] = separate_feature_channels
|
| 123 |
+
p.extra_generation_params["Scaling Startpoint"] = scaling_startpoint
|
| 124 |
+
p.extra_generation_params["Variability Measure"] = variability_measure
|
| 125 |
+
p.extra_generation_params["Interpolate Phi"] = interpolate_phi
|
| 126 |
+
p.extra_generation_params["Threshold percentile"] = threshold_percentile
|
| 127 |
+
p.extra_generation_params["Sampler"] = orig_sampler_name
|
| 128 |
+
if mimic_mode != "Constant":
|
| 129 |
+
p.extra_generation_params["Mimic mode"] = mimic_mode
|
| 130 |
+
p.extra_generation_params["Mimic scale minimum"] = mimic_scale_min
|
| 131 |
+
if cfg_mode != "Constant":
|
| 132 |
+
p.extra_generation_params["CFG mode"] = cfg_mode
|
| 133 |
+
p.extra_generation_params["CFG scale minimum"] = cfg_scale_min
|
| 134 |
+
if cfg_mode in MODES_WITH_VALUE or mimic_mode in MODES_WITH_VALUE:
|
| 135 |
+
p.extra_generation_params["Scheduler value"] = sched_val
|
| 136 |
+
# Note: the ID number is to protect the edge case of multiple simultaneous runs with different settings
|
| 137 |
+
Script.last_id += 1
|
| 138 |
+
# Percentage to portion
|
| 139 |
+
threshold_percentile *= 0.01
|
| 140 |
+
|
| 141 |
+
def make_sampler(orig_sampler_name):
|
| 142 |
+
fixed_sampler_name = f"{orig_sampler_name}_dynthres{Script.last_id}"
|
| 143 |
+
|
| 144 |
+
# Make a placeholder sampler
|
| 145 |
+
sampler = sd_samplers.all_samplers_map[orig_sampler_name]
|
| 146 |
+
dt_data = dynthres_core.DynThresh(mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, experiment_mode, p.steps, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi)
|
| 147 |
+
if orig_sampler_name == "UniPC":
|
| 148 |
+
def unipc_constructor(model):
|
| 149 |
+
return CustomVanillaSDSampler(dynthres_unipc.CustomUniPCSampler, model, dt_data)
|
| 150 |
+
new_sampler = sd_samplers_common.SamplerData(fixed_sampler_name, unipc_constructor, sampler.aliases, sampler.options)
|
| 151 |
+
else:
|
| 152 |
+
def new_constructor(model):
|
| 153 |
+
result = sampler.constructor(model)
|
| 154 |
+
cfg = CustomCFGDenoiser(result if IS_AUTO_16 else result.model_wrap_cfg.inner_model, dt_data)
|
| 155 |
+
result.model_wrap_cfg = cfg
|
| 156 |
+
return result
|
| 157 |
+
new_sampler = sd_samplers_common.SamplerData(fixed_sampler_name, new_constructor, sampler.aliases, sampler.options)
|
| 158 |
+
return fixed_sampler_name, new_sampler
|
| 159 |
+
|
| 160 |
+
# Apply for usage
|
| 161 |
+
p.orig_sampler_name = orig_sampler_name
|
| 162 |
+
p.orig_latent_sampler_name = orig_latent_sampler_name
|
| 163 |
+
p.fixed_samplers = []
|
| 164 |
+
|
| 165 |
+
if orig_latent_sampler_name:
|
| 166 |
+
latent_sampler_name, latent_sampler = make_sampler(orig_latent_sampler_name)
|
| 167 |
+
sd_samplers.all_samplers_map[latent_sampler_name] = latent_sampler
|
| 168 |
+
p.fixed_samplers.append(latent_sampler_name)
|
| 169 |
+
p.latent_sampler = latent_sampler_name
|
| 170 |
+
|
| 171 |
+
if orig_sampler_name != orig_latent_sampler_name:
|
| 172 |
+
p.sampler_name, new_sampler = make_sampler(orig_sampler_name)
|
| 173 |
+
sd_samplers.all_samplers_map[p.sampler_name] = new_sampler
|
| 174 |
+
p.fixed_samplers.append(p.sampler_name)
|
| 175 |
+
else:
|
| 176 |
+
p.sampler_name = p.latent_sampler
|
| 177 |
+
|
| 178 |
+
if p.sampler is not None:
|
| 179 |
+
p.sampler = sd_samplers.create_sampler(p.sampler_name, p.sd_model)
|
| 180 |
+
|
| 181 |
+
def postprocess_batch(self, p, enabled, mimic_scale, threshold_percentile, mimic_mode, mimic_scale_min, cfg_mode, cfg_scale_min, sched_val, separate_feature_channels, scaling_startpoint, variability_measure, interpolate_phi, batch_number, images):
|
| 182 |
+
if not enabled or not hasattr(p, 'orig_sampler_name'):
|
| 183 |
+
return
|
| 184 |
+
p.sampler_name = p.orig_sampler_name
|
| 185 |
+
if p.orig_latent_sampler_name:
|
| 186 |
+
p.latent_sampler = p.orig_latent_sampler_name
|
| 187 |
+
for added_sampler in p.fixed_samplers:
|
| 188 |
+
del sd_samplers.all_samplers_map[added_sampler]
|
| 189 |
+
del p.fixed_samplers
|
| 190 |
+
del p.orig_sampler_name
|
| 191 |
+
del p.orig_latent_sampler_name
|
| 192 |
+
|
| 193 |
+
######################### CompVis Implementation logic #########################
|
| 194 |
+
|
| 195 |
+
class CustomVanillaSDSampler(sd_samplers_compvis.VanillaStableDiffusionSampler):
|
| 196 |
+
def __init__(self, constructor, sd_model, dt_data):
|
| 197 |
+
super().__init__(constructor, sd_model)
|
| 198 |
+
self.sampler.main_class = dt_data
|
| 199 |
+
|
| 200 |
+
######################### K-Diffusion Implementation logic #########################
|
| 201 |
+
|
| 202 |
+
class CustomCFGDenoiser(cfgdenoisekdiff):
|
| 203 |
+
def __init__(self, model, dt_data):
|
| 204 |
+
super().__init__(model)
|
| 205 |
+
self.main_class = dt_data
|
| 206 |
+
|
| 207 |
+
def combine_denoised(self, x_out, conds_list, uncond, cond_scale):
|
| 208 |
+
if isinstance(uncond, dict) and 'crossattn' in uncond:
|
| 209 |
+
uncond = uncond['crossattn']
|
| 210 |
+
denoised_uncond = x_out[-uncond.shape[0]:]
|
| 211 |
+
# conds_list shape is (batch, cond, 2)
|
| 212 |
+
weights = torch.tensor(conds_list, device=uncond.device).select(2, 1)
|
| 213 |
+
weights = weights.reshape(*weights.shape, 1, 1, 1)
|
| 214 |
+
self.main_class.step = self.step
|
| 215 |
+
if hasattr(self, 'total_steps'):
|
| 216 |
+
self.main_class.max_steps = self.total_steps
|
| 217 |
+
|
| 218 |
+
if self.main_class.experiment_mode >= 4 and self.main_class.experiment_mode <= 5:
|
| 219 |
+
# https://arxiv.org/pdf/2305.08891.pdf "Rescale CFG". It's not good, but if you want to test it, just set experiment_mode = 4 + phi.
|
| 220 |
+
denoised = torch.clone(denoised_uncond)
|
| 221 |
+
fi = self.main_class.experiment_mode - 4.0
|
| 222 |
+
for i, conds in enumerate(conds_list):
|
| 223 |
+
for cond_index, weight in conds:
|
| 224 |
+
xcfg = (denoised_uncond[i] + (x_out[cond_index] - denoised_uncond[i]) * (cond_scale * weight))
|
| 225 |
+
xrescaled = xcfg * (torch.std(x_out[cond_index]) / torch.std(xcfg))
|
| 226 |
+
xfinal = fi * xrescaled + (1.0 - fi) * xcfg
|
| 227 |
+
denoised[i] = xfinal
|
| 228 |
+
return denoised
|
| 229 |
+
|
| 230 |
+
return self.main_class.dynthresh(x_out[:-uncond.shape[0]], denoised_uncond, cond_scale, weights)
|
| 231 |
+
|
| 232 |
+
######################### XYZ Plot Script Support logic #########################
|
| 233 |
+
|
| 234 |
+
def make_axis_options():
|
| 235 |
+
xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ in ("xyz_grid.py", "scripts.xyz_grid")][0].module
|
| 236 |
+
def apply_mimic_scale(p, x, xs):
|
| 237 |
+
if x != 0:
|
| 238 |
+
setattr(p, "dynthres_enabled", True)
|
| 239 |
+
setattr(p, "dynthres_mimic_scale", x)
|
| 240 |
+
else:
|
| 241 |
+
setattr(p, "dynthres_enabled", False)
|
| 242 |
+
def confirm_scheduler(p, xs):
|
| 243 |
+
for x in xs:
|
| 244 |
+
if x not in dynthres_core.DynThresh.Modes:
|
| 245 |
+
raise RuntimeError(f"Unknown Scheduler: {x}")
|
| 246 |
+
extra_axis_options = [
|
| 247 |
+
xyz_grid.AxisOption("[DynThres] Mimic Scale", float, apply_mimic_scale),
|
| 248 |
+
xyz_grid.AxisOption("[DynThres] Separate Feature Channels", int,
|
| 249 |
+
xyz_grid.apply_field("dynthres_separate_feature_channels")),
|
| 250 |
+
xyz_grid.AxisOption("[DynThres] Scaling Startpoint", str, xyz_grid.apply_field("dynthres_scaling_startpoint"), choices=lambda:['ZERO', 'MEAN']),
|
| 251 |
+
xyz_grid.AxisOption("[DynThres] Variability Measure", str, xyz_grid.apply_field("dynthres_variability_measure"), choices=lambda:['STD', 'AD']),
|
| 252 |
+
xyz_grid.AxisOption("[DynThres] Interpolate Phi", float, xyz_grid.apply_field("dynthres_interpolate_phi")),
|
| 253 |
+
xyz_grid.AxisOption("[DynThres] Threshold Percentile", float, xyz_grid.apply_field("dynthres_threshold_percentile")),
|
| 254 |
+
xyz_grid.AxisOption("[DynThres] Mimic Scheduler", str, xyz_grid.apply_field("dynthres_mimic_mode"), confirm=confirm_scheduler, choices=lambda: dynthres_core.DynThresh.Modes),
|
| 255 |
+
xyz_grid.AxisOption("[DynThres] Mimic minimum", float, xyz_grid.apply_field("dynthres_mimic_scale_min")),
|
| 256 |
+
xyz_grid.AxisOption("[DynThres] CFG Scheduler", str, xyz_grid.apply_field("dynthres_cfg_mode"), confirm=confirm_scheduler, choices=lambda: dynthres_core.DynThresh.Modes),
|
| 257 |
+
xyz_grid.AxisOption("[DynThres] CFG minimum", float, xyz_grid.apply_field("dynthres_cfg_scale_min")),
|
| 258 |
+
xyz_grid.AxisOption("[DynThres] Scheduler value", float, xyz_grid.apply_field("dynthres_scheduler_val"))
|
| 259 |
+
]
|
| 260 |
+
if not any("[DynThres]" in x.label for x in xyz_grid.axis_options):
|
| 261 |
+
xyz_grid.axis_options.extend(extra_axis_options)
|
| 262 |
+
|
| 263 |
+
def callback_before_ui():
|
| 264 |
+
try:
|
| 265 |
+
make_axis_options()
|
| 266 |
+
except Exception as e:
|
| 267 |
+
traceback.print_exc()
|
| 268 |
+
print(f"Failed to add support for X/Y/Z Plot Script because: {e}")
|
| 269 |
+
|
| 270 |
+
script_callbacks.on_before_ui(callback_before_ui)
|
extensions/ABG_extension/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
scripts/__pycache__
|
extensions/ABG_extension/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h3 align="center">
|
| 2 |
+
<b>ABG extension</b>
|
| 3 |
+
</h3>
|
| 4 |
+
|
| 5 |
+
<p align="center">
|
| 6 |
+
<a href="https://github.com/KutsuyaYuki/ABG_extension/stargazers"><img src="https://img.shields.io/github/stars/KutsuyaYuki/ABG_extension?style=for-the-badge"></a>
|
| 7 |
+
<a href="https://github.com/KutsuyaYuki/ABG_extension/issues"><img src="https://img.shields.io/github/issues/KutsuyaYuki/ABG_extension?style=for-the-badge"></a>
|
| 8 |
+
<a href="https://github.com/KutsuyaYuki/ABG_extension/commits/main"><img src="https://img.shields.io/github/last-commit/KutsuyaYuki/ABG_extension?style=for-the-badge"></a>
|
| 9 |
+
</p>
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
1. Install extension by going to Extensions tab -> Install from URL -> Paste github URL and click Install.
|
| 14 |
+
2. After it's installed, go back to the Installed tab in Extensions and press Apply and restart UI.
|
| 15 |
+
3. Installation finished.
|
| 16 |
+
4. If the script does not show up or work, please restart the WebUI.
|
| 17 |
+
|
| 18 |
+
## Usage
|
| 19 |
+
|
| 20 |
+
### txt2img
|
| 21 |
+
|
| 22 |
+
1. In the bottom of the WebUI in Script, select **ABG Remover**.
|
| 23 |
+
2. Select the desired options: **Only save background free pictures** or **Do not auto save**.
|
| 24 |
+
3. Generate an image and you will see the result in the output area.
|
| 25 |
+
|
| 26 |
+
### img2img
|
| 27 |
+
|
| 28 |
+
1. In the bottom of the WebUI in Script, select **ABG Remover**.
|
| 29 |
+
2. Select the desired options: **Only save background free pictures** or **Do not auto save**.
|
| 30 |
+
3. **IMPORTANT**: Set **Denoising strength** to a low value, like **0.01**
|
| 31 |
+
|
| 32 |
+
Based on https://huggingface.co/spaces/skytnt/anime-remove-background
|
extensions/ABG_extension/install.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import launch
|
| 2 |
+
|
| 3 |
+
for dep in ['onnx', 'onnxruntime', 'numpy']:
|
| 4 |
+
if not launch.is_installed(dep):
|
| 5 |
+
launch.run_pip(f"install {dep}", f"{dep} for ABG_extension")
|
| 6 |
+
|
| 7 |
+
if not launch.is_installed("cv2"):
|
| 8 |
+
launch.run_pip("install opencv-python", "opencv-python")
|
| 9 |
+
|
| 10 |
+
if not launch.is_installed("PIL"):
|
| 11 |
+
launch.run_pip("install Pillow", "Pillow")
|
extensions/ABG_extension/scripts/__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (4.23 kB). View file
|
|
|
extensions/ABG_extension/scripts/app.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import modules.scripts as scripts
|
| 3 |
+
from modules import images
|
| 4 |
+
from modules.processing import process_images, Processed
|
| 5 |
+
from modules.processing import Processed
|
| 6 |
+
from modules.shared import opts, cmd_opts, state
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import huggingface_hub
|
| 10 |
+
import onnxruntime as rt
|
| 11 |
+
import copy
|
| 12 |
+
import numpy as np
|
| 13 |
+
import cv2
|
| 14 |
+
from PIL import Image as im, ImageDraw
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Declare Execution Providers
|
| 18 |
+
providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
|
| 19 |
+
|
| 20 |
+
# Download and host the model
|
| 21 |
+
model_path = huggingface_hub.hf_hub_download(
|
| 22 |
+
"skytnt/anime-seg", "isnetis.onnx")
|
| 23 |
+
rmbg_model = rt.InferenceSession(model_path, providers=providers)
|
| 24 |
+
|
| 25 |
+
# Function to get mask
|
| 26 |
+
def get_mask(img, s=1024):
|
| 27 |
+
# Resize the img to a square shape with dimension s
|
| 28 |
+
# Convert img pixel values from integers 0-255 to float 0-1
|
| 29 |
+
img = (img / 255).astype(np.float32)
|
| 30 |
+
# get the amount of dimensions of img
|
| 31 |
+
dim = img.shape[2]
|
| 32 |
+
# Convert the input image to RGB format if it has an alpha channel
|
| 33 |
+
if dim == 4:
|
| 34 |
+
img = img[..., :3]
|
| 35 |
+
dim = 3
|
| 36 |
+
# Get height and width of the image
|
| 37 |
+
h, w = h0, w0 = img.shape[:-1]
|
| 38 |
+
# IF height is greater than width, set h as s and w as s*width/height
|
| 39 |
+
# ELSE, set w as s and h as s*height/width
|
| 40 |
+
h, w = (s, int(s * w / h)) if h > w else (int(s * h / w), s)
|
| 41 |
+
# Calculate padding for height and width
|
| 42 |
+
ph, pw = s - h, s - w
|
| 43 |
+
# Create a 1024x1024x3 array of 0's
|
| 44 |
+
img_input = np.zeros([s, s, dim], dtype=np.float32)
|
| 45 |
+
# Resize the original image to (w,h) and then pad with the calculated ph,pw
|
| 46 |
+
img_input[ph // 2:ph // 2 + h, pw //
|
| 47 |
+
2:pw // 2 + w] = cv2.resize(img, (w, h))
|
| 48 |
+
# Change the axes
|
| 49 |
+
img_input = np.transpose(img_input, (2, 0, 1))
|
| 50 |
+
# Add an extra axis (1,0)
|
| 51 |
+
img_input = img_input[np.newaxis, :]
|
| 52 |
+
# Run the model to get the mask
|
| 53 |
+
mask = rmbg_model.run(None, {'img': img_input})[0][0]
|
| 54 |
+
# Transpose axis
|
| 55 |
+
mask = np.transpose(mask, (1, 2, 0))
|
| 56 |
+
# Crop it to the images original dimensions (h0,w0)
|
| 57 |
+
mask = mask[ph // 2:ph // 2 + h, pw // 2:pw // 2 + w]
|
| 58 |
+
# Resize the mask to original image size (h0,w0)
|
| 59 |
+
mask = cv2.resize(mask, (w0, h0))[:, :, np.newaxis]
|
| 60 |
+
return mask
|
| 61 |
+
|
| 62 |
+
### Function to remove background
|
| 63 |
+
def rmbg_fn(img):
|
| 64 |
+
# Call get_mask() to get the mask
|
| 65 |
+
mask = get_mask(img)
|
| 66 |
+
# Multiply the image and the mask together to get the output image
|
| 67 |
+
img = (mask * img + 255 * (1 - mask)).astype(np.uint8)
|
| 68 |
+
# Convert mask value back to int 0-255
|
| 69 |
+
mask = (mask * 255).astype(np.uint8)
|
| 70 |
+
# Concatenate the output image and mask
|
| 71 |
+
img = np.concatenate([img, mask], axis=2, dtype=np.uint8)
|
| 72 |
+
# Stacking 3 identical copies of the mask for displaying
|
| 73 |
+
mask = mask.repeat(3, axis=2)
|
| 74 |
+
return mask, img
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class Script(scripts.Script):
|
| 78 |
+
is_txt2img = False
|
| 79 |
+
|
| 80 |
+
# Function to set title
|
| 81 |
+
def title(self):
|
| 82 |
+
return "ABG Remover"
|
| 83 |
+
|
| 84 |
+
def ui(self, is_img2img):
|
| 85 |
+
|
| 86 |
+
with gr.Column():
|
| 87 |
+
only_save_background_free_pictures = gr.Checkbox(
|
| 88 |
+
label='Only save background free pictures')
|
| 89 |
+
do_not_auto_save = gr.Checkbox(label='Do not auto save')
|
| 90 |
+
with gr.Row():
|
| 91 |
+
custom_background = gr.Checkbox(label='Custom Background')
|
| 92 |
+
custom_background_color = gr.ColorPicker(
|
| 93 |
+
label='Background Color', default='#ff0000')
|
| 94 |
+
custom_background_random = gr.Checkbox(
|
| 95 |
+
label='Random Custom Background')
|
| 96 |
+
|
| 97 |
+
return [only_save_background_free_pictures, do_not_auto_save, custom_background, custom_background_color, custom_background_random]
|
| 98 |
+
|
| 99 |
+
# Function to show the script
|
| 100 |
+
def show(self, is_img2img):
|
| 101 |
+
return True
|
| 102 |
+
|
| 103 |
+
# Function to run the script
|
| 104 |
+
def run(self, p, only_save_background_free_pictures, do_not_auto_save, custom_background, custom_background_color, custom_background_random):
|
| 105 |
+
# If only_save_background_free_pictures is true, set do_not_save_samples to true
|
| 106 |
+
if only_save_background_free_pictures:
|
| 107 |
+
p.do_not_save_samples = True
|
| 108 |
+
|
| 109 |
+
# Create a process_images object
|
| 110 |
+
proc = process_images(p)
|
| 111 |
+
|
| 112 |
+
has_grid = False
|
| 113 |
+
|
| 114 |
+
unwanted_grid_because_of_img_count = len(
|
| 115 |
+
proc.images) < 2 and opts.grid_only_if_multiple
|
| 116 |
+
if (opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not unwanted_grid_because_of_img_count:
|
| 117 |
+
has_grid = True
|
| 118 |
+
|
| 119 |
+
# Loop through all the images in proc
|
| 120 |
+
for i in range(len(proc.images)):
|
| 121 |
+
# Separate the background from the foreground
|
| 122 |
+
nmask, nimg = rmbg_fn(np.array(proc.images[i]))
|
| 123 |
+
|
| 124 |
+
# Check the number of channels in the nimg array, select only the first 3 or 4 channels
|
| 125 |
+
num_channels = nimg.shape[2]
|
| 126 |
+
if num_channels > 4:
|
| 127 |
+
nimg = nimg[:, :, :4]
|
| 128 |
+
|
| 129 |
+
# Ensure the data type is uint8 and convert the image back to a format that can be saved
|
| 130 |
+
nimg = nimg.astype(np.uint8)
|
| 131 |
+
img = im.fromarray(nimg)
|
| 132 |
+
|
| 133 |
+
# If only_save_background_free_pictures is true, check if the image has a background
|
| 134 |
+
if custom_background or custom_background_random:
|
| 135 |
+
# If custom_background_random is true, set the background color to a random color
|
| 136 |
+
if custom_background_random:
|
| 137 |
+
custom_background_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
| 138 |
+
|
| 139 |
+
# Create a new image with the same size as the original image
|
| 140 |
+
background = im.new('RGBA', img.size, custom_background_color)
|
| 141 |
+
|
| 142 |
+
# Draw a colored rectangle onto the new image
|
| 143 |
+
draw = ImageDraw.Draw(background)
|
| 144 |
+
draw.rectangle([(0, 0), img.size],
|
| 145 |
+
fill=custom_background_color)
|
| 146 |
+
|
| 147 |
+
# Merge the two images
|
| 148 |
+
img = im.alpha_composite(background, img)
|
| 149 |
+
|
| 150 |
+
# determine output path
|
| 151 |
+
outpath = p.outpath_grids if has_grid and i == 0 else p.outpath_samples
|
| 152 |
+
|
| 153 |
+
# If we are saving all images, save the mask and the image
|
| 154 |
+
if not only_save_background_free_pictures:
|
| 155 |
+
mask = im.fromarray(nmask)
|
| 156 |
+
# Dot not save the new images if checkbox is checked
|
| 157 |
+
if not do_not_auto_save:
|
| 158 |
+
# Save the new images
|
| 159 |
+
images.save_image(
|
| 160 |
+
mask, outpath, "mask_", proc.seed + i, proc.prompt, "png", info=proc.info, p=p)
|
| 161 |
+
images.save_image(
|
| 162 |
+
img, outpath, "img_", proc.seed + i, proc.prompt, "png", info=proc.info, p=p)
|
| 163 |
+
# Add the images to the proc object
|
| 164 |
+
proc.images.append(mask)
|
| 165 |
+
proc.images.append(img)
|
| 166 |
+
# If we are only saving background-free images, save the image and replace it in the proc object
|
| 167 |
+
else:
|
| 168 |
+
proc.images[i] = img
|
| 169 |
+
|
| 170 |
+
# Check if automatic saving is enabled
|
| 171 |
+
if not do_not_auto_save:
|
| 172 |
+
# Check if the image is the first one and has a grid
|
| 173 |
+
if has_grid and i == 0:
|
| 174 |
+
# Save the image
|
| 175 |
+
images.save_image(img, p.outpath_grids, "grid", p.all_seeds[0], p.all_prompts[0],
|
| 176 |
+
opts.grid_format, info=proc.info, short_filename=not opts.grid_extended_filename, p=p)
|
| 177 |
+
else:
|
| 178 |
+
# Save the image
|
| 179 |
+
images.save_image(img, outpath, "", proc.seed,
|
| 180 |
+
proc.prompt, "png", info=proc.info, p=p)
|
| 181 |
+
|
| 182 |
+
# Return the proc object
|
| 183 |
+
return proc
|
extensions/AdverseCleanerExtension/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**scripts/__pycache__/
|
| 2 |
+
**dist
|
extensions/AdverseCleanerExtension/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
extensions/AdverseCleanerExtension/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AdverseCleaner Extension for AUTOMATIC1111/stable-diffusion-webui
|
| 2 |
+
This extension provides a simple and easy-to-use way to denoise images using the cv2 bilateral filter and guided filter.
|
| 3 |
+
Original script by: https://github.com/lllyasviel/AdverseCleaner
|
| 4 |
+
## Usage
|
| 5 |
+
Select AdverseCleaner as your active script
|
| 6 |
+

|
| 7 |
+
You will then have access to all the parameters for both filter steps
|
| 8 |
+

|
extensions/AdverseCleanerExtension/install.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import launch
|
| 2 |
+
|
| 3 |
+
if not launch.is_installed("opencv-contrib-python"):
|
| 4 |
+
if launch.is_installed("opencv-python"):
|
| 5 |
+
launch.run_pip("uninstall opencv-python")
|
| 6 |
+
print("Uninstalling opencv-python...")
|
| 7 |
+
launch.run_pip("install opencv-contrib-python")
|
| 8 |
+
print("Installing opencv-contrib-python...")
|
| 9 |
+
|
| 10 |
+
if not launch.is_installed("numpy"):
|
| 11 |
+
launch.run_pip("install numpy")
|
| 12 |
+
print("Installing numpy...")
|
extensions/AdverseCleanerExtension/scripts/__pycache__/denoise.cpython-310.pyc
ADDED
|
Binary file (2.71 kB). View file
|
|
|
extensions/AdverseCleanerExtension/scripts/denoise.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2
|
| 5 |
+
import modules.scripts as scripts
|
| 6 |
+
|
| 7 |
+
from modules import images
|
| 8 |
+
from modules.shared import opts
|
| 9 |
+
|
| 10 |
+
from cv2.ximgproc import guidedFilter
|
| 11 |
+
from modules.processing import process_images
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Script(scripts.Script):
|
| 15 |
+
def title(self):
|
| 16 |
+
return "AdverseCleaner"
|
| 17 |
+
|
| 18 |
+
def show(self, is_img2img):
|
| 19 |
+
return True
|
| 20 |
+
|
| 21 |
+
def ui(self, is_img2img):
|
| 22 |
+
info = gr.Markdown('''
|
| 23 |
+
### Bilateral Filter
|
| 24 |
+
''')
|
| 25 |
+
bilateral_steps = gr.Slider(minimum=1, maximum=128, step=1,
|
| 26 |
+
value=64, label="Bilateral Steps")
|
| 27 |
+
diameter = gr.Slider(minimum=1, maximum=30, step=1,
|
| 28 |
+
value=5, label="Diameter")
|
| 29 |
+
sigma_color = gr.Slider(minimum=1, maximum=30,
|
| 30 |
+
step=1, value=8, label="SigmaColor")
|
| 31 |
+
sigma_space = gr.Slider(minimum=1, maximum=30,
|
| 32 |
+
step=1, value=8, label="SigmaSpace")
|
| 33 |
+
info2 = gr.Markdown('''
|
| 34 |
+
### Guided Filter
|
| 35 |
+
''')
|
| 36 |
+
guided_steps = gr.Slider(minimum=1, maximum=64, step=1,
|
| 37 |
+
value=4, label="Guided Steps")
|
| 38 |
+
radius = gr.Slider(minimum=1, maximum=30, step=1,
|
| 39 |
+
value=4, label="Radius")
|
| 40 |
+
eps = gr.Slider(minimum=1, maximum=30, step=1,
|
| 41 |
+
value=16, label="Accuracy")
|
| 42 |
+
return [info, bilateral_steps, diameter, sigma_color, sigma_space, info2, guided_steps, radius, eps]
|
| 43 |
+
|
| 44 |
+
def run(self, p, _, bilateral_steps, diameter, sigma_color, sigma_space, __, guided_steps, radius, eps):
|
| 45 |
+
from PIL import Image
|
| 46 |
+
has_grid = False
|
| 47 |
+
|
| 48 |
+
proc = process_images(p)
|
| 49 |
+
unwanted_grid_because_of_img_count = len(
|
| 50 |
+
proc.images) < 2 and opts.grid_only_if_multiple
|
| 51 |
+
if (opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not unwanted_grid_because_of_img_count:
|
| 52 |
+
has_grid = True
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def process(im,i):
|
| 56 |
+
outpath = p.outpath_grids if has_grid and i == 0 else p.outpath_samples
|
| 57 |
+
img = cv2.cvtColor(
|
| 58 |
+
np.array(im), cv2.COLOR_RGB2BGR).astype(np.float32)
|
| 59 |
+
y = img.copy()
|
| 60 |
+
for _ in range(bilateral_steps):
|
| 61 |
+
y = cv2.bilateralFilter(y, diameter, sigma_color, sigma_space)
|
| 62 |
+
|
| 63 |
+
for _ in range(guided_steps):
|
| 64 |
+
y = guidedFilter(img, y, radius, eps)
|
| 65 |
+
|
| 66 |
+
out_image = Image.fromarray(cv2.cvtColor(
|
| 67 |
+
y.clip(0, 255).astype(np.uint8), cv2.COLOR_BGR2RGB))
|
| 68 |
+
images.save_image(out_image, outpath, "img_", proc.seed +
|
| 69 |
+
i, proc.prompt, "png", info=proc.info, p=p)
|
| 70 |
+
return out_image
|
| 71 |
+
|
| 72 |
+
for i in range(len(proc.images)):
|
| 73 |
+
proc.images.append(process(proc.images[i], i))
|
| 74 |
+
return proc
|
extensions/CFG-Schedule-for-Automatic1111-SD/Examples
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copy paste following to use their effect. CFG slider will still work
|
| 2 |
+
|
| 3 |
+
CFG is how much to stick to the prompt
|
| 4 |
+
ETA is how much of shift to cause ... maybe
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Example 1
|
| 9 |
+
About: Gradually reduce CFG
|
| 10 |
+
CFG
|
| 11 |
+
0: cfg * e
|
| 12 |
+
ETA
|
| 13 |
+
0: e
|
| 14 |
+
|
| 15 |
+
Example 3
|
| 16 |
+
About: Half the way, use CFG while reducing its strong effect
|
| 17 |
+
0: cfg * (0.5+ (t<T/2) *0.5)
|
| 18 |
+
0: 1.2-e
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Example 3
|
| 23 |
+
About: The higher the CFG, the more frequent details added from prompt
|
| 24 |
+
CFG:
|
| 25 |
+
0: 5-( cfg/30*5 ) + ( (t% math.floor((35-cfg)/2))==0)*(cfg*e*0.5+30)
|
| 26 |
+
ETA:
|
| 27 |
+
0: pow(e,1/(1/pow(2, (cfg-15)/30*3 ) ))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Example 4
|
| 31 |
+
About: Focus on adding details midway
|
| 32 |
+
CFG:
|
| 33 |
+
0:( 1-pow(2*e-1 ,2))*cfg*0.75 * (t%4<1 and t<T-4)+(31-cfg)*0.25
|
| 34 |
+
ETA:
|
| 35 |
+
0: pow(2*e-1 ,2)*cfg
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Example 5
|
| 41 |
+
About: Pay more attention to details at beginning, then relax
|
| 42 |
+
CFG:
|
| 43 |
+
0:pow(e,0.1)*cfg*( t%4<1)+5*(1-e)
|
| 44 |
+
ETA:
|
| 45 |
+
0:pow(e,0.3)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Example 6
|
| 49 |
+
About: This can help you compare results of this script with results without it.
|
| 50 |
+
It will try to create the same image as without it, but enhance it.
|
| 51 |
+
CFG:
|
| 52 |
+
0: cfg*(e>0.7 or e<0.1)+ (15-cfg*0.2)*(e<0.4 and (t%3<1))
|
| 53 |
+
ETA:
|
| 54 |
+
0:e+(e<0.4)*(e*3)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Example 7
|
| 58 |
+
About: Conditional. Does some clean up at the end.
|
| 59 |
+
CFG:
|
| 60 |
+
0:abs(0.3-e)*(3.5+cfg*2)
|
| 61 |
+
ETA:
|
| 62 |
+
0:abs( (1.5-2*e)*3)*(pow(1-e,2) if e>.2 or cfg>20 else e)
|
extensions/CFG-Schedule-for-Automatic1111-SD/Experiments
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Other experimental ideas I was trying. CFG value might be useless in some:
|
| 2 |
+
|
| 3 |
+
0: cfg*(e>0.5)+cfg* (3*(e%2<=0.5 and t%5<1) - 1*(t%5==2)) * (t<T-3)
|
| 4 |
+
0:e+e*(e<0.5)+(e%2<=0.5 and t%5<2 and t<T-3)*0.5
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
0: 5+ ( (t% math.floor((30+cfg)/2))==0)*10
|
| 9 |
+
0: 1/(1+cfg*e*e)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
0: 40*( ((t)%math.floor(5+cfg/8) )==0) *2*e*(t<T-5)+ (31-cfg)*0.1
|
| 14 |
+
0: ( ((t)%math.floor(5+cfg/8) )>x(e*2,0,1) )*e*2+e*0.1
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
0: 40*( ((t)%math.floor(5+cfg/8) )==0) *2*e*(t<T-5)+ (31-cfg)*0.1
|
| 19 |
+
0: ( ((t)%math.floor(5+cfg/8) )>0)*e*2+e*0.1
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
0:pow(cfg,0.5)+ 5*(cfg/30)* (1-((t*0.2)%1))*(t%6<2)*( (t%6==1)*3) + (31-cfg)*.05
|
| 24 |
+
0:5*((t%6)>0)*pow(e,2)+((t%6)<20)*2
|
| 25 |
+
|
| 26 |
+
0:2;3:1;5:=10-(t/T)*10; 25:=10+20*e
|
| 27 |
+
0:=60*d;3:0.5; 10:1;23:=2.4-(t/T)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
0:1+(t%5 ==0 )*(15-d*5) ;13:10 ;20:5+e*5-d*2
|
| 32 |
+
0:20-min(0,t*3);13:0.5*e ;20:1+e; 30:e*2
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
0:1+(t%4<1 )*95*e*e ;50:5+(t%4<1 )*5*e
|
| 37 |
+
0:(15-(t%4<1 )*14)*(1+e)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
0:1+((t%4<1)*20+(t%5<1)*190)*e*e ;50:5+(t%5<1 )*4*e
|
| 42 |
+
0:(15-(t%5<1 )*14)*(1+e)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
=2+50*(t%4<1)*e
|
| 47 |
+
=1/(1+t/T)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
0:15; 2:(5*e+30*(t%3<1 and t<25)*e*e) /(1+d)
|
| 51 |
+
0:5*e; 10:5*e*e
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# changes show on all denoising strength
|
| 55 |
+
0: 6-( cfg/30*5 ) + ( (t% math.floor((32-cfg+d*4)/2))==0)*( pow(200,1-d/2)*e*e)
|
| 56 |
+
0: e*0.2 if (t% math.floor((36-cfg)/2))==0 else pow(e,1/(1/pow(2, (cfg-15)/30*3 ) ))
|
| 57 |
+
|
| 58 |
+
# Trying to force modification
|
| 59 |
+
0:( 1-pow(2*e-1 ,2))*cfg*(0.75+(t<T/5)) * (t%4<(1+(t<T/5)) and t<T-4)+(31-cfg)*0.25
|
| 60 |
+
0:pow(e,0.3)*(1+e*6*(t%8>3 and t%8<5 and t>T*.6 and t<T*.6+6) )
|
| 61 |
+
|
| 62 |
+
#or
|
| 63 |
+
0:( 1-pow(2*e-1 ,2))*(cfg +pow((1-d)*6,2) )*(0.75+(t<T/5)) * (t%4<(1+(t<T/5)) and t<T-4)+(31-cfg)*0.25
|
| 64 |
+
0:pow(e,0.3)*(1+e*6*(t%8>3 and t%8<5+0*pow( (1-d)*10,2) and t>T*.6 and t<T*.6+6) )
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
#The more CFG value, the stronger it drops.
|
| 68 |
+
0:(cfg+1)*(pow(cfg+1,e-1)-1/(cfg+1))/(cfg)*cfg+3
|
| 69 |
+
0:e
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
#Test for better img2img consistancy. Keep denoising at low level and try different CFG values
|
| 75 |
+
0:(1-e*.9)*cfg + ( ((t%(2+(e>0.7)) <1)*1.1*cfg*(e+(e>0.3 and e<0.6)*0.2)) )* ( 2*( 1+pow(d,pow(2,1/(1+d))))-1 )
|
| 76 |
+
0:e+ (e>0.7 and t%2==0)*3 + (e<0.3 and t%2==1 and t<T-3)*1
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
#random idea
|
| 80 |
+
0:cfg if (t%2==0) else cfg*pow(e,pow(1-e,2))
|
| 81 |
+
0:(1-pow(e,pow(1-e,2)))*2
|
| 82 |
+
--
|
| 83 |
+
0:cfg/(8**(2*(1-e))) if t%2==0 else 0
|
| 84 |
+
--
|
| 85 |
+
|
| 86 |
+
Update DEC 2022
|
| 87 |
+
#Very foreceful. Needs low deniosing
|
| 88 |
+
0:200/(t*0.4+1); 25:0.07; 37:cfg
|
| 89 |
+
0:0.3; 25:3; 37:max((3-(t-37)/10 ),e)
|
| 90 |
+
|
| 91 |
+
#Super forceful
|
| 92 |
+
0:(1100-d*1050)/(t*0.4+1); 25:0.07; 37:cfg+cfg*d*3
|
| 93 |
+
0:0.8-d*0.5; 25:30-d*29; 37:max((3-(t-37)/(10-10*d) ),e)
|
| 94 |
+
|
| 95 |
+
#Forceful using CFG and Denoising as parameters
|
| 96 |
+
0:(200-d*150)/(t*(30-cfg)/30+1); 25:0.07; 37:5
|
| 97 |
+
0:0.8-d*0.5; 25:30 if (t<37-d*11) else 0.2; 37:1+e
|
| 98 |
+
|
| 99 |
+
#idea 2
|
| 100 |
+
0:( 50* (4-d*3.75))/(t*(30-cfg)/30+1); 25:0.07; 37:5
|
| 101 |
+
0:0.8-d*0.5; 25:30 if (t<37-d*11) else 0.2; 37:1+e
|
| 102 |
+
|
| 103 |
+
#idea 3
|
| 104 |
+
0:(100*(1-d)+d*50 )/(t*(30-cfg)/30+1); 25:1; 37:5
|
| 105 |
+
0:0.5-min(t*0.1,0.49); 25:2 if (t<29) else 0.2; 37:1+e
|
| 106 |
+
|
| 107 |
+
0:(120*(1-d)+d*50 )/(t*(30-cfg)/30+1); 25:1; 37:5
|
| 108 |
+
0:0.8+1.5-min(t*0.1, 0.8+1.5 -0.01); 25:2 if (t<29) else 0.2; 37:1+e
|
extensions/CFG-Schedule-for-Automatic1111-SD/LICENSE
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works.
|
| 12 |
+
|
| 13 |
+
The licenses for most software and other practical works are designed
|
| 14 |
+
to take away your freedom to share and change the works. By contrast,
|
| 15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 16 |
+
share and change all versions of a program--to make sure it remains free
|
| 17 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 18 |
+
GNU General Public License for most of our software; it applies also to
|
| 19 |
+
any other work released this way by its authors. You can apply it to
|
| 20 |
+
your programs, too.
|
| 21 |
+
|
| 22 |
+
When we speak of free software, we are referring to freedom, not
|
| 23 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 24 |
+
have the freedom to distribute copies of free software (and charge for
|
| 25 |
+
them if you wish), that you receive source code or can get it if you
|
| 26 |
+
want it, that you can change the software or use pieces of it in new
|
| 27 |
+
free programs, and that you know you can do these things.
|
| 28 |
+
|
| 29 |
+
To protect your rights, we need to prevent others from denying you
|
| 30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 31 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 32 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 33 |
+
|
| 34 |
+
For example, if you distribute copies of such a program, whether
|
| 35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 36 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 37 |
+
or can get the source code. And you must show them these terms so they
|
| 38 |
+
know their rights.
|
| 39 |
+
|
| 40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 43 |
+
|
| 44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 45 |
+
that there is no warranty for this free software. For both users' and
|
| 46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 47 |
+
changed, so that their problems will not be attributed erroneously to
|
| 48 |
+
authors of previous versions.
|
| 49 |
+
|
| 50 |
+
Some devices are designed to deny users access to install or run
|
| 51 |
+
modified versions of the software inside them, although the manufacturer
|
| 52 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 53 |
+
protecting users' freedom to change the software. The systematic
|
| 54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 56 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 57 |
+
products. If such problems arise substantially in other domains, we
|
| 58 |
+
stand ready to extend this provision to those domains in future versions
|
| 59 |
+
of the GPL, as needed to protect the freedom of users.
|
| 60 |
+
|
| 61 |
+
Finally, every program is threatened constantly by software patents.
|
| 62 |
+
States should not allow patents to restrict development and use of
|
| 63 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 64 |
+
avoid the special danger that patents applied to a free program could
|
| 65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 66 |
+
patents cannot be used to render the program non-free.
|
| 67 |
+
|
| 68 |
+
The precise terms and conditions for copying, distribution and
|
| 69 |
+
modification follow.
|
| 70 |
+
|
| 71 |
+
TERMS AND CONDITIONS
|
| 72 |
+
|
| 73 |
+
0. Definitions.
|
| 74 |
+
|
| 75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 76 |
+
|
| 77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 78 |
+
works, such as semiconductor masks.
|
| 79 |
+
|
| 80 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 82 |
+
"recipients" may be individuals or organizations.
|
| 83 |
+
|
| 84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 85 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 86 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 87 |
+
earlier work or a work "based on" the earlier work.
|
| 88 |
+
|
| 89 |
+
A "covered work" means either the unmodified Program or a work based
|
| 90 |
+
on the Program.
|
| 91 |
+
|
| 92 |
+
To "propagate" a work means to do anything with it that, without
|
| 93 |
+
permission, would make you directly or secondarily liable for
|
| 94 |
+
infringement under applicable copyright law, except executing it on a
|
| 95 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 96 |
+
distribution (with or without modification), making available to the
|
| 97 |
+
public, and in some countries other activities as well.
|
| 98 |
+
|
| 99 |
+
To "convey" a work means any kind of propagation that enables other
|
| 100 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 102 |
+
|
| 103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 104 |
+
to the extent that it includes a convenient and prominently visible
|
| 105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 106 |
+
tells the user that there is no warranty for the work (except to the
|
| 107 |
+
extent that warranties are provided), that licensees may convey the
|
| 108 |
+
work under this License, and how to view a copy of this License. If
|
| 109 |
+
the interface presents a list of user commands or options, such as a
|
| 110 |
+
menu, a prominent item in the list meets this criterion.
|
| 111 |
+
|
| 112 |
+
1. Source Code.
|
| 113 |
+
|
| 114 |
+
The "source code" for a work means the preferred form of the work
|
| 115 |
+
for making modifications to it. "Object code" means any non-source
|
| 116 |
+
form of a work.
|
| 117 |
+
|
| 118 |
+
A "Standard Interface" means an interface that either is an official
|
| 119 |
+
standard defined by a recognized standards body, or, in the case of
|
| 120 |
+
interfaces specified for a particular programming language, one that
|
| 121 |
+
is widely used among developers working in that language.
|
| 122 |
+
|
| 123 |
+
The "System Libraries" of an executable work include anything, other
|
| 124 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 125 |
+
packaging a Major Component, but which is not part of that Major
|
| 126 |
+
Component, and (b) serves only to enable use of the work with that
|
| 127 |
+
Major Component, or to implement a Standard Interface for which an
|
| 128 |
+
implementation is available to the public in source code form. A
|
| 129 |
+
"Major Component", in this context, means a major essential component
|
| 130 |
+
(kernel, window system, and so on) of the specific operating system
|
| 131 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 132 |
+
produce the work, or an object code interpreter used to run it.
|
| 133 |
+
|
| 134 |
+
The "Corresponding Source" for a work in object code form means all
|
| 135 |
+
the source code needed to generate, install, and (for an executable
|
| 136 |
+
work) run the object code and to modify the work, including scripts to
|
| 137 |
+
control those activities. However, it does not include the work's
|
| 138 |
+
System Libraries, or general-purpose tools or generally available free
|
| 139 |
+
programs which are used unmodified in performing those activities but
|
| 140 |
+
which are not part of the work. For example, Corresponding Source
|
| 141 |
+
includes interface definition files associated with source files for
|
| 142 |
+
the work, and the source code for shared libraries and dynamically
|
| 143 |
+
linked subprograms that the work is specifically designed to require,
|
| 144 |
+
such as by intimate data communication or control flow between those
|
| 145 |
+
subprograms and other parts of the work.
|
| 146 |
+
|
| 147 |
+
The Corresponding Source need not include anything that users
|
| 148 |
+
can regenerate automatically from other parts of the Corresponding
|
| 149 |
+
Source.
|
| 150 |
+
|
| 151 |
+
The Corresponding Source for a work in source code form is that
|
| 152 |
+
same work.
|
| 153 |
+
|
| 154 |
+
2. Basic Permissions.
|
| 155 |
+
|
| 156 |
+
All rights granted under this License are granted for the term of
|
| 157 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 158 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 159 |
+
permission to run the unmodified Program. The output from running a
|
| 160 |
+
covered work is covered by this License only if the output, given its
|
| 161 |
+
content, constitutes a covered work. This License acknowledges your
|
| 162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 163 |
+
|
| 164 |
+
You may make, run and propagate covered works that you do not
|
| 165 |
+
convey, without conditions so long as your license otherwise remains
|
| 166 |
+
in force. You may convey covered works to others for the sole purpose
|
| 167 |
+
of having them make modifications exclusively for you, or provide you
|
| 168 |
+
with facilities for running those works, provided that you comply with
|
| 169 |
+
the terms of this License in conveying all material for which you do
|
| 170 |
+
not control copyright. Those thus making or running the covered works
|
| 171 |
+
for you must do so exclusively on your behalf, under your direction
|
| 172 |
+
and control, on terms that prohibit them from making any copies of
|
| 173 |
+
your copyrighted material outside their relationship with you.
|
| 174 |
+
|
| 175 |
+
Conveying under any other circumstances is permitted solely under
|
| 176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 177 |
+
makes it unnecessary.
|
| 178 |
+
|
| 179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 180 |
+
|
| 181 |
+
No covered work shall be deemed part of an effective technological
|
| 182 |
+
measure under any applicable law fulfilling obligations under article
|
| 183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 184 |
+
similar laws prohibiting or restricting circumvention of such
|
| 185 |
+
measures.
|
| 186 |
+
|
| 187 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 188 |
+
circumvention of technological measures to the extent such circumvention
|
| 189 |
+
is effected by exercising rights under this License with respect to
|
| 190 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 191 |
+
modification of the work as a means of enforcing, against the work's
|
| 192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 193 |
+
technological measures.
|
| 194 |
+
|
| 195 |
+
4. Conveying Verbatim Copies.
|
| 196 |
+
|
| 197 |
+
You may convey verbatim copies of the Program's source code as you
|
| 198 |
+
receive it, in any medium, provided that you conspicuously and
|
| 199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 200 |
+
keep intact all notices stating that this License and any
|
| 201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 202 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 203 |
+
recipients a copy of this License along with the Program.
|
| 204 |
+
|
| 205 |
+
You may charge any price or no price for each copy that you convey,
|
| 206 |
+
and you may offer support or warranty protection for a fee.
|
| 207 |
+
|
| 208 |
+
5. Conveying Modified Source Versions.
|
| 209 |
+
|
| 210 |
+
You may convey a work based on the Program, or the modifications to
|
| 211 |
+
produce it from the Program, in the form of source code under the
|
| 212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 213 |
+
|
| 214 |
+
a) The work must carry prominent notices stating that you modified
|
| 215 |
+
it, and giving a relevant date.
|
| 216 |
+
|
| 217 |
+
b) The work must carry prominent notices stating that it is
|
| 218 |
+
released under this License and any conditions added under section
|
| 219 |
+
7. This requirement modifies the requirement in section 4 to
|
| 220 |
+
"keep intact all notices".
|
| 221 |
+
|
| 222 |
+
c) You must license the entire work, as a whole, under this
|
| 223 |
+
License to anyone who comes into possession of a copy. This
|
| 224 |
+
License will therefore apply, along with any applicable section 7
|
| 225 |
+
additional terms, to the whole of the work, and all its parts,
|
| 226 |
+
regardless of how they are packaged. This License gives no
|
| 227 |
+
permission to license the work in any other way, but it does not
|
| 228 |
+
invalidate such permission if you have separately received it.
|
| 229 |
+
|
| 230 |
+
d) If the work has interactive user interfaces, each must display
|
| 231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 233 |
+
work need not make them do so.
|
| 234 |
+
|
| 235 |
+
A compilation of a covered work with other separate and independent
|
| 236 |
+
works, which are not by their nature extensions of the covered work,
|
| 237 |
+
and which are not combined with it such as to form a larger program,
|
| 238 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 240 |
+
used to limit the access or legal rights of the compilation's users
|
| 241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 242 |
+
in an aggregate does not cause this License to apply to the other
|
| 243 |
+
parts of the aggregate.
|
| 244 |
+
|
| 245 |
+
6. Conveying Non-Source Forms.
|
| 246 |
+
|
| 247 |
+
You may convey a covered work in object code form under the terms
|
| 248 |
+
of sections 4 and 5, provided that you also convey the
|
| 249 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 250 |
+
in one of these ways:
|
| 251 |
+
|
| 252 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 253 |
+
(including a physical distribution medium), accompanied by the
|
| 254 |
+
Corresponding Source fixed on a durable physical medium
|
| 255 |
+
customarily used for software interchange.
|
| 256 |
+
|
| 257 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 258 |
+
(including a physical distribution medium), accompanied by a
|
| 259 |
+
written offer, valid for at least three years and valid for as
|
| 260 |
+
long as you offer spare parts or customer support for that product
|
| 261 |
+
model, to give anyone who possesses the object code either (1) a
|
| 262 |
+
copy of the Corresponding Source for all the software in the
|
| 263 |
+
product that is covered by this License, on a durable physical
|
| 264 |
+
medium customarily used for software interchange, for a price no
|
| 265 |
+
more than your reasonable cost of physically performing this
|
| 266 |
+
conveying of source, or (2) access to copy the
|
| 267 |
+
Corresponding Source from a network server at no charge.
|
| 268 |
+
|
| 269 |
+
c) Convey individual copies of the object code with a copy of the
|
| 270 |
+
written offer to provide the Corresponding Source. This
|
| 271 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 272 |
+
only if you received the object code with such an offer, in accord
|
| 273 |
+
with subsection 6b.
|
| 274 |
+
|
| 275 |
+
d) Convey the object code by offering access from a designated
|
| 276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 277 |
+
Corresponding Source in the same way through the same place at no
|
| 278 |
+
further charge. You need not require recipients to copy the
|
| 279 |
+
Corresponding Source along with the object code. If the place to
|
| 280 |
+
copy the object code is a network server, the Corresponding Source
|
| 281 |
+
may be on a different server (operated by you or a third party)
|
| 282 |
+
that supports equivalent copying facilities, provided you maintain
|
| 283 |
+
clear directions next to the object code saying where to find the
|
| 284 |
+
Corresponding Source. Regardless of what server hosts the
|
| 285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 286 |
+
available for as long as needed to satisfy these requirements.
|
| 287 |
+
|
| 288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 289 |
+
you inform other peers where the object code and Corresponding
|
| 290 |
+
Source of the work are being offered to the general public at no
|
| 291 |
+
charge under subsection 6d.
|
| 292 |
+
|
| 293 |
+
A separable portion of the object code, whose source code is excluded
|
| 294 |
+
from the Corresponding Source as a System Library, need not be
|
| 295 |
+
included in conveying the object code work.
|
| 296 |
+
|
| 297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 298 |
+
tangible personal property which is normally used for personal, family,
|
| 299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 302 |
+
product received by a particular user, "normally used" refers to a
|
| 303 |
+
typical or common use of that class of product, regardless of the status
|
| 304 |
+
of the particular user or of the way in which the particular user
|
| 305 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 306 |
+
is a consumer product regardless of whether the product has substantial
|
| 307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 308 |
+
the only significant mode of use of the product.
|
| 309 |
+
|
| 310 |
+
"Installation Information" for a User Product means any methods,
|
| 311 |
+
procedures, authorization keys, or other information required to install
|
| 312 |
+
and execute modified versions of a covered work in that User Product from
|
| 313 |
+
a modified version of its Corresponding Source. The information must
|
| 314 |
+
suffice to ensure that the continued functioning of the modified object
|
| 315 |
+
code is in no case prevented or interfered with solely because
|
| 316 |
+
modification has been made.
|
| 317 |
+
|
| 318 |
+
If you convey an object code work under this section in, or with, or
|
| 319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 320 |
+
part of a transaction in which the right of possession and use of the
|
| 321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 322 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 323 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 324 |
+
by the Installation Information. But this requirement does not apply
|
| 325 |
+
if neither you nor any third party retains the ability to install
|
| 326 |
+
modified object code on the User Product (for example, the work has
|
| 327 |
+
been installed in ROM).
|
| 328 |
+
|
| 329 |
+
The requirement to provide Installation Information does not include a
|
| 330 |
+
requirement to continue to provide support service, warranty, or updates
|
| 331 |
+
for a work that has been modified or installed by the recipient, or for
|
| 332 |
+
the User Product in which it has been modified or installed. Access to a
|
| 333 |
+
network may be denied when the modification itself materially and
|
| 334 |
+
adversely affects the operation of the network or violates the rules and
|
| 335 |
+
protocols for communication across the network.
|
| 336 |
+
|
| 337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 338 |
+
in accord with this section must be in a format that is publicly
|
| 339 |
+
documented (and with an implementation available to the public in
|
| 340 |
+
source code form), and must require no special password or key for
|
| 341 |
+
unpacking, reading or copying.
|
| 342 |
+
|
| 343 |
+
7. Additional Terms.
|
| 344 |
+
|
| 345 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 346 |
+
License by making exceptions from one or more of its conditions.
|
| 347 |
+
Additional permissions that are applicable to the entire Program shall
|
| 348 |
+
be treated as though they were included in this License, to the extent
|
| 349 |
+
that they are valid under applicable law. If additional permissions
|
| 350 |
+
apply only to part of the Program, that part may be used separately
|
| 351 |
+
under those permissions, but the entire Program remains governed by
|
| 352 |
+
this License without regard to the additional permissions.
|
| 353 |
+
|
| 354 |
+
When you convey a copy of a covered work, you may at your option
|
| 355 |
+
remove any additional permissions from that copy, or from any part of
|
| 356 |
+
it. (Additional permissions may be written to require their own
|
| 357 |
+
removal in certain cases when you modify the work.) You may place
|
| 358 |
+
additional permissions on material, added by you to a covered work,
|
| 359 |
+
for which you have or can give appropriate copyright permission.
|
| 360 |
+
|
| 361 |
+
Notwithstanding any other provision of this License, for material you
|
| 362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 363 |
+
that material) supplement the terms of this License with terms:
|
| 364 |
+
|
| 365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 366 |
+
terms of sections 15 and 16 of this License; or
|
| 367 |
+
|
| 368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 369 |
+
author attributions in that material or in the Appropriate Legal
|
| 370 |
+
Notices displayed by works containing it; or
|
| 371 |
+
|
| 372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 373 |
+
requiring that modified versions of such material be marked in
|
| 374 |
+
reasonable ways as different from the original version; or
|
| 375 |
+
|
| 376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 377 |
+
authors of the material; or
|
| 378 |
+
|
| 379 |
+
e) Declining to grant rights under trademark law for use of some
|
| 380 |
+
trade names, trademarks, or service marks; or
|
| 381 |
+
|
| 382 |
+
f) Requiring indemnification of licensors and authors of that
|
| 383 |
+
material by anyone who conveys the material (or modified versions of
|
| 384 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 385 |
+
any liability that these contractual assumptions directly impose on
|
| 386 |
+
those licensors and authors.
|
| 387 |
+
|
| 388 |
+
All other non-permissive additional terms are considered "further
|
| 389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 390 |
+
received it, or any part of it, contains a notice stating that it is
|
| 391 |
+
governed by this License along with a term that is a further
|
| 392 |
+
restriction, you may remove that term. If a license document contains
|
| 393 |
+
a further restriction but permits relicensing or conveying under this
|
| 394 |
+
License, you may add to a covered work material governed by the terms
|
| 395 |
+
of that license document, provided that the further restriction does
|
| 396 |
+
not survive such relicensing or conveying.
|
| 397 |
+
|
| 398 |
+
If you add terms to a covered work in accord with this section, you
|
| 399 |
+
must place, in the relevant source files, a statement of the
|
| 400 |
+
additional terms that apply to those files, or a notice indicating
|
| 401 |
+
where to find the applicable terms.
|
| 402 |
+
|
| 403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 404 |
+
form of a separately written license, or stated as exceptions;
|
| 405 |
+
the above requirements apply either way.
|
| 406 |
+
|
| 407 |
+
8. Termination.
|
| 408 |
+
|
| 409 |
+
You may not propagate or modify a covered work except as expressly
|
| 410 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 411 |
+
modify it is void, and will automatically terminate your rights under
|
| 412 |
+
this License (including any patent licenses granted under the third
|
| 413 |
+
paragraph of section 11).
|
| 414 |
+
|
| 415 |
+
However, if you cease all violation of this License, then your
|
| 416 |
+
license from a particular copyright holder is reinstated (a)
|
| 417 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 419 |
+
holder fails to notify you of the violation by some reasonable means
|
| 420 |
+
prior to 60 days after the cessation.
|
| 421 |
+
|
| 422 |
+
Moreover, your license from a particular copyright holder is
|
| 423 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 424 |
+
violation by some reasonable means, this is the first time you have
|
| 425 |
+
received notice of violation of this License (for any work) from that
|
| 426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 427 |
+
your receipt of the notice.
|
| 428 |
+
|
| 429 |
+
Termination of your rights under this section does not terminate the
|
| 430 |
+
licenses of parties who have received copies or rights from you under
|
| 431 |
+
this License. If your rights have been terminated and not permanently
|
| 432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 433 |
+
material under section 10.
|
| 434 |
+
|
| 435 |
+
9. Acceptance Not Required for Having Copies.
|
| 436 |
+
|
| 437 |
+
You are not required to accept this License in order to receive or
|
| 438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 440 |
+
to receive a copy likewise does not require acceptance. However,
|
| 441 |
+
nothing other than this License grants you permission to propagate or
|
| 442 |
+
modify any covered work. These actions infringe copyright if you do
|
| 443 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 444 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 445 |
+
|
| 446 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 447 |
+
|
| 448 |
+
Each time you convey a covered work, the recipient automatically
|
| 449 |
+
receives a license from the original licensors, to run, modify and
|
| 450 |
+
propagate that work, subject to this License. You are not responsible
|
| 451 |
+
for enforcing compliance by third parties with this License.
|
| 452 |
+
|
| 453 |
+
An "entity transaction" is a transaction transferring control of an
|
| 454 |
+
organization, or substantially all assets of one, or subdividing an
|
| 455 |
+
organization, or merging organizations. If propagation of a covered
|
| 456 |
+
work results from an entity transaction, each party to that
|
| 457 |
+
transaction who receives a copy of the work also receives whatever
|
| 458 |
+
licenses to the work the party's predecessor in interest had or could
|
| 459 |
+
give under the previous paragraph, plus a right to possession of the
|
| 460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 461 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 462 |
+
|
| 463 |
+
You may not impose any further restrictions on the exercise of the
|
| 464 |
+
rights granted or affirmed under this License. For example, you may
|
| 465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 466 |
+
rights granted under this License, and you may not initiate litigation
|
| 467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 468 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 469 |
+
sale, or importing the Program or any portion of it.
|
| 470 |
+
|
| 471 |
+
11. Patents.
|
| 472 |
+
|
| 473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 474 |
+
License of the Program or a work on which the Program is based. The
|
| 475 |
+
work thus licensed is called the contributor's "contributor version".
|
| 476 |
+
|
| 477 |
+
A contributor's "essential patent claims" are all patent claims
|
| 478 |
+
owned or controlled by the contributor, whether already acquired or
|
| 479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 480 |
+
by this License, of making, using, or selling its contributor version,
|
| 481 |
+
but do not include claims that would be infringed only as a
|
| 482 |
+
consequence of further modification of the contributor version. For
|
| 483 |
+
purposes of this definition, "control" includes the right to grant
|
| 484 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 485 |
+
this License.
|
| 486 |
+
|
| 487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 488 |
+
patent license under the contributor's essential patent claims, to
|
| 489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 490 |
+
propagate the contents of its contributor version.
|
| 491 |
+
|
| 492 |
+
In the following three paragraphs, a "patent license" is any express
|
| 493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 494 |
+
(such as an express permission to practice a patent or covenant not to
|
| 495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 496 |
+
party means to make such an agreement or commitment not to enforce a
|
| 497 |
+
patent against the party.
|
| 498 |
+
|
| 499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 500 |
+
and the Corresponding Source of the work is not available for anyone
|
| 501 |
+
to copy, free of charge and under the terms of this License, through a
|
| 502 |
+
publicly available network server or other readily accessible means,
|
| 503 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 506 |
+
consistent with the requirements of this License, to extend the patent
|
| 507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 508 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 509 |
+
covered work in a country, or your recipient's use of the covered work
|
| 510 |
+
in a country, would infringe one or more identifiable patents in that
|
| 511 |
+
country that you have reason to believe are valid.
|
| 512 |
+
|
| 513 |
+
If, pursuant to or in connection with a single transaction or
|
| 514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 515 |
+
covered work, and grant a patent license to some of the parties
|
| 516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 517 |
+
or convey a specific copy of the covered work, then the patent license
|
| 518 |
+
you grant is automatically extended to all recipients of the covered
|
| 519 |
+
work and works based on it.
|
| 520 |
+
|
| 521 |
+
A patent license is "discriminatory" if it does not include within
|
| 522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 524 |
+
specifically granted under this License. You may not convey a covered
|
| 525 |
+
work if you are a party to an arrangement with a third party that is
|
| 526 |
+
in the business of distributing software, under which you make payment
|
| 527 |
+
to the third party based on the extent of your activity of conveying
|
| 528 |
+
the work, and under which the third party grants, to any of the
|
| 529 |
+
parties who would receive the covered work from you, a discriminatory
|
| 530 |
+
patent license (a) in connection with copies of the covered work
|
| 531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 532 |
+
for and in connection with specific products or compilations that
|
| 533 |
+
contain the covered work, unless you entered into that arrangement,
|
| 534 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 535 |
+
|
| 536 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 537 |
+
any implied license or other defenses to infringement that may
|
| 538 |
+
otherwise be available to you under applicable patent law.
|
| 539 |
+
|
| 540 |
+
12. No Surrender of Others' Freedom.
|
| 541 |
+
|
| 542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 543 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 546 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 548 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 549 |
+
the Program, the only way you could satisfy both those terms and this
|
| 550 |
+
License would be to refrain entirely from conveying the Program.
|
| 551 |
+
|
| 552 |
+
13. Use with the GNU Affero General Public License.
|
| 553 |
+
|
| 554 |
+
Notwithstanding any other provision of this License, you have
|
| 555 |
+
permission to link or combine any covered work with a work licensed
|
| 556 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 557 |
+
combined work, and to convey the resulting work. The terms of this
|
| 558 |
+
License will continue to apply to the part which is the covered work,
|
| 559 |
+
but the special requirements of the GNU Affero General Public License,
|
| 560 |
+
section 13, concerning interaction through a network will apply to the
|
| 561 |
+
combination as such.
|
| 562 |
+
|
| 563 |
+
14. Revised Versions of this License.
|
| 564 |
+
|
| 565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 566 |
+
the GNU General Public License from time to time. Such new versions will
|
| 567 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 568 |
+
address new problems or concerns.
|
| 569 |
+
|
| 570 |
+
Each version is given a distinguishing version number. If the
|
| 571 |
+
Program specifies that a certain numbered version of the GNU General
|
| 572 |
+
Public License "or any later version" applies to it, you have the
|
| 573 |
+
option of following the terms and conditions either of that numbered
|
| 574 |
+
version or of any later version published by the Free Software
|
| 575 |
+
Foundation. If the Program does not specify a version number of the
|
| 576 |
+
GNU General Public License, you may choose any version ever published
|
| 577 |
+
by the Free Software Foundation.
|
| 578 |
+
|
| 579 |
+
If the Program specifies that a proxy can decide which future
|
| 580 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 581 |
+
public statement of acceptance of a version permanently authorizes you
|
| 582 |
+
to choose that version for the Program.
|
| 583 |
+
|
| 584 |
+
Later license versions may give you additional or different
|
| 585 |
+
permissions. However, no additional obligations are imposed on any
|
| 586 |
+
author or copyright holder as a result of your choosing to follow a
|
| 587 |
+
later version.
|
| 588 |
+
|
| 589 |
+
15. Disclaimer of Warranty.
|
| 590 |
+
|
| 591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 599 |
+
|
| 600 |
+
16. Limitation of Liability.
|
| 601 |
+
|
| 602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 610 |
+
SUCH DAMAGES.
|
| 611 |
+
|
| 612 |
+
17. Interpretation of Sections 15 and 16.
|
| 613 |
+
|
| 614 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 615 |
+
above cannot be given local legal effect according to their terms,
|
| 616 |
+
reviewing courts shall apply local law that most closely approximates
|
| 617 |
+
an absolute waiver of all civil liability in connection with the
|
| 618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 619 |
+
copy of the Program in return for a fee.
|
| 620 |
+
|
| 621 |
+
END OF TERMS AND CONDITIONS
|
| 622 |
+
|
| 623 |
+
How to Apply These Terms to Your New Programs
|
| 624 |
+
|
| 625 |
+
If you develop a new program, and you want it to be of the greatest
|
| 626 |
+
possible use to the public, the best way to achieve this is to make it
|
| 627 |
+
free software which everyone can redistribute and change under these terms.
|
| 628 |
+
|
| 629 |
+
To do so, attach the following notices to the program. It is safest
|
| 630 |
+
to attach them to the start of each source file to most effectively
|
| 631 |
+
state the exclusion of warranty; and each file should have at least
|
| 632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 633 |
+
|
| 634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 635 |
+
Copyright (C) <year> <name of author>
|
| 636 |
+
|
| 637 |
+
This program is free software: you can redistribute it and/or modify
|
| 638 |
+
it under the terms of the GNU General Public License as published by
|
| 639 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 640 |
+
(at your option) any later version.
|
| 641 |
+
|
| 642 |
+
This program is distributed in the hope that it will be useful,
|
| 643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 645 |
+
GNU General Public License for more details.
|
| 646 |
+
|
| 647 |
+
You should have received a copy of the GNU General Public License
|
| 648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 649 |
+
|
| 650 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 651 |
+
|
| 652 |
+
If the program does terminal interaction, make it output a short
|
| 653 |
+
notice like this when it starts in an interactive mode:
|
| 654 |
+
|
| 655 |
+
<program> Copyright (C) <year> <name of author>
|
| 656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 657 |
+
This is free software, and you are welcome to redistribute it
|
| 658 |
+
under certain conditions; type `show c' for details.
|
| 659 |
+
|
| 660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 661 |
+
parts of the General Public License. Of course, your program's commands
|
| 662 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 663 |
+
|
| 664 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 667 |
+
<https://www.gnu.org/licenses/>.
|
| 668 |
+
|
| 669 |
+
The GNU General Public License does not permit incorporating your program
|
| 670 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 671 |
+
may consider it more useful to permit linking proprietary applications with
|
| 672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 673 |
+
Public License instead of this License. But first, please read
|
| 674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
extensions/CFG-Schedule-for-Automatic1111-SD/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# How to install
|
| 2 |
+
Drop the .py files in your automatic1111 scripts folder.
|
| 3 |
+
|
| 4 |
+
# CFG-Schedule-for-Automatic1111-SD
|
| 5 |
+
Note: Works with Eular a. Might not work with the rest of the samplers.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
## CFG Auto.py
|
| 9 |
+
A simplified version. Contains tools to make the small denoising effective.
|
| 10 |
+
Its main use is to fix img2img drastic change to images and makes it preserve original image features.
|
| 11 |
+
|
| 12 |
+
Following was set on denising: 0.1
|
| 13 |
+
Batch size is used to loop. Batch size:4
|
| 14 |
+
##
|
| 15 |
+
Input: output 
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## CFG Schedule.py
|
| 19 |
+
A script for scheduling CFG scale and ETA to change during the denoising steps
|
| 20 |
+
<pre>
|
| 21 |
+
Modified code of https://github.com/tkalayci71/attenuate-cfg-scale
|
| 22 |
+
To use: Place the .py file in AUTOMATIC1111\scripts folder
|
| 23 |
+
Update: 11/14/2022
|
| 24 |
+
-Now works with all samplers
|
| 25 |
+
-new function x. Example use: x(t,60,70,2) which will map t to be 0 at 60 and 1 and 70, then multipy by 2
|
| 26 |
+
-edit: Indecies can now have more than one index. Example: 0,5:=1 ; 1:10
|
| 27 |
+
Update: 11/13/2022
|
| 28 |
+
|
| 29 |
+
You can now use functions like:
|
| 30 |
+
0:=math.sin(t) , 10:=math.cos(t)
|
| 31 |
+
or simply just:
|
| 32 |
+
=math.sin(t)
|
| 33 |
+
|
| 34 |
+
Available variables:
|
| 35 |
+
t: current step
|
| 36 |
+
T: total steps
|
| 37 |
+
e: (1-t/T) which is current ETA
|
| 38 |
+
d: denoising strength
|
| 39 |
+
pi:pi
|
| 40 |
+
cfg: initial CFG
|
| 41 |
+
math: The python math module
|
| 42 |
+
|
| 43 |
+
Available functions:
|
| 44 |
+
-From python: min, max, pow, abs
|
| 45 |
+
-x(value,min,max,multiply)
|
| 46 |
+
This will take value and make it 0 when <=min, and make it 1 when >=max. Then, multiply result by last argumant.
|
| 47 |
+
If multiply is less than 0, the range becomes 1 to 0 instead
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
I've tried the following function on 58 steps and it is giving good results:
|
| 52 |
+
CFG:
|
| 53 |
+
0:=math.fabs( (e*1.4-2)*15);30:5
|
| 54 |
+
ETA:
|
| 55 |
+
0:=0.01; 20:=e*1.5;10:=e
|
| 56 |
+
</pre>
|
| 57 |
+

|
extensions/CFG-Schedule-for-Automatic1111-SD/scripts/CFG Auto.py
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#CFG Scheduler for Automatic1111 Stable Diffusion web-ui
|
| 2 |
+
#Author: https://github.com/guzuligo/
|
| 3 |
+
#Based on: https://github.com/tkalayci71/attenuate-cfg-scale
|
| 4 |
+
#Version: 1.81
|
| 5 |
+
|
| 6 |
+
from logging import PlaceHolder
|
| 7 |
+
import math
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import traceback
|
| 11 |
+
import copy
|
| 12 |
+
import numpy as np
|
| 13 |
+
import modules.scripts as scripts
|
| 14 |
+
import gradio as gr
|
| 15 |
+
|
| 16 |
+
#from modules.processing import Processed, process_images
|
| 17 |
+
from modules import images,processing
|
| 18 |
+
from modules.processing import process_images, Processed
|
| 19 |
+
from modules.processing import Processed
|
| 20 |
+
from modules.shared import opts, cmd_opts, state
|
| 21 |
+
class Script(scripts.Script):
|
| 22 |
+
def run(self,p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle):
|
| 23 |
+
return self.runBasic(p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle)
|
| 24 |
+
|
| 25 |
+
#def run(self,p,cfg,eta,dns ,loops,nSingle):
|
| 26 |
+
# return self.runAdvanced(p,cfg,eta,dns ,loops,nSingle)
|
| 27 |
+
|
| 28 |
+
def show(self, is_img2img):
|
| 29 |
+
self.isAdvanced=False
|
| 30 |
+
return True
|
| 31 |
+
def title(self):
|
| 32 |
+
return "CFG Scheduling" if (self.isAdvanced) else "CFG Auto"
|
| 33 |
+
|
| 34 |
+
def uiAdvanced(self, is_img2img):
|
| 35 |
+
|
| 36 |
+
placeholder="The steps on which to modify, in format step:value - example: 0:10 ; 10:15"
|
| 37 |
+
n0 = gr.Textbox(label="CFG",placeholder=placeholder)
|
| 38 |
+
placeholder="You can also use functions like: 0: math.fabs(-t) ; 1: (1-t/T) ; 2:=e ;3:t*d"
|
| 39 |
+
n1 = gr.Textbox(label="ETA",placeholder=placeholder)
|
| 40 |
+
#loops
|
| 41 |
+
#n2 = gr.Slider(minimum=1, maximum=32, step=1, label='Loops', value=1)
|
| 42 |
+
n2 = gr.Slider(minimum=0, maximum=1, step=0.01, label='Target Denoising : Decay per Batch', value=0.5)
|
| 43 |
+
with gr.Row():
|
| 44 |
+
loops=gr.Number(value=1,precision=0,label="loops")
|
| 45 |
+
nSingle= gr.Checkbox(label="Loop returns one")
|
| 46 |
+
|
| 47 |
+
return [n0,n1,n2 ,loops,nSingle]
|
| 48 |
+
#uiBasic
|
| 49 |
+
def uiAuto(self, is_img2img):
|
| 50 |
+
self.autoOptions={"b1":"Blur First V1","b2":"Blur Last","f1":"Force at Start V1","f2":"Force Allover"}
|
| 51 |
+
with gr.Row():
|
| 52 |
+
dns = gr.Slider(minimum=0, maximum=1, step=0.01, label='Target Denoising : Decay per Batch', value=0.25)
|
| 53 |
+
n0=gr.Dropdown(list(self.autoOptions.values()),value=self.autoOptions["b1"],label="Scheduler")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
n1 = gr.Slider(minimum=0, maximum=100, step=1, label='Main Strength', value=10)
|
| 56 |
+
n2 = gr.Slider(minimum=0, maximum=100, step=1, label='Sub- Strength', value=10)
|
| 57 |
+
with gr.Row():
|
| 58 |
+
n3 = gr.Slider(minimum=0, maximum=100, step=1, label='Main Range', value=10)
|
| 59 |
+
n4 = gr.Slider(minimum=0, maximum=100, step=1, label='Sub- Range', value=10)
|
| 60 |
+
with gr.Row():
|
| 61 |
+
loops=gr.Number(value=1,precision=0,label="loops")
|
| 62 |
+
nSingle= gr.Checkbox(label="Loop returns one")
|
| 63 |
+
return [n0,dns, n1,n2,n3,n4 ,loops,nSingle]
|
| 64 |
+
|
| 65 |
+
def ui(self, is_img2img):
|
| 66 |
+
return self.uiAdvanced(is_img2img) if (self.isAdvanced) else self.uiAuto(is_img2img)
|
| 67 |
+
|
| 68 |
+
def prepare(self,p,cfg,eta):
|
| 69 |
+
sampler_name=p.sampler_name
|
| 70 |
+
if not sampler_name:
|
| 71 |
+
print("Warning: sampler not specified. Using Euler a")
|
| 72 |
+
sampler_name="Euler a"
|
| 73 |
+
#if p.sampler_index in (0,1,2,7,8,10,14):
|
| 74 |
+
if sampler_name in ('Euler a','Euler','LMS','DPM++ 2M','DPM fast','LMS Karras','DPM++ 2M Karras'):
|
| 75 |
+
max_mul_count = p.steps * p.batch_size
|
| 76 |
+
steps_per_mul = p.batch_size
|
| 77 |
+
#elif p.sampler_index in (3,4,5,6,11,12,13):
|
| 78 |
+
elif sampler_name in ('Heun','DPM2','DPM2 a','DPM++ 2S a','DPM2 Karras','DPM2 a Karras','DPM++ 2S a Karras'):
|
| 79 |
+
max_mul_count = ((p.steps*2)-1) * p.batch_size
|
| 80 |
+
steps_per_mul = 2 * p.batch_size
|
| 81 |
+
#elif p.sampler_index==15: # ddim
|
| 82 |
+
elif sampler_name=='DDIM': # ddim
|
| 83 |
+
max_mul_count = fix_ddim_step_count(p.steps)
|
| 84 |
+
steps_per_mul = 1
|
| 85 |
+
#elif p.sampler_index==16: # plms
|
| 86 |
+
elif sampler_name=='PLMS': # plms
|
| 87 |
+
max_mul_count = fix_ddim_step_count(p.steps)+1
|
| 88 |
+
steps_per_mul = 1
|
| 89 |
+
else:
|
| 90 |
+
print("Not supported sampler", p.sampler_name, p.sampler_index)
|
| 91 |
+
return # 9=dpm adaptive
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
#print("it is:",n0t)
|
| 96 |
+
#for x in range(int(n)):
|
| 97 |
+
self.p=p
|
| 98 |
+
cfg=cfg.strip()
|
| 99 |
+
eta=eta.strip()
|
| 100 |
+
if cfg:
|
| 101 |
+
p.cfg_scale=Fake_float(p.cfg_scale,self.split(cfg,str(p.cfg_scale)) , max_mul_count, steps_per_mul)
|
| 102 |
+
#p.cfg_scale.p=p
|
| 103 |
+
if eta:
|
| 104 |
+
if (eta.find("@")==-1):
|
| 105 |
+
p.s_churn=p.eta =Fake_float(p.eta or 1,self.split(eta,str(p.eta)) , max_mul_count, steps_per_mul)
|
| 106 |
+
#print(p.s_noise)
|
| 107 |
+
|
| 108 |
+
#Fake_float(p.s_churn or 1,self.split(eta,str(p.s_churn)), max_mul_count, steps_per_mul)
|
| 109 |
+
else:
|
| 110 |
+
eta=eta.split("@")
|
| 111 |
+
if eta[0].strip()!="":
|
| 112 |
+
p.s_churn=Fake_float(p.s_churn or 1,self.split(eta[0],str(p.s_churn)), max_mul_count, steps_per_mul)
|
| 113 |
+
if len(eta)>1 and eta[1].strip()!="":
|
| 114 |
+
p.s_noise=Fake_float(p.s_noise or 1,self.split(eta[1],str(p.s_noise)), max_mul_count, steps_per_mul)
|
| 115 |
+
if len(eta)>2 and eta[2].strip()!="":
|
| 116 |
+
p.s_tmin=Fake_float(p.s_tmin or 1,self.split(eta[2],str(p.s_tmin)), max_mul_count, steps_per_mul)
|
| 117 |
+
if len(eta)>3 and eta[3].strip()!="":
|
| 118 |
+
p.s_tmax=Fake_float(p.s_tmax or 1,self.split(eta[2],str(p.s_tmax)), max_mul_count, steps_per_mul)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
#p.cfg_scale.p=p
|
| 122 |
+
#
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def runBasic(self,p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle):
|
| 127 |
+
if(n0==self.autoOptions["b1"]):
|
| 128 |
+
cfg=f"""0:{ns2}/2 if (t<T* (({nr1}/100)**2)) else cfg"""
|
| 129 |
+
eta=f"""0:{ns1}+1 if (t<T*(({nr1}/100)**2) ) else e*({nr2}/50)"""
|
| 130 |
+
elif(n0==self.autoOptions["f1"]):
|
| 131 |
+
cfg=f"""0:({ns1}*4)*((1-d**0.5)**1.5)/(t*(30-cfg)/30+1)/(l*2+1) if (t<T*{nr1}/100) else 0.1 if (t<T*({nr1}+{nr2}-{nr1}*{nr2})/100) else 7-d*7"""
|
| 132 |
+
eta=f"""0:0.8+{ns2}/25-min(t*0.1, 0.8+{ns2}/25 -0.01) if (t<T*{nr1}/100) else {ns2}/(10*(1+l*0.5)) if (t<T*({nr1}+{nr2}-{nr1}*{nr2})/100) else 1+e"""
|
| 133 |
+
elif(n0==self.autoOptions["b2"]):
|
| 134 |
+
cfg=f"""0:cfg if (e>{nr1}/100 or e<(1-({nr1}+{nr2}*(100-{nr1})/100)/100)) else {ns2}/10"""
|
| 135 |
+
eta=f"""0:e if (e>{nr1}/100 or e<(1-({nr1}+{nr2}*(100-{nr1})/100)/100)) else {ns1}/10"""
|
| 136 |
+
elif(n0==self.autoOptions["f2"]):
|
| 137 |
+
cfg=f"""= min(40,max(0,cfg+x(t)*({ns2}-50)/2 )) """
|
| 138 |
+
eta=f"""0:(1-(t%(2+ 10-.1*{nr1} ))/ (2+10-.1*{nr1}) )*{ns1}*.1 * (e*(100-{nr2})+{nr2})*.01 """
|
| 139 |
+
self.cfgsib={"Scheduler":n0,'Main Strength':ns1,'Sub- Strength':ns2,'Main Range':nr1,'Sub- Range':nr2}
|
| 140 |
+
return self.runAdvanced(p,cfg,eta,dns ,loops,nSingle)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def runAdvanced(self, p, cfg,eta,dns ,loops,nSingle):
|
| 144 |
+
self.initSeed=p.seed
|
| 145 |
+
#loops=p.batch_size
|
| 146 |
+
loops = loops if (loops>0) else 1
|
| 147 |
+
|
| 148 |
+
batch_count=p.n_iter
|
| 149 |
+
state.job_count = loops*p.n_iter
|
| 150 |
+
p.denoising_strength=p.denoising_strength or (1 if (self.isAdvanced) else 0.2)
|
| 151 |
+
initial_denoising_strength=p.denoising_strength
|
| 152 |
+
p.do_not_save_grid = True
|
| 153 |
+
if hasattr(p,"init_images"):
|
| 154 |
+
original_init_image = p.init_images
|
| 155 |
+
initial_color_corrections = [processing.setup_color_correction(p.init_images[0])]
|
| 156 |
+
else:
|
| 157 |
+
original_init_image=None
|
| 158 |
+
|
| 159 |
+
all_images = []
|
| 160 |
+
cfgsi=" loops:"+str(loops)+" terget denoising: "+str(dns)+"\nCFG: "+cfg+"\nETA: "+eta+"\n"
|
| 161 |
+
|
| 162 |
+
p.extra_generation_params = {
|
| 163 |
+
"CFG Scheduler Info":cfgsi,
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
#if basic, add basic info as well
|
| 168 |
+
if (self.isAdvanced==False):
|
| 169 |
+
self.cfgsib.update(p.extra_generation_params)
|
| 170 |
+
p.extra_generation_params=self.cfgsib
|
| 171 |
+
|
| 172 |
+
if loops>1:
|
| 173 |
+
processing.fix_seed(p)
|
| 174 |
+
#self.initDenoise=p.denoising_strength
|
| 175 |
+
|
| 176 |
+
for n in range(batch_count):
|
| 177 |
+
proc=None
|
| 178 |
+
history = []
|
| 179 |
+
p.denoising_strength=initial_denoising_strength
|
| 180 |
+
if (original_init_image!=None):
|
| 181 |
+
p.init_images=original_init_image
|
| 182 |
+
for loop in range(loops):
|
| 183 |
+
if opts.img2img_color_correction and original_init_image!=None:
|
| 184 |
+
p.color_corrections = initial_color_corrections
|
| 185 |
+
|
| 186 |
+
p.batch_size = 1
|
| 187 |
+
p.n_iter = 1
|
| 188 |
+
self.loop=loop
|
| 189 |
+
self.prepare(p, cfg,eta)
|
| 190 |
+
proc = process_images(p)
|
| 191 |
+
if loop==0:
|
| 192 |
+
self.initInfo=proc.info
|
| 193 |
+
self.initSeed=proc.seed
|
| 194 |
+
if len(proc.images)>0:
|
| 195 |
+
history.append(proc.images[0])
|
| 196 |
+
p.seed+=1
|
| 197 |
+
p.init_images=[proc.images[0]]
|
| 198 |
+
#p.denoising_strength=min(max(p.denoising_strength * dns, 0.05), 1)
|
| 199 |
+
p.denoising_strength=initial_denoising_strength+(dns-initial_denoising_strength)*(loop+1)/(loops)
|
| 200 |
+
else:#interrupted
|
| 201 |
+
break
|
| 202 |
+
#print("New denoising:"+str(p.denoising_strength)+"\n" )
|
| 203 |
+
all_images += history
|
| 204 |
+
if loops>0:#TODO:maybe this is not needed
|
| 205 |
+
p.seed=self.initSeed
|
| 206 |
+
#return proc if (loops==1 and p.batch_size==1) else Processed(p, all_images, self.initSeed, self.initInfo)
|
| 207 |
+
return proc if(nSingle) else Processed(p, all_images, self.initSeed, self.initInfo)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def peek(self,val):
|
| 216 |
+
print(val)
|
| 217 |
+
return val
|
| 218 |
+
|
| 219 |
+
def split(self,src,default='0'):
|
| 220 |
+
p=self.p
|
| 221 |
+
self.P=copy.copy({
|
| 222 |
+
'cfg':float(str(p.cfg_scale)),
|
| 223 |
+
'd':p.denoising_strength or 1,
|
| 224 |
+
'l':self.loop,
|
| 225 |
+
'min':min,
|
| 226 |
+
'max':max,
|
| 227 |
+
'abs':abs,
|
| 228 |
+
'pow':pow,
|
| 229 |
+
'pi':math.pi,
|
| 230 |
+
'x':self._interpolate,
|
| 231 |
+
'int':int,
|
| 232 |
+
'floor':math.floor,
|
| 233 |
+
'peek':self.peek,
|
| 234 |
+
})
|
| 235 |
+
|
| 236 |
+
if src[0:4]=="eval":
|
| 237 |
+
src="0:"+src[4:]
|
| 238 |
+
if src[0]=="=":
|
| 239 |
+
src="0:"+src[1:]
|
| 240 |
+
|
| 241 |
+
#clean up
|
| 242 |
+
while src[len(src)-1] in [";"," "]:
|
| 243 |
+
src=src[0:len(src)-1]
|
| 244 |
+
while src[0] in [";"," "]:
|
| 245 |
+
src=src[1:]
|
| 246 |
+
|
| 247 |
+
arr0 = src.split(';')##2
|
| 248 |
+
|
| 249 |
+
#resort array accounting for commas in indecies
|
| 250 |
+
arr=[]
|
| 251 |
+
for j in arr0:
|
| 252 |
+
#print(j)
|
| 253 |
+
v=j.split(":")
|
| 254 |
+
q=v[0].split(",")
|
| 255 |
+
|
| 256 |
+
for i in q:
|
| 257 |
+
arr.append(i+":"+v[1])
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
arr.sort(key=self._sort)
|
| 263 |
+
s=[]
|
| 264 |
+
val=default
|
| 265 |
+
for j in range(p.steps+1):
|
| 266 |
+
i=0
|
| 267 |
+
while i<len(arr) and i<=j:
|
| 268 |
+
v=arr[i].split(":")
|
| 269 |
+
#s=proc[j].n_iter
|
| 270 |
+
if math.floor(int(v[0]) if v[0].isnumeric() else float(v[0])*p.steps)==j:
|
| 271 |
+
val=v[1].strip()
|
| 272 |
+
break
|
| 273 |
+
i=i+1
|
| 274 |
+
|
| 275 |
+
#lets just evaluate all
|
| 276 |
+
if val[0]=="=":
|
| 277 |
+
val=val[1:]
|
| 278 |
+
|
| 279 |
+
_eta=1-j/p.steps
|
| 280 |
+
params={'t':j,'T':p.steps,'math':math,'p':p,'e':float(str(_eta))}
|
| 281 |
+
|
| 282 |
+
params.update(copy.copy(self.P))
|
| 283 |
+
#print(params)
|
| 284 |
+
s.append(float(eval(val,params)))
|
| 285 |
+
#end while loop
|
| 286 |
+
#else:
|
| 287 |
+
#s.append(float(val))
|
| 288 |
+
print(np.round(s,1),"\n")
|
| 289 |
+
return s
|
| 290 |
+
#limits a range of a value
|
| 291 |
+
def _interpolate(self,v,start=0,end=None,m=1):
|
| 292 |
+
end=end or self.p.steps
|
| 293 |
+
v=min(max(v,start),end)-start
|
| 294 |
+
return v*m/(end-start)+(1 if m<0 else 0)
|
| 295 |
+
|
| 296 |
+
def _sort(self,a):
|
| 297 |
+
_=a.split(":")[0]#splitter tester
|
| 298 |
+
return math.floor(int(_) if (_.isnumeric()) else float(_)*self.p.steps)
|
| 299 |
+
|
| 300 |
+
def evaluate (self,src):
|
| 301 |
+
s=[]
|
| 302 |
+
p=self.p
|
| 303 |
+
T=self.p.steps
|
| 304 |
+
for j in range(T+1):
|
| 305 |
+
_eta=1-j/p.steps
|
| 306 |
+
params={'t':j,'T':p.steps,'math':math,'p':p,'e':_eta}
|
| 307 |
+
params.update(self.P)
|
| 308 |
+
s.append(float(eval(src,params)))
|
| 309 |
+
return s
|
| 310 |
+
|
| 311 |
+
class Fake_float(float):
|
| 312 |
+
def __new__(self, value, arr, max_mul_count, steps_per_mul):
|
| 313 |
+
return float.__new__(self, value)
|
| 314 |
+
|
| 315 |
+
def __init__(self, value, arr, max_mul_count, steps_per_mul):
|
| 316 |
+
float.__init__(value)
|
| 317 |
+
self.arr = arr
|
| 318 |
+
self.curstep = 0
|
| 319 |
+
#self.p=p
|
| 320 |
+
|
| 321 |
+
#self.orig_value = orig_value
|
| 322 |
+
#self.target_value = target_value
|
| 323 |
+
self.max_mul_count = max_mul_count
|
| 324 |
+
self.current_mul = 0
|
| 325 |
+
self.steps_per_mul = steps_per_mul
|
| 326 |
+
self.current_step = 0 #fake
|
| 327 |
+
self.max_step_count = (max_mul_count // steps_per_mul) + (max_mul_count % steps_per_mul > 0)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def __mul__(self,other):
|
| 331 |
+
return self.fake_mul(other)
|
| 332 |
+
|
| 333 |
+
def __rmul__(self,other):
|
| 334 |
+
return self.fake_mul(other)
|
| 335 |
+
|
| 336 |
+
#def __add__(self,other):
|
| 337 |
+
#print("ADD!")
|
| 338 |
+
# return self.get_fake_value(other)+other
|
| 339 |
+
#def __sub__(self,other):
|
| 340 |
+
#print("SUB!")
|
| 341 |
+
# return self.get_fake_value(other)-other
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
def fake_mul(self,other):
|
| 346 |
+
#print("MUL!")
|
| 347 |
+
return self.get_fake_value(other) * other
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
def get_fake_value(self,other):
|
| 351 |
+
if (self.max_step_count==1):
|
| 352 |
+
fake_value = self.arr[0]
|
| 353 |
+
else:
|
| 354 |
+
|
| 355 |
+
fake_value = self.arr[self.curstep]
|
| 356 |
+
self.current_mul = (self.current_mul+1) % self.max_mul_count
|
| 357 |
+
self.curstep = (self.current_mul) // self.steps_per_mul
|
| 358 |
+
self.current_step+=1#FAKE STEP
|
| 359 |
+
return fake_value
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def fix_ddim_step_count(steps):
|
| 365 |
+
valid_step = 999 / (1000 // steps)
|
| 366 |
+
if valid_step == int(valid_step): steps=int(valid_step)+1
|
| 367 |
+
if ((1000 % steps)!=0): steps +=1
|
| 368 |
+
return steps
|
extensions/CFG-Schedule-for-Automatic1111-SD/scripts/CFG Schedule.py
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#CFG Scheduler for Automatic1111 Stable Diffusion web-ui
|
| 2 |
+
#Author: https://github.com/guzuligo/
|
| 3 |
+
#Based on: https://github.com/tkalayci71/attenuate-cfg-scale
|
| 4 |
+
#Version: 1.81
|
| 5 |
+
|
| 6 |
+
from logging import PlaceHolder
|
| 7 |
+
import math
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import traceback
|
| 11 |
+
import copy
|
| 12 |
+
import numpy as np
|
| 13 |
+
import modules.scripts as scripts
|
| 14 |
+
import gradio as gr
|
| 15 |
+
|
| 16 |
+
#from modules.processing import Processed, process_images
|
| 17 |
+
from modules import images,processing
|
| 18 |
+
from modules.processing import process_images, Processed
|
| 19 |
+
from modules.processing import Processed
|
| 20 |
+
from modules.shared import opts, cmd_opts, state
|
| 21 |
+
class Script(scripts.Script):
|
| 22 |
+
#def run(self,p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle):
|
| 23 |
+
# return self.runBasic(p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle)
|
| 24 |
+
|
| 25 |
+
def run(self,p,cfg,eta,dns ,loops,nSingle):
|
| 26 |
+
return self.runAdvanced(p,cfg,eta,dns ,loops,nSingle)
|
| 27 |
+
|
| 28 |
+
def show(self, is_img2img):
|
| 29 |
+
self.isAdvanced=True
|
| 30 |
+
return True
|
| 31 |
+
def title(self):
|
| 32 |
+
return "CFG Scheduling" if (self.isAdvanced) else "CFG Auto"
|
| 33 |
+
|
| 34 |
+
def uiAdvanced(self, is_img2img):
|
| 35 |
+
|
| 36 |
+
placeholder="The steps on which to modify, in format step:value - example: 0:10 ; 10:15"
|
| 37 |
+
n0 = gr.Textbox(label="CFG",placeholder=placeholder)
|
| 38 |
+
placeholder="You can also use functions like: 0: math.fabs(-t) ; 1: (1-t/T) ; 2:=e ;3:t*d"
|
| 39 |
+
n1 = gr.Textbox(label="ETA",placeholder=placeholder)
|
| 40 |
+
#loops
|
| 41 |
+
#n2 = gr.Slider(minimum=1, maximum=32, step=1, label='Loops', value=1)
|
| 42 |
+
n2 = gr.Slider(minimum=0, maximum=1, step=0.01, label='Target Denoising : Decay per Batch', value=0.5)
|
| 43 |
+
with gr.Row():
|
| 44 |
+
loops=gr.Number(value=1,precision=0,label="loops")
|
| 45 |
+
nSingle= gr.Checkbox(label="Loop returns one")
|
| 46 |
+
|
| 47 |
+
return [n0,n1,n2 ,loops,nSingle]
|
| 48 |
+
#uiBasic
|
| 49 |
+
def uiAuto(self, is_img2img):
|
| 50 |
+
self.autoOptions={"b1":"Blur First V1","b2":"Blur Last","f1":"Force at Start V1","f2":"Force Allover"}
|
| 51 |
+
with gr.Row():
|
| 52 |
+
dns = gr.Slider(minimum=0, maximum=1, step=0.01, label='Target Denoising : Decay per Batch', value=0.25)
|
| 53 |
+
n0=gr.Dropdown(list(self.autoOptions.values()),value=self.autoOptions["b1"],label="Scheduler")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
n1 = gr.Slider(minimum=0, maximum=100, step=1, label='Main Strength', value=10)
|
| 56 |
+
n2 = gr.Slider(minimum=0, maximum=100, step=1, label='Sub- Strength', value=10)
|
| 57 |
+
with gr.Row():
|
| 58 |
+
n3 = gr.Slider(minimum=0, maximum=100, step=1, label='Main Range', value=10)
|
| 59 |
+
n4 = gr.Slider(minimum=0, maximum=100, step=1, label='Sub- Range', value=10)
|
| 60 |
+
with gr.Row():
|
| 61 |
+
loops=gr.Number(value=1,precision=0,label="loops")
|
| 62 |
+
nSingle= gr.Checkbox(label="Loop returns one")
|
| 63 |
+
return [n0,dns, n1,n2,n3,n4 ,loops,nSingle]
|
| 64 |
+
|
| 65 |
+
def ui(self, is_img2img):
|
| 66 |
+
return self.uiAdvanced(is_img2img) if (self.isAdvanced) else self.uiAuto(is_img2img)
|
| 67 |
+
|
| 68 |
+
def prepare(self,p,cfg,eta):
|
| 69 |
+
sampler_name=p.sampler_name
|
| 70 |
+
if not sampler_name:
|
| 71 |
+
print("Warning: sampler not specified. Using Euler a")
|
| 72 |
+
sampler_name="Euler a"
|
| 73 |
+
#if p.sampler_index in (0,1,2,7,8,10,14):
|
| 74 |
+
if sampler_name in ('Euler a','Euler','LMS','DPM++ 2M','DPM fast','LMS Karras','DPM++ 2M Karras'):
|
| 75 |
+
max_mul_count = p.steps * p.batch_size
|
| 76 |
+
steps_per_mul = p.batch_size
|
| 77 |
+
#elif p.sampler_index in (3,4,5,6,11,12,13):
|
| 78 |
+
elif sampler_name in ('Heun','DPM2','DPM2 a','DPM++ 2S a','DPM2 Karras','DPM2 a Karras','DPM++ 2S a Karras'):
|
| 79 |
+
max_mul_count = ((p.steps*2)-1) * p.batch_size
|
| 80 |
+
steps_per_mul = 2 * p.batch_size
|
| 81 |
+
#elif p.sampler_index==15: # ddim
|
| 82 |
+
elif sampler_name=='DDIM': # ddim
|
| 83 |
+
max_mul_count = fix_ddim_step_count(p.steps)
|
| 84 |
+
steps_per_mul = 1
|
| 85 |
+
#elif p.sampler_index==16: # plms
|
| 86 |
+
elif sampler_name=='PLMS': # plms
|
| 87 |
+
max_mul_count = fix_ddim_step_count(p.steps)+1
|
| 88 |
+
steps_per_mul = 1
|
| 89 |
+
else:
|
| 90 |
+
print("Not supported sampler", p.sampler_name, p.sampler_index)
|
| 91 |
+
return # 9=dpm adaptive
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
#print("it is:",n0t)
|
| 96 |
+
#for x in range(int(n)):
|
| 97 |
+
self.p=p
|
| 98 |
+
cfg=cfg.strip()
|
| 99 |
+
eta=eta.strip()
|
| 100 |
+
if cfg:
|
| 101 |
+
p.cfg_scale=Fake_float(p.cfg_scale,self.split(cfg,str(p.cfg_scale)) , max_mul_count, steps_per_mul)
|
| 102 |
+
#p.cfg_scale.p=p
|
| 103 |
+
if eta:
|
| 104 |
+
if (eta.find("@")==-1):
|
| 105 |
+
p.s_churn=p.eta =Fake_float(p.eta or 1,self.split(eta,str(p.eta)) , max_mul_count, steps_per_mul)
|
| 106 |
+
#print(p.s_noise)
|
| 107 |
+
|
| 108 |
+
#Fake_float(p.s_churn or 1,self.split(eta,str(p.s_churn)), max_mul_count, steps_per_mul)
|
| 109 |
+
else:
|
| 110 |
+
eta=eta.split("@")
|
| 111 |
+
if eta[0].strip()!="":
|
| 112 |
+
p.s_churn=Fake_float(p.s_churn or 1,self.split(eta[0],str(p.s_churn)), max_mul_count, steps_per_mul)
|
| 113 |
+
if len(eta)>1 and eta[1].strip()!="":
|
| 114 |
+
p.s_noise=Fake_float(p.s_noise or 1,self.split(eta[1],str(p.s_noise)), max_mul_count, steps_per_mul)
|
| 115 |
+
if len(eta)>2 and eta[2].strip()!="":
|
| 116 |
+
p.s_tmin=Fake_float(p.s_tmin or 1,self.split(eta[2],str(p.s_tmin)), max_mul_count, steps_per_mul)
|
| 117 |
+
if len(eta)>3 and eta[3].strip()!="":
|
| 118 |
+
p.s_tmax=Fake_float(p.s_tmax or 1,self.split(eta[2],str(p.s_tmax)), max_mul_count, steps_per_mul)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
#p.cfg_scale.p=p
|
| 122 |
+
#
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def runBasic(self,p,n0,dns,ns1,ns2,nr1,nr2 ,loops,nSingle):
|
| 127 |
+
if(n0==self.autoOptions["b1"]):
|
| 128 |
+
cfg=f"""0:{ns2}/2 if (t<T* (({nr1}/100)**2)) else cfg"""
|
| 129 |
+
eta=f"""0:{ns1}+1 if (t<T*(({nr1}/100)**2) ) else e*({nr2}/50)"""
|
| 130 |
+
elif(n0==self.autoOptions["f1"]):
|
| 131 |
+
cfg=f"""0:({ns1}*4)*((1-d**0.5)**1.5)/(t*(30-cfg)/30+1)/(l*2+1) if (t<T*{nr1}/100) else 0.1 if (t<T*({nr1}+{nr2}-{nr1}*{nr2})/100) else 7-d*7"""
|
| 132 |
+
eta=f"""0:0.8+{ns2}/25-min(t*0.1, 0.8+{ns2}/25 -0.01) if (t<T*{nr1}/100) else {ns2}/(10*(1+l*0.5)) if (t<T*({nr1}+{nr2}-{nr1}*{nr2})/100) else 1+e"""
|
| 133 |
+
elif(n0==self.autoOptions["b2"]):
|
| 134 |
+
cfg=f"""0:cfg if (e>{nr1}/100 or e<(1-({nr1}+{nr2}*(100-{nr1})/100)/100)) else {ns2}/10"""
|
| 135 |
+
eta=f"""0:e if (e>{nr1}/100 or e<(1-({nr1}+{nr2}*(100-{nr1})/100)/100)) else {ns1}/10"""
|
| 136 |
+
elif(n0==self.autoOptions["f2"]):
|
| 137 |
+
cfg=f"""= min(40,max(0,cfg+x(t)*({ns2}-50)/2 )) """
|
| 138 |
+
eta=f"""0:(1-(t%(2+ 10-.1*{nr1} ))/ (2+10-.1*{nr1}) )*{ns1}*.1 * (e*(100-{nr2})+{nr2})*.01 """
|
| 139 |
+
self.cfgsib={"Scheduler":n0,'Main Strength':ns1,'Sub- Strength':ns2,'Main Range':nr1,'Sub- Range':nr2}
|
| 140 |
+
self.cfgsib={"Scheduler":n0,'Main Strength':ns1,'Sub- Strength':ns2,'Main Range':nr1,'Sub- Range':nr2}
|
| 141 |
+
return self.runAdvanced(p,cfg,eta,dns ,loops,nSingle)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def runAdvanced(self, p, cfg,eta,dns ,loops,nSingle):
|
| 145 |
+
self.initSeed=p.seed
|
| 146 |
+
#loops=p.batch_size
|
| 147 |
+
loops = loops if (loops>0) else 1
|
| 148 |
+
|
| 149 |
+
batch_count=p.n_iter
|
| 150 |
+
state.job_count = loops*p.n_iter
|
| 151 |
+
p.denoising_strength=p.denoising_strength or (1 if (self.isAdvanced) else 0.2)
|
| 152 |
+
initial_denoising_strength=p.denoising_strength
|
| 153 |
+
p.do_not_save_grid = True
|
| 154 |
+
if hasattr(p,"init_images"):
|
| 155 |
+
original_init_image = p.init_images
|
| 156 |
+
initial_color_corrections = [processing.setup_color_correction(p.init_images[0])]
|
| 157 |
+
else:
|
| 158 |
+
original_init_image=None
|
| 159 |
+
|
| 160 |
+
all_images = []
|
| 161 |
+
cfgsi=" loops:"+str(loops)+" terget denoising: "+str(dns)+"\nCFG: "+cfg+"\nETA: "+eta+"\n"
|
| 162 |
+
|
| 163 |
+
p.extra_generation_params = {
|
| 164 |
+
"CFG Scheduler Info":cfgsi,
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
#if basic, add basic info as well
|
| 169 |
+
if (self.isAdvanced==False):
|
| 170 |
+
self.cfgsib.update(p.extra_generation_params)
|
| 171 |
+
p.extra_generation_params=self.cfgsib
|
| 172 |
+
|
| 173 |
+
if loops>1:
|
| 174 |
+
processing.fix_seed(p)
|
| 175 |
+
#self.initDenoise=p.denoising_strength
|
| 176 |
+
|
| 177 |
+
for n in range(batch_count):
|
| 178 |
+
proc=None
|
| 179 |
+
history = []
|
| 180 |
+
p.denoising_strength=initial_denoising_strength
|
| 181 |
+
if (original_init_image!=None):
|
| 182 |
+
p.init_images=original_init_image
|
| 183 |
+
for loop in range(loops):
|
| 184 |
+
if opts.img2img_color_correction and original_init_image!=None:
|
| 185 |
+
p.color_corrections = initial_color_corrections
|
| 186 |
+
|
| 187 |
+
p.batch_size = 1
|
| 188 |
+
p.n_iter = 1
|
| 189 |
+
self.loop=loop
|
| 190 |
+
self.prepare(p, cfg,eta)
|
| 191 |
+
proc = process_images(p)
|
| 192 |
+
if loop==0:
|
| 193 |
+
self.initInfo=proc.info
|
| 194 |
+
self.initSeed=proc.seed
|
| 195 |
+
if len(proc.images)>0:
|
| 196 |
+
history.append(proc.images[0])
|
| 197 |
+
p.seed+=1
|
| 198 |
+
p.init_images=[proc.images[0]]
|
| 199 |
+
#p.denoising_strength=min(max(p.denoising_strength * dns, 0.05), 1)
|
| 200 |
+
p.denoising_strength=initial_denoising_strength+(dns-initial_denoising_strength)*(loop+1)/(loops)
|
| 201 |
+
else:#interrupted
|
| 202 |
+
break
|
| 203 |
+
#print("New denoising:"+str(p.denoising_strength)+"\n" )
|
| 204 |
+
all_images += history
|
| 205 |
+
if loops>0:#TODO:maybe this is not needed
|
| 206 |
+
p.seed=self.initSeed
|
| 207 |
+
#return proc if (loops==1 and p.batch_size==1) else Processed(p, all_images, self.initSeed, self.initInfo)
|
| 208 |
+
return proc if(nSingle) else Processed(p, all_images, self.initSeed, self.initInfo)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def peek(self,val):
|
| 217 |
+
print(val)
|
| 218 |
+
return val
|
| 219 |
+
|
| 220 |
+
def split(self,src,default='0'):
|
| 221 |
+
p=self.p
|
| 222 |
+
self.P=copy.copy({
|
| 223 |
+
'cfg':float(str(p.cfg_scale)),
|
| 224 |
+
'd':p.denoising_strength or 1,
|
| 225 |
+
'l':self.loop,
|
| 226 |
+
'min':min,
|
| 227 |
+
'max':max,
|
| 228 |
+
'abs':abs,
|
| 229 |
+
'pow':pow,
|
| 230 |
+
'pi':math.pi,
|
| 231 |
+
'x':self._interpolate,
|
| 232 |
+
'int':int,
|
| 233 |
+
'floor':math.floor,
|
| 234 |
+
'peek':self.peek,
|
| 235 |
+
})
|
| 236 |
+
|
| 237 |
+
if src[0:4]=="eval":
|
| 238 |
+
src="0:"+src[4:]
|
| 239 |
+
if src[0]=="=":
|
| 240 |
+
src="0:"+src[1:]
|
| 241 |
+
|
| 242 |
+
#clean up
|
| 243 |
+
while src[len(src)-1] in [";"," "]:
|
| 244 |
+
src=src[0:len(src)-1]
|
| 245 |
+
while src[0] in [";"," "]:
|
| 246 |
+
src=src[1:]
|
| 247 |
+
|
| 248 |
+
arr0 = src.split(';')##2
|
| 249 |
+
|
| 250 |
+
#resort array accounting for commas in indecies
|
| 251 |
+
arr=[]
|
| 252 |
+
for j in arr0:
|
| 253 |
+
#print(j)
|
| 254 |
+
v=j.split(":")
|
| 255 |
+
q=v[0].split(",")
|
| 256 |
+
|
| 257 |
+
for i in q:
|
| 258 |
+
arr.append(i+":"+v[1])
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
arr.sort(key=self._sort)
|
| 264 |
+
s=[]
|
| 265 |
+
val=default
|
| 266 |
+
for j in range(p.steps+1):
|
| 267 |
+
i=0
|
| 268 |
+
while i<len(arr) and i<=j:
|
| 269 |
+
v=arr[i].split(":")
|
| 270 |
+
#s=proc[j].n_iter
|
| 271 |
+
if math.floor(int(v[0]) if v[0].isnumeric() else float(v[0])*p.steps)==j:
|
| 272 |
+
val=v[1].strip()
|
| 273 |
+
break
|
| 274 |
+
i=i+1
|
| 275 |
+
|
| 276 |
+
#lets just evaluate all
|
| 277 |
+
if val[0]=="=":
|
| 278 |
+
val=val[1:]
|
| 279 |
+
|
| 280 |
+
_eta=1-j/p.steps
|
| 281 |
+
params={'t':j,'T':p.steps,'math':math,'p':p,'e':float(str(_eta))}
|
| 282 |
+
|
| 283 |
+
params.update(copy.copy(self.P))
|
| 284 |
+
#print(params)
|
| 285 |
+
s.append(float(eval(val,params)))
|
| 286 |
+
#end while loop
|
| 287 |
+
#else:
|
| 288 |
+
#s.append(float(val))
|
| 289 |
+
print(np.round(s,1),"\n")
|
| 290 |
+
return s
|
| 291 |
+
#limits a range of a value
|
| 292 |
+
def _interpolate(self,v,start=0,end=None,m=1):
|
| 293 |
+
end=end or self.p.steps
|
| 294 |
+
v=min(max(v,start),end)-start
|
| 295 |
+
return v*m/(end-start)+(1 if m<0 else 0)
|
| 296 |
+
|
| 297 |
+
def _sort(self,a):
|
| 298 |
+
_=a.split(":")[0]#splitter tester
|
| 299 |
+
return math.floor(int(_) if (_.isnumeric()) else float(_)*self.p.steps)
|
| 300 |
+
|
| 301 |
+
def evaluate (self,src):
|
| 302 |
+
s=[]
|
| 303 |
+
p=self.p
|
| 304 |
+
T=self.p.steps
|
| 305 |
+
for j in range(T+1):
|
| 306 |
+
_eta=1-j/p.steps
|
| 307 |
+
params={'t':j,'T':p.steps,'math':math,'p':p,'e':_eta}
|
| 308 |
+
params.update(self.P)
|
| 309 |
+
s.append(float(eval(src,params)))
|
| 310 |
+
return s
|
| 311 |
+
|
| 312 |
+
class Fake_float(float):
|
| 313 |
+
def __new__(self, value, arr, max_mul_count, steps_per_mul):
|
| 314 |
+
return float.__new__(self, value)
|
| 315 |
+
|
| 316 |
+
def __init__(self, value, arr, max_mul_count, steps_per_mul):
|
| 317 |
+
float.__init__(value)
|
| 318 |
+
self.arr = arr
|
| 319 |
+
self.curstep = 0
|
| 320 |
+
#self.p=p
|
| 321 |
+
|
| 322 |
+
#self.orig_value = orig_value
|
| 323 |
+
#self.target_value = target_value
|
| 324 |
+
self.max_mul_count = max_mul_count
|
| 325 |
+
self.current_mul = 0
|
| 326 |
+
self.steps_per_mul = steps_per_mul
|
| 327 |
+
self.current_step = 0 #fake
|
| 328 |
+
self.max_step_count = (max_mul_count // steps_per_mul) + (max_mul_count % steps_per_mul > 0)
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def __mul__(self,other):
|
| 332 |
+
return self.fake_mul(other)
|
| 333 |
+
|
| 334 |
+
def __rmul__(self,other):
|
| 335 |
+
return self.fake_mul(other)
|
| 336 |
+
|
| 337 |
+
#def __add__(self,other):
|
| 338 |
+
#print("ADD!")
|
| 339 |
+
# return self.get_fake_value(other)+other
|
| 340 |
+
#def __sub__(self,other):
|
| 341 |
+
#print("SUB!")
|
| 342 |
+
# return self.get_fake_value(other)-other
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def fake_mul(self,other):
|
| 347 |
+
#print("MUL!")
|
| 348 |
+
return self.get_fake_value(other) * other
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def get_fake_value(self,other):
|
| 352 |
+
if (self.max_step_count==1):
|
| 353 |
+
fake_value = self.arr[0]
|
| 354 |
+
else:
|
| 355 |
+
|
| 356 |
+
fake_value = self.arr[self.curstep]
|
| 357 |
+
self.current_mul = (self.current_mul+1) % self.max_mul_count
|
| 358 |
+
self.curstep = (self.current_mul) // self.steps_per_mul
|
| 359 |
+
self.current_step+=1#FAKE STEP
|
| 360 |
+
return fake_value
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def fix_ddim_step_count(steps):
|
| 366 |
+
valid_step = 999 / (1000 // steps)
|
| 367 |
+
if valid_step == int(valid_step): steps=int(valid_step)+1
|
| 368 |
+
if ((1000 % steps)!=0): steps +=1
|
| 369 |
+
return steps
|
extensions/CFG-Schedule-for-Automatic1111-SD/scripts/__pycache__/CFG Auto.cpython-310.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
extensions/CFG-Schedule-for-Automatic1111-SD/scripts/__pycache__/CFG Schedule.cpython-310.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
extensions/CFG_Rescale_webui/.gitignore
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# poetry
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 102 |
+
#poetry.lock
|
| 103 |
+
|
| 104 |
+
# pdm
|
| 105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 106 |
+
#pdm.lock
|
| 107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 108 |
+
# in version control.
|
| 109 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 110 |
+
.pdm.toml
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
# PyCharm
|
| 156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
+
#.idea/
|
extensions/CFG_Rescale_webui/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 CartUniverse
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
extensions/CFG_Rescale_webui/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CFG_Rescale_webui
|
| 2 |
+
Adds a CFG rescale option to A1111 webui for vpred models. Implements features described in https://arxiv.org/pdf/2305.08891.pdf
|
| 3 |
+
|
| 4 |
+
When installed, you will see a CFG slider below appear below the seed selection.
|
| 5 |
+
|
| 6 |
+
The recommended settings from the paper is 0.7 CFG rescale. The paper recommends using it at 7.5 CFG, but I find that the default 7.0 CFG works just fine as well.
|
| 7 |
+
If you notice your images are dull or muddy, try setting CFG Rescale to 0.5 and/or turning on color fix.
|
| 8 |
+
|
| 9 |
+
# Extra Features
|
| 10 |
+
Auto color fix: CFG rescale can result in the color palette of the image becoming smaller, resulting in muddy or brown images. Turning this on attempts to return the image colors to full range again, making it appear more vibrant and natural.
|
extensions/CFG_Rescale_webui/scripts/CFGRescale.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import torch
|
| 3 |
+
import re
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
import modules.scripts as scripts
|
| 7 |
+
import modules.images as saving
|
| 8 |
+
from modules import devices, processing, shared, sd_samplers_kdiffusion, sd_samplers_compvis, script_callbacks
|
| 9 |
+
from modules.processing import Processed
|
| 10 |
+
from modules.shared import opts, state
|
| 11 |
+
from ldm.models.diffusion import ddim
|
| 12 |
+
from PIL import Image
|
| 13 |
+
|
| 14 |
+
from ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, noise_like
|
| 15 |
+
|
| 16 |
+
re_prompt_cfgr = re.compile(r"<cfg_rescale:([^>]+)>")
|
| 17 |
+
|
| 18 |
+
class Script(scripts.Script):
|
| 19 |
+
|
| 20 |
+
def __init__(self):
|
| 21 |
+
self.old_denoising = sd_samplers_kdiffusion.CFGDenoiser.combine_denoised
|
| 22 |
+
self.old_schedule = ddim.DDIMSampler.make_schedule
|
| 23 |
+
self.old_sample = ddim.DDIMSampler.p_sample_ddim
|
| 24 |
+
globals()['enable_furry_cocks'] = True
|
| 25 |
+
|
| 26 |
+
def find_module(module_names):
|
| 27 |
+
if isinstance(module_names, str):
|
| 28 |
+
module_names = [s.strip() for s in module_names.split(",")]
|
| 29 |
+
for data in scripts.scripts_data:
|
| 30 |
+
if data.script_class.__module__ in module_names and hasattr(data, "module"):
|
| 31 |
+
return data.module
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
def rescale_opt(p, x, xs):
|
| 35 |
+
globals()['cfg_rescale_fi'] = x
|
| 36 |
+
globals()['enable_furry_cocks'] = False
|
| 37 |
+
|
| 38 |
+
xyz_grid = find_module("xyz_grid.py, xy_grid.py")
|
| 39 |
+
if xyz_grid:
|
| 40 |
+
extra_axis_options = [xyz_grid.AxisOption("Rescale CFG", float, rescale_opt)]
|
| 41 |
+
xyz_grid.axis_options.extend(extra_axis_options)
|
| 42 |
+
|
| 43 |
+
def title(self):
|
| 44 |
+
return "CFG Rescale Extension"
|
| 45 |
+
|
| 46 |
+
def show(self, is_img2img):
|
| 47 |
+
return scripts.AlwaysVisible
|
| 48 |
+
|
| 49 |
+
def ui(self, is_img2img):
|
| 50 |
+
with gr.Accordion("CFG Rescale", open=True, elem_id="cfg_rescale"):
|
| 51 |
+
rescale = gr.Slider(label="CFG Rescale", show_label=False, minimum=0.0, maximum=1.0, step=0.01, value=0.0)
|
| 52 |
+
with gr.Row():
|
| 53 |
+
recolor = gr.Checkbox(label="Auto Color Fix", default=False)
|
| 54 |
+
rec_strength = gr.Slider(label="Fix Strength", interactive=True, visible=False,
|
| 55 |
+
elem_id=self.elem_id("rec_strength"), minimum=0.1, maximum=10.0, step=0.1,
|
| 56 |
+
value=1.0)
|
| 57 |
+
show_original = gr.Checkbox(label="Keep Original Images", elem_id=self.elem_id("show_original"), visible=False, default=False)
|
| 58 |
+
|
| 59 |
+
def show_recolor_strength(rec_checked):
|
| 60 |
+
return [gr.update(visible=rec_checked), gr.update(visible=rec_checked)]
|
| 61 |
+
|
| 62 |
+
recolor.change(
|
| 63 |
+
fn=show_recolor_strength,
|
| 64 |
+
inputs=recolor,
|
| 65 |
+
outputs=[rec_strength, show_original]
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
self.infotext_fields = [
|
| 69 |
+
(rescale, "CFG Rescale"),
|
| 70 |
+
(recolor, "Auto Color Fix")
|
| 71 |
+
]
|
| 72 |
+
self.paste_field_names = []
|
| 73 |
+
for _, field_name in self.infotext_fields:
|
| 74 |
+
self.paste_field_names.append(field_name)
|
| 75 |
+
return [rescale, recolor, rec_strength, show_original]
|
| 76 |
+
|
| 77 |
+
def cfg_replace(self, x_out, conds_list, uncond, cond_scale):
|
| 78 |
+
denoised_uncond = x_out[-uncond.shape[0]:]
|
| 79 |
+
denoised = torch.clone(denoised_uncond)
|
| 80 |
+
fi = globals()['cfg_rescale_fi']
|
| 81 |
+
|
| 82 |
+
for i, conds in enumerate(conds_list):
|
| 83 |
+
for cond_index, weight in conds:
|
| 84 |
+
if fi == 0:
|
| 85 |
+
denoised[i] += (x_out[cond_index] - denoised_uncond[i]) * (weight * cond_scale)
|
| 86 |
+
else:
|
| 87 |
+
xcfg = (denoised_uncond[i] + (x_out[cond_index] - denoised_uncond[i]) * (cond_scale * weight))
|
| 88 |
+
xrescaled = (torch.std(x_out[cond_index]) / torch.std(xcfg))
|
| 89 |
+
xfinal = fi * xrescaled + (1.0 - fi)
|
| 90 |
+
denoised[i] = xfinal * xcfg
|
| 91 |
+
|
| 92 |
+
return denoised
|
| 93 |
+
|
| 94 |
+
def process(self, p, rescale, recolor, rec_strength, show_original):
|
| 95 |
+
|
| 96 |
+
if globals()['enable_furry_cocks']:
|
| 97 |
+
# parse <cfg_rescale:[number]> from prompt for override
|
| 98 |
+
rescale_override = None
|
| 99 |
+
def found(m):
|
| 100 |
+
nonlocal rescale_override
|
| 101 |
+
try:
|
| 102 |
+
rescale_override = float(m.group(1))
|
| 103 |
+
except ValueError:
|
| 104 |
+
rescale_override = None
|
| 105 |
+
return ""
|
| 106 |
+
p.prompt = re.sub(re_prompt_cfgr, found, p.prompt)
|
| 107 |
+
if rescale_override is not None:
|
| 108 |
+
rescale = rescale_override
|
| 109 |
+
|
| 110 |
+
globals()['cfg_rescale_fi'] = rescale
|
| 111 |
+
else:
|
| 112 |
+
# rescale value is being set from xyz_grid
|
| 113 |
+
rescale = globals()['cfg_rescale_fi']
|
| 114 |
+
globals()['enable_furry_cocks'] = True
|
| 115 |
+
|
| 116 |
+
sd_samplers_kdiffusion.CFGDenoiser.combine_denoised = self.cfg_replace
|
| 117 |
+
|
| 118 |
+
if rescale > 0:
|
| 119 |
+
p.extra_generation_params["CFG Rescale"] = rescale
|
| 120 |
+
|
| 121 |
+
if recolor:
|
| 122 |
+
p.extra_generation_params["Auto Color Fix Strength"] = rec_strength
|
| 123 |
+
p.do_not_save_samples = True
|
| 124 |
+
|
| 125 |
+
def postprocess_batch_list(self, p, pp, rescale, recolor, rec_strength, show_original, batch_number):
|
| 126 |
+
if recolor and show_original:
|
| 127 |
+
num = len(pp.images)
|
| 128 |
+
for i in range(num):
|
| 129 |
+
pp.images.append(pp.images[i])
|
| 130 |
+
p.prompts.append(p.prompts[i])
|
| 131 |
+
p.negative_prompts.append(p.negative_prompts[i])
|
| 132 |
+
p.seeds.append(p.seeds[i])
|
| 133 |
+
p.subseeds.append(p.subseeds[i])
|
| 134 |
+
|
| 135 |
+
def postprocess(self, p, processed, rescale, recolor, rec_strength, show_original):
|
| 136 |
+
sd_samplers_kdiffusion.CFGDenoiser.combine_denoised = self.old_denoising
|
| 137 |
+
|
| 138 |
+
def postfix(img, rec_strength):
|
| 139 |
+
prec = 0.0005 * rec_strength
|
| 140 |
+
r, g, b = img.split()
|
| 141 |
+
|
| 142 |
+
# softer effect
|
| 143 |
+
# r_min, r_max = np.percentile(r, p), np.percentile(r, 100.0 - p)
|
| 144 |
+
# g_min, g_max = np.percentile(g, p), np.percentile(g, 100.0 - p)
|
| 145 |
+
# b_min, b_max = np.percentile(b, p), np.percentile(b, 100.0 - p)
|
| 146 |
+
|
| 147 |
+
rh, rbins = np.histogram(r, 256, (0, 256))
|
| 148 |
+
tmp = np.where(rh > rh.sum() * prec)[0]
|
| 149 |
+
r_min = tmp.min()
|
| 150 |
+
r_max = tmp.max()
|
| 151 |
+
|
| 152 |
+
gh, gbins = np.histogram(g, 256, (0, 256))
|
| 153 |
+
tmp = np.where(gh > gh.sum() * prec)[0]
|
| 154 |
+
g_min = tmp.min()
|
| 155 |
+
g_max = tmp.max()
|
| 156 |
+
|
| 157 |
+
bh, bbins = np.histogram(b, 256, (0, 256))
|
| 158 |
+
tmp = np.where(bh > bh.sum() * prec)[0]
|
| 159 |
+
b_min = tmp.min()
|
| 160 |
+
b_max = tmp.max()
|
| 161 |
+
|
| 162 |
+
r = r.point(lambda i: int(255 * (min(max(i, r_min), r_max) - r_min) / (r_max - r_min)))
|
| 163 |
+
g = g.point(lambda i: int(255 * (min(max(i, g_min), g_max) - g_min) / (g_max - g_min)))
|
| 164 |
+
b = b.point(lambda i: int(255 * (min(max(i, b_min), b_max) - b_min) / (b_max - b_min)))
|
| 165 |
+
|
| 166 |
+
new_img = Image.merge("RGB", (r, g, b))
|
| 167 |
+
|
| 168 |
+
return new_img
|
| 169 |
+
|
| 170 |
+
if recolor:
|
| 171 |
+
grab = 0
|
| 172 |
+
n_img = len(processed.images)
|
| 173 |
+
for i in range(n_img):
|
| 174 |
+
doit = False
|
| 175 |
+
|
| 176 |
+
if show_original:
|
| 177 |
+
check = i
|
| 178 |
+
if opts.return_grid:
|
| 179 |
+
if i == 0:
|
| 180 |
+
continue
|
| 181 |
+
else:
|
| 182 |
+
check = check - 1
|
| 183 |
+
doit = check % (p.batch_size * 2) >= p.batch_size
|
| 184 |
+
else:
|
| 185 |
+
if n_img > 1 and i != 0:
|
| 186 |
+
doit = True
|
| 187 |
+
elif n_img == 1 or not opts.return_grid:
|
| 188 |
+
doit = True
|
| 189 |
+
|
| 190 |
+
if doit:
|
| 191 |
+
res_img = postfix(processed.images[i], rec_strength)
|
| 192 |
+
if opts.samples_save:
|
| 193 |
+
ind = grab
|
| 194 |
+
grab += 1
|
| 195 |
+
prompt_infotext = processing.create_infotext(p, p.all_prompts, p.all_seeds, p.all_subseeds,
|
| 196 |
+
index=ind)
|
| 197 |
+
# Save images to disk
|
| 198 |
+
if opts.samples_save:
|
| 199 |
+
saving.save_image(processed.images[i], p.outpath_samples, "", seed=p.all_seeds[ind],
|
| 200 |
+
prompt=p.all_prompts[ind],
|
| 201 |
+
info=prompt_infotext, p=p, suffix="colorfix")
|
| 202 |
+
saving.save_image(res_img, p.outpath_samples, "", seed=p.all_seeds[ind],
|
| 203 |
+
prompt=p.all_prompts[ind],
|
| 204 |
+
info=prompt_infotext, p=p, suffix="colorfix")
|
| 205 |
+
|
| 206 |
+
processed.images[i] = res_img
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def on_infotext_pasted(infotext, params):
|
| 210 |
+
if "CFG Rescale" not in params:
|
| 211 |
+
params["CFG Rescale"] = 0
|
| 212 |
+
|
| 213 |
+
if "CFG Rescale φ" in params:
|
| 214 |
+
params["CFG Rescale"] = params["CFG Rescale φ"]
|
| 215 |
+
del params["CFG Rescale φ"]
|
| 216 |
+
|
| 217 |
+
if "CFG Rescale phi" in params and scripts.scripts_txt2img.script("Neutral Prompt") is None:
|
| 218 |
+
params["CFG Rescale"] = params["CFG Rescale phi"]
|
| 219 |
+
del params["CFG Rescale phi"]
|
| 220 |
+
|
| 221 |
+
if "DDIM Trailing" not in params:
|
| 222 |
+
params["DDIM Trailing"] = False
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
script_callbacks.on_infotext_pasted(on_infotext_pasted)
|
extensions/CFG_Rescale_webui/scripts/__pycache__/CFGRescale.cpython-310.pyc
ADDED
|
Binary file (7.39 kB). View file
|
|
|
extensions/DeepShrinkHires.fix/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
| 2 |
+
settings.json
|
extensions/DeepShrinkHires.fix/scripts/DeepShrinkHires.fix.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
import modules.devices as devices
|
| 5 |
+
import modules.scripts as scripts
|
| 6 |
+
import modules.script_callbacks as script_callbacks
|
| 7 |
+
import modules.sd_unet as sd_unet
|
| 8 |
+
import modules.shared as shared
|
| 9 |
+
|
| 10 |
+
from ldm.modules.diffusionmodules.util import timestep_embedding as timestep_embedding
|
| 11 |
+
|
| 12 |
+
class DeepShrinkHiresFixAction():
|
| 13 |
+
def __init__(self, enable: bool, timestep: float, depth: int, scale: float):
|
| 14 |
+
self.enable = enable
|
| 15 |
+
self.timestep = timestep
|
| 16 |
+
self.depth = depth
|
| 17 |
+
self.scale = scale
|
| 18 |
+
pass
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
class DeepShrinkHiresFix(scripts.Script):
|
| 22 |
+
deepShrinkHiresFixActions: list[DeepShrinkHiresFixAction] = []
|
| 23 |
+
enableExperimental: bool = False
|
| 24 |
+
experimentalTimestep: float = 900
|
| 25 |
+
experimentalScales: list[float] = []
|
| 26 |
+
|
| 27 |
+
def __init__(self):
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
def title(self):
|
| 31 |
+
return "Deep Shrink Hires.fix"
|
| 32 |
+
pass
|
| 33 |
+
|
| 34 |
+
def show(self, is_img2img):
|
| 35 |
+
return scripts.AlwaysVisible
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
def ui(self, is_img2img):
|
| 39 |
+
with gradio.Accordion(label="Deep Shrink Hires.fix", open=False):
|
| 40 |
+
with gradio.Row():
|
| 41 |
+
Enable_1 = gradio.Checkbox(value=True, label="Enable 1")
|
| 42 |
+
Timestep_1 = gradio.Number(value=900, label="Timestep 1")
|
| 43 |
+
Depth_1 = gradio.Number(value=3, label="Block Depth 1", precision=0)
|
| 44 |
+
Scale_1 = gradio.Number(value=2, label="Scale factor 1")
|
| 45 |
+
pass
|
| 46 |
+
with gradio.Row():
|
| 47 |
+
Enable_2 = gradio.Checkbox(value=True, label="Enable 2")
|
| 48 |
+
Timestep_2 = gradio.Number(value=650, label="Timestep 2")
|
| 49 |
+
Depth_2 = gradio.Number(value=3, label="Block Depth 2", precision=0)
|
| 50 |
+
Scale_2 = gradio.Number(value=2, label="Scale factor 2")
|
| 51 |
+
pass
|
| 52 |
+
with gradio.Accordion(label="Advanced Settings", open=False):
|
| 53 |
+
with gradio.Row():
|
| 54 |
+
Enable_3 = gradio.Checkbox(value=False, label="Enable 3")
|
| 55 |
+
Timestep_3 = gradio.Number(value=900, label="Timestep 3")
|
| 56 |
+
Depth_3 = gradio.Number(value=3, label="Block Depth 3", precision=0)
|
| 57 |
+
Scale_3 = gradio.Number(value=2, label="Scale factor 3")
|
| 58 |
+
pass
|
| 59 |
+
with gradio.Row():
|
| 60 |
+
Enable_4 = gradio.Checkbox(value=False, label="Enable 4")
|
| 61 |
+
Timestep_4 = gradio.Number(value=650, label="Timestep 4")
|
| 62 |
+
Depth_4 = gradio.Number(value=3, label="Block Depth 4", precision=0)
|
| 63 |
+
Scale_4 = gradio.Number(value=2, label="Scale factor 4")
|
| 64 |
+
pass
|
| 65 |
+
with gradio.Row():
|
| 66 |
+
Enable_5 = gradio.Checkbox(value=False, label="Enable 5")
|
| 67 |
+
Timestep_5 = gradio.Number(value=900, label="Timestep 5")
|
| 68 |
+
Depth_5 = gradio.Number(value=3, label="Block Depth 5", precision=0)
|
| 69 |
+
Scale_5 = gradio.Number(value=2, label="Scale factor 5")
|
| 70 |
+
pass
|
| 71 |
+
with gradio.Row():
|
| 72 |
+
Enable_6 = gradio.Checkbox(value=False, label="Enable 6")
|
| 73 |
+
Timestep_6 = gradio.Number(value=650, label="Timestep 6")
|
| 74 |
+
Depth_6 = gradio.Number(value=3, label="Block Depth 6", precision=0)
|
| 75 |
+
Scale_6 = gradio.Number(value=2, label="Scale factor 6")
|
| 76 |
+
pass
|
| 77 |
+
with gradio.Row():
|
| 78 |
+
Enable_7 = gradio.Checkbox(value=False, label="Enable 7")
|
| 79 |
+
Timestep_7 = gradio.Number(value=900, label="Timestep 7")
|
| 80 |
+
Depth_7 = gradio.Number(value=3, label="Block Depth 7", precision=0)
|
| 81 |
+
Scale_7 = gradio.Number(value=2, label="Scale factor 7")
|
| 82 |
+
pass
|
| 83 |
+
with gradio.Row():
|
| 84 |
+
Enable_8 = gradio.Checkbox(value=False, label="Enable 8")
|
| 85 |
+
Timestep_8 = gradio.Number(value=650, label="Timestep 8")
|
| 86 |
+
Depth_8 = gradio.Number(value=3, label="Block Depth 8", precision=0)
|
| 87 |
+
Scale_8 = gradio.Number(value=2, label="Scale factor 8")
|
| 88 |
+
pass
|
| 89 |
+
pass
|
| 90 |
+
with gradio.Accordion(label="Experimental Settings", open=False):
|
| 91 |
+
with gradio.Row():
|
| 92 |
+
Enable_Experimental = gradio.Checkbox(value=False, label="Enable Experimental Mode")
|
| 93 |
+
Timestep_Experimental = gradio.Number(value=900, label="Timestep")
|
| 94 |
+
Scale_Experimental = gradio.Textbox(value="1,1,1, 1,1,1, 1,1,1, 1,1,1, 2, 1,1,1, 1,1,1, 1,1,1, 1,1,1", label="Scale Factor List")
|
| 95 |
+
pass
|
| 96 |
+
pass
|
| 97 |
+
pass
|
| 98 |
+
return [Enable_1, Timestep_1, Depth_1, Scale_1, Enable_2, Timestep_2, Depth_2, Scale_2, Enable_3, Timestep_3, Depth_3, Scale_3, Enable_4, Timestep_4, Depth_4, Scale_4,
|
| 99 |
+
Enable_5, Timestep_5, Depth_5, Scale_5, Enable_6, Timestep_6, Depth_6, Scale_6, Enable_7, Timestep_7, Depth_7, Scale_7, Enable_8, Timestep_8, Depth_8, Scale_8,
|
| 100 |
+
Enable_Experimental, Timestep_Experimental, Scale_Experimental]
|
| 101 |
+
pass
|
| 102 |
+
|
| 103 |
+
def process(self, p, *args):
|
| 104 |
+
del DeepShrinkHiresFix.deepShrinkHiresFixActions[:]
|
| 105 |
+
for i in range(8):
|
| 106 |
+
DeepShrinkHiresFix.deepShrinkHiresFixActions.append(DeepShrinkHiresFixAction(args[i*4], args[i*4+1], args[i*4+2], args[i*4+3]))
|
| 107 |
+
pass
|
| 108 |
+
del DeepShrinkHiresFix.experimentalScales[:]
|
| 109 |
+
DeepShrinkHiresFix.enableExperimental = args[8*4]
|
| 110 |
+
DeepShrinkHiresFix.experimentalTimestep = args[8*4+1]
|
| 111 |
+
scaleFactorsTexts: str = args[8*4+2]
|
| 112 |
+
scaleFactorsTextsList = scaleFactorsTexts.split(",")
|
| 113 |
+
for scaleFactorsText in scaleFactorsTextsList:
|
| 114 |
+
DeepShrinkHiresFix.experimentalScales.append(float(scaleFactorsText))
|
| 115 |
+
pass
|
| 116 |
+
pass
|
| 117 |
+
|
| 118 |
+
class DeepShrinkHiresFixUNet(sd_unet.SdUnet):
|
| 119 |
+
def __init__(self, _model):
|
| 120 |
+
super().__init__()
|
| 121 |
+
self.model = _model.to(devices.device)
|
| 122 |
+
pass
|
| 123 |
+
def forward(self, x, timesteps, context, y=None, **kwargs):
|
| 124 |
+
assert (y is not None) == (
|
| 125 |
+
self.model.num_classes is not None
|
| 126 |
+
), "must specify y if and only if the model is class-conditional"
|
| 127 |
+
hs = []
|
| 128 |
+
ss = []
|
| 129 |
+
t_emb = timestep_embedding(timesteps, self.model.model_channels, repeat_only=False)
|
| 130 |
+
emb = self.model.time_embed(t_emb)
|
| 131 |
+
|
| 132 |
+
if self.model.num_classes is not None:
|
| 133 |
+
assert y.shape[0] == x.shape[0]
|
| 134 |
+
emb = emb + self.model.label_emb(y)
|
| 135 |
+
|
| 136 |
+
h = x.type(self.model.dtype)
|
| 137 |
+
depth = 0
|
| 138 |
+
block = 0
|
| 139 |
+
scale = 1
|
| 140 |
+
for module in self.model.input_blocks:
|
| 141 |
+
for action in DeepShrinkHiresFix.deepShrinkHiresFixActions:
|
| 142 |
+
if action.enable == True and action.depth == depth and action.timestep < timesteps[0]:
|
| 143 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=1/action.scale, mode="bicubic", align_corners=False).to(h.dtype)
|
| 144 |
+
break
|
| 145 |
+
pass
|
| 146 |
+
pass
|
| 147 |
+
if DeepShrinkHiresFix.enableExperimental and timesteps[0] >= DeepShrinkHiresFix.experimentalTimestep:
|
| 148 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=scale/DeepShrinkHiresFix.experimentalScales[block], mode="bicubic", align_corners=False).to(h.dtype)
|
| 149 |
+
scale = DeepShrinkHiresFix.experimentalScales[block]
|
| 150 |
+
ss.append(scale)
|
| 151 |
+
pass
|
| 152 |
+
h = module(h, emb, context)
|
| 153 |
+
hs.append(h)
|
| 154 |
+
depth += 1
|
| 155 |
+
block += 1
|
| 156 |
+
pass
|
| 157 |
+
|
| 158 |
+
for action in DeepShrinkHiresFix.deepShrinkHiresFixActions:
|
| 159 |
+
if action.enable == True and action.depth == depth and action.timestep < timesteps[0]:
|
| 160 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=1/action.scale, mode="bicubic", align_corners=False).to(h.dtype)
|
| 161 |
+
break
|
| 162 |
+
pass
|
| 163 |
+
pass
|
| 164 |
+
if DeepShrinkHiresFix.enableExperimental and timesteps[0] >= DeepShrinkHiresFix.experimentalTimestep:
|
| 165 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=scale/DeepShrinkHiresFix.experimentalScales[block], mode="bicubic", align_corners=False).to(h.dtype)
|
| 166 |
+
scale = DeepShrinkHiresFix.experimentalScales[block]
|
| 167 |
+
pass
|
| 168 |
+
|
| 169 |
+
h = self.model.middle_block(h, emb, context)
|
| 170 |
+
|
| 171 |
+
for action in DeepShrinkHiresFix.deepShrinkHiresFixActions:
|
| 172 |
+
if action.enable == True and action.depth == depth and action.timestep < timesteps[0]:
|
| 173 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=action.scale, mode="bicubic", align_corners=False).to(h.dtype)
|
| 174 |
+
break
|
| 175 |
+
pass
|
| 176 |
+
pass
|
| 177 |
+
block += 1
|
| 178 |
+
|
| 179 |
+
for module in self.model.output_blocks:
|
| 180 |
+
depth -= 1
|
| 181 |
+
if DeepShrinkHiresFix.enableExperimental and timesteps[0] >= DeepShrinkHiresFix.experimentalTimestep:
|
| 182 |
+
h = torch.cat([torch.nn.functional.interpolate(h.float(), scale_factor=scale/DeepShrinkHiresFix.experimentalScales[block], mode="bicubic", align_corners=False).to(h.dtype),
|
| 183 |
+
torch.nn.functional.interpolate(hs.pop().float(), scale_factor=ss.pop()/DeepShrinkHiresFix.experimentalScales[block], mode="bicubic", align_corners=False).to(h.dtype)], dim=1)
|
| 184 |
+
scale = DeepShrinkHiresFix.experimentalScales[block]
|
| 185 |
+
pass
|
| 186 |
+
else:
|
| 187 |
+
h = torch.cat([h, hs.pop()], dim=1)
|
| 188 |
+
pass
|
| 189 |
+
h = module(h, emb, context)
|
| 190 |
+
for action in DeepShrinkHiresFix.deepShrinkHiresFixActions:
|
| 191 |
+
if action.enable == True and action.depth == depth and action.timestep < timesteps[0]:
|
| 192 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=action.scale, mode="bicubic", align_corners=False).to(h.dtype)
|
| 193 |
+
break
|
| 194 |
+
pass
|
| 195 |
+
pass
|
| 196 |
+
block += 1
|
| 197 |
+
pass
|
| 198 |
+
if DeepShrinkHiresFix.enableExperimental and timesteps[0] >= DeepShrinkHiresFix.experimentalTimestep:
|
| 199 |
+
h = torch.nn.functional.interpolate(h.float(), scale_factor=scale, mode="bicubic", align_corners=False).to(h.dtype)
|
| 200 |
+
pass
|
| 201 |
+
h = h.type(x.dtype)
|
| 202 |
+
if self.model.predict_codebook_ids:
|
| 203 |
+
return self.model.id_predictor(h)
|
| 204 |
+
else:
|
| 205 |
+
return self.model.out(h)
|
| 206 |
+
pass
|
| 207 |
+
pass
|
| 208 |
+
|
| 209 |
+
DeepShrinkHiresFixUNetOption = sd_unet.SdUnetOption()
|
| 210 |
+
DeepShrinkHiresFixUNetOption.label = "Deep Shrink Hires.fix"
|
| 211 |
+
DeepShrinkHiresFixUNetOption.create_unet = lambda: DeepShrinkHiresFix.DeepShrinkHiresFixUNet(shared.sd_model.model.diffusion_model)
|
| 212 |
+
|
| 213 |
+
pass
|
| 214 |
+
|
| 215 |
+
script_callbacks.on_list_unets(lambda unets: unets.append(DeepShrinkHiresFix.DeepShrinkHiresFixUNetOption))
|
extensions/DeepShrinkHires.fix/scripts/__pycache__/DeepShrinkHires.fix.cpython-310.pyc
ADDED
|
Binary file (7.57 kB). View file
|
|
|
extensions/Euler-Smea-Dyn-Sampler/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
extensions/Euler-Smea-Dyn-Sampler/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2024 KBlueLeaf
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
extensions/Euler-Smea-Dyn-Sampler/README.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
| Catalog |
|
| 2 |
+
| ---- |
|
| 3 |
+
| [2024.05.09 Add Euler Negative And Euler dy Negtive 添加两个新采样器](#section1) |
|
| 4 |
+
| [2024.04.24](#section2) |
|
| 5 |
+
| [2024.04.18 Stage Technical Report 阶段性技术报告](#section3) |
|
| 6 |
+
| [2024.04.15 Compatible with Stable Cascade Models 适配Sc模型](#section4) |
|
| 7 |
+
| [2024.04.13 Fix Bug In ComfyUI 修复ComfyUI中的Bug](#section5) |
|
| 8 |
+
| [2024.04.11 Important! This repo can be use as a extension! 重大!现在此仓库可作为插件使用](#section6) |
|
| 9 |
+
| [2024.04.10](#section7) |
|
| 10 |
+
| [2024.04.09](#section8) |
|
| 11 |
+
| [Euler Smea Dyn Sampler](#section9) |
|
| 12 |
+
| [Effect 效果](#section10) |
|
| 13 |
+
| [how to use(This has become outdated, but it will be retained) 如何使用(已经过期,依然保留,仅做参考)](#section11) |
|
| 14 |
+
| [The technical principles 技术报告](#section12) |
|
| 15 |
+
| [Contact the author 联系作者](#section13) |
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
<a id="section1"></a>
|
| 19 |
+
## 2024.05.09 Add Euler Negative And Euler dy Negtive
|
| 20 |
+
|
| 21 |
+
新增两个采样器,Euler Negative 和 Euler dy Negtive。我不会说它们效果比别的好,因为没有理论依据。不过在实践中我很喜欢它们。
|
| 22 |
+
|
| 23 |
+
在SDXL表现更好一些,但在SD1.5使用效果也不差
|
| 24 |
+
|
| 25 |
+
我得去稍微进修一下关于AI的知识,目前这种纯粹依靠灵感和实践的方案过于自由。
|
| 26 |
+
|
| 27 |
+
以下是关于它们的测试:
|
| 28 |
+
|
| 29 |
+
Two new samplers have been added, Euler Negative and Euler dy Negative. I won't claim they perform better than others because there's no theoretical basis for it. However, in practice, I quite like them.
|
| 30 |
+
|
| 31 |
+
They perform slightly better in SDXL, but their performance in SD1.5 is also decent.
|
| 32 |
+
|
| 33 |
+
I need to brush up on my professional knowledge of AI. Currently, relying solely on intuition and practice feels too unrestricted.
|
| 34 |
+
|
| 35 |
+
Below are the test results for them:
|
| 36 |
+
|
| 37 |
+
**768x768, model meinaMixV11**
|
| 38 |
+

|
| 39 |
+
|
| 40 |
+
**832x1216,model kohaku-xl-epsilon**
|
| 41 |
+

|
| 42 |
+

|
| 43 |
+

|
| 44 |
+
|
| 45 |
+
**832x1216,model animegineV30**
|
| 46 |
+

|
| 47 |
+
|
| 48 |
+
**Please Note**
|
| 49 |
+
|
| 50 |
+
目前插件有一些小bug,会使得人物在画面中的占比变小,就像这样:
|
| 51 |
+
|
| 52 |
+
The current plugin has a few minor bugs that cause the characters to shrink in the frame, like this:
|
| 53 |
+
|
| 54 |
+

|
| 55 |
+

|
| 56 |
+
|
| 57 |
+
所以你可以采用其他方案,例如修改源码的方案去添加这两个采样器,请参考:[How to use](#section11)
|
| 58 |
+
|
| 59 |
+
So, you can consider alternative solutions, such as modifying the source code to add these two samplers. Please refer to:[How to use](#section11)
|
| 60 |
+
|
| 61 |
+
<a id="section2"></a>
|
| 62 |
+
## 2024.04.24
|
| 63 |
+
|
| 64 |
+
简单分析Dy Step的原理
|
| 65 |
+
|
| 66 |
+
最近我尝试在https://civitai.com/models/399873/kohaku-xl-epsilon上测试了Euler Dy,效果不尽人意(但在ang3以及pony系列效果不错)。因此我咨询了作者,得到的回复是“模型没有使用任何低分辨率的图片进行训练”。我想这就是原因所在,Euler Dy将图片放在一个小的尺度上,让去噪工作来到模型的舒适区,并给予一个参考。尤其在SD1.5,Euler Dy确保图像始终处于模型的舒适区域。
|
| 67 |
+
|
| 68 |
+
而在本次的SDXL模型中,它几乎遗忘了如何在小尺度上生成图片。所以,Dy Step的改进方向已经变得很明显:寻找到SDXL模型的舒适区域,并让采样器在SDXL的舒适区工作。
|
| 69 |
+
|
| 70 |
+
同时我也写了几个其他��采样器,效果平平,达不到Dy Step的效果。如果有人想试试它们,请在评论区留言。
|
| 71 |
+
|
| 72 |
+
Recently, I attempted to analyze the principle of Dy Step on https://civitai.com/models/399873/kohaku-xl-epsilon using Euler Dy. The results were unsatisfactory (although they performed well on ang3 and pony series). Therefore, I consulted the author and received the response that "the model did not use any low-resolution images for training." I believe this is the reason why. Euler Dy places images on a small scale, allowing denoising to operate within the model's comfort zone and providing a reference. Especially in SD1.5, Euler Dy ensures that the image always remains within the model's comfort zone.
|
| 73 |
+
|
| 74 |
+
However, in the current SDXL model, it has almost forgotten how to generate images on a small scale. Therefore, the direction for improving Dy Step has become apparent: to find the comfort zone of the SDXL model and enable the sampler to work within the comfort zone of SDXL.
|
| 75 |
+
|
| 76 |
+
I've also written a few other samplers, but their performance is mediocre and doesn't match up to Dy Step's effectiveness. If anyone wants to try them out, please leave a comment in the discussions.
|
| 77 |
+
|
| 78 |
+
<a id="section3"></a>
|
| 79 |
+
## 2024.04.18 Stage Technical Report
|
| 80 |
+
|
| 81 |
+
阶段性技术报告报告。
|
| 82 |
+
|
| 83 |
+
这些日子里,我尝试了超过二十种策略,但采样器的质量总是优于euler a却差于euler dy,所以暂时还不能发布euler dy a。我必须承认这和nai3的dyn是不同的东西。我依旧会长期维护这个项目,并为了新的采样方法努力,同时尽可能降低ai的算力需求。
|
| 84 |
+
|
| 85 |
+
Stage Technical Report
|
| 86 |
+
|
| 87 |
+
In these days, I have attempted over twenty strategies, but the quality of the sampler is always better than Euler A yet worse than Euler DY. Therefore, I cannot release Euler DY A for the time being. I must acknowledge that this is different from NAI3's DYN. I will continue to maintain this project in the long term and work towards developing new sampling methods while trying to minimize the AI's computing power requirements as much as possible.
|
| 88 |
+
|
| 89 |
+

|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
<a id="section4"></a>
|
| 93 |
+
## 2024.04.15 Compatible with Stable Cascade Models
|
| 94 |
+
|
| 95 |
+
Makes dy_step respect original channel count, making it compatible with Stable Cascade models.
|
| 96 |
+
|
| 97 |
+
使dy_step遵循原本的通道数,使其与Stable Cascade模型相适应。
|
| 98 |
+
|
| 99 |
+
<a id="section5"></a>
|
| 100 |
+
## 2024.04.13 Fix Bug In ComfyUI
|
| 101 |
+
|
| 102 |
+
Change code for ComfyUI import. This will fix the overwrite error that occurs in ComfyUI when other extensions use `scripts` as the import folder (I really hope ComfyUI will standardize its interfaces and version dependencies).
|
| 103 |
+
|
| 104 |
+
P.S.You may find some commits with no means, that because I am not familiar with Github, and try times. So don't care.
|
| 105 |
+
|
| 106 |
+
更改代码,用于ComfyUI导入。这将修复在ComfyUI中存在其他插件时,若其他插件将`scripts`作为导入文件夹时引起的覆盖错误。(真希望ComfyUI能规范一下它的接口和版本依赖)。
|
| 107 |
+
|
| 108 |
+
P.S.你可能会发现一些无意义的提交,这是因为我不熟悉Github的使用,并且尝试了几次。别在意。
|
| 109 |
+
|
| 110 |
+
<a id="section6"></a>
|
| 111 |
+
## 2024.04.11 Important! This repo can be use as a extension!
|
| 112 |
+
|
| 113 |
+
Thanks for @pamparamm, his selfless work has been a great help.
|
| 114 |
+
|
| 115 |
+
Now this sampler can be use as a extension for **ComfyUI** and **WebUI from Automatic1111**.
|
| 116 |
+
|
| 117 |
+
The inpainting bug will be fixed.(**At least doesn't throw any exceptions.**)
|
| 118 |
+
|
| 119 |
+
Thanks again.
|
| 120 |
+
|
| 121 |
+
Another extension from @licyk , in repo: https://github.com/licyk/advanced_euler_sampler_extension **suitable for 1.8 version**
|
| 122 |
+
|
| 123 |
+
It's also useful, and thanks hard efforts from licky, too.
|
| 124 |
+
|
| 125 |
+
In the future, I will work on making dy step compatible with more samplers (such as the DPM series).
|
| 126 |
+
|
| 127 |
+
感谢 @pamparamm,他的无私工作帮助很大。
|
| 128 |
+
|
| 129 |
+
现在,这个采样器可以作为 **ComfyUI** 和 **Automatic1111 的 WebUI** 的扩展来使用。
|
| 130 |
+
|
| 131 |
+
修复了inpainting的bug。(**至少不再抛出异常。**)
|
| 132 |
+
|
| 133 |
+
再次感谢。
|
| 134 |
+
|
| 135 |
+
另一个拓展来自@licyk,位于: https://github.com/licyk/advanced_euler_sampler_extension **适用于1.8**
|
| 136 |
+
|
| 137 |
+
也同样很好用, 同样感谢licyk的辛勤努力。
|
| 138 |
+
|
| 139 |
+
之后我会想办法让dy step适配更多采样器(例如dpm系列)。
|
| 140 |
+
|
| 141 |
+
<a id="section7"></a>
|
| 142 |
+
## 2024.04.10
|
| 143 |
+
|
| 144 |
+

|
| 145 |
+
|
| 146 |
+
Find a way to avoid errors during inpaint and extensions.
|
| 147 |
+
|
| 148 |
+
**Please note that this is just a temporary solution and doesn't actually resolve the issue.It will try to use Euler method if error occurs.**
|
| 149 |
+
|
| 150 |
+
P.S.I trying to fix it……but all methods seems doesn't work.I've working for it over 36 hours.
|
| 151 |
+
|
| 152 |
+
**Suggestions from anyone are welcome**.
|
| 153 |
+
|
| 154 |
+
I need to take a short break and prepare for my other project.*<== A mobile phone app base on flutter, using for TRPG.(No worries, I don't mean I will give up this project,also not about diverting traffic either. LOL.)*
|
| 155 |
+
|
| 156 |
+
想了个办法避免在局部重绘以及拓展中的报错。
|
| 157 |
+
|
| 158 |
+
**请注意,这只是一个临时解决方案,实际上并没有解决问题。如果出现错误,它将尝试使用欧拉方法。**
|
| 159 |
+
|
| 160 |
+
我努力尝试修复……但所有方案都不起作用。我已经连续工作了36小时以上。**欢迎任何人提出建议。**
|
| 161 |
+
,
|
| 162 |
+
我需要稍微休息一下,并且为我的其他项目做准备。*<== 一个基于Flutter的手机应用,用于TRPG。(别担心,我不是说我要放弃这个项目,也不是引流。)*
|
| 163 |
+
|
| 164 |
+
<a id="section8"></a>
|
| 165 |
+
## 2024.04.09
|
| 166 |
+
|
| 167 |
+
Add `__init__.py` for ComfyUI. Thanks for CapsAdmin. I don't use ComfyUI so I can't tell you how to add it, sorry.
|
| 168 |
+
|
| 169 |
+
为ComfyUI增加`__init__.py` 感谢CapsAdmin 我不用ComfyUI所以我没法告诉你怎么添加它,抱歉
|
| 170 |
+
|
| 171 |
+
<a id="section9"></a>
|
| 172 |
+
## Euler Smea Dyn Sampler
|
| 173 |
+
|
| 174 |
+
A sampling method based on Euler's approach, designed to generate superior imagery.
|
| 175 |
+
|
| 176 |
+
The SMEA sampler can significantly mitigate the structural and limb collapse that occurs when generating large images, and to a great extent, it can produce superior hand depictions (not perfect, but better than existing sampling methods).
|
| 177 |
+
|
| 178 |
+
The SMEA sampler is designed to accommodate the majority of image sizes, with particularly outstanding performance on larger images. It also supports the generation of images in unconventional sizes that lack sufficient training data (for example, running 512x512 in SDXL, 823x1216 in SD1.5, as well as 640x960, etc.).
|
| 179 |
+
|
| 180 |
+
The SMEA sampler performs very well in SD1.5, but the effects are not as pronounced in SDXL.
|
| 181 |
+
|
| 182 |
+
In terms of computational resource consumption, the Euler dy is approximately equivalent to the Euler a, while the Euler SMEA Dy sampler will consume more computational resources, approximately 1.25 times more.
|
| 183 |
+
|
| 184 |
+
一种基于Euler的采样方法,旨在生成更好的图片
|
| 185 |
+
|
| 186 |
+
Dyn采样器可以很大程度上避免出大图时的结构、肢体崩坏,能很大程度得到更优秀的手部(不完美但比已有采样方法更好)
|
| 187 |
+
|
| 188 |
+
Smea采样器理论上将增加图片的细节(**无法达到Nai3让图片闪闪发光的效果**)
|
| 189 |
+
|
| 190 |
+
适配绝大多数图片尺寸,在大图的效果尤其优秀,支持缺乏训练的异种尺寸(例如在sdxl跑512x512,在sd1.5跑823x1216,以及640x960等)
|
| 191 |
+
|
| 192 |
+
在SD1.5效果很好,在SDXL效果不明显。
|
| 193 |
+
|
| 194 |
+
计算资源消耗:Euler dy将约等于euler a, 而euler smea dy将消耗更多计算资源(约1.25倍)
|
| 195 |
+
|
| 196 |
+
<a id="section10"></a>
|
| 197 |
+
## Effect
|
| 198 |
+
**SD1.5,测试模型AnythingV5-Prt-RE,测试姿势Heart Hand,一个容易出坏手的姿势**
|
| 199 |
+
|
| 200 |
+
**SD1.5: Testing the AnythingV5-Prt-RE model with the Heart Hand pose often results in distorted hand positions.**
|
| 201 |
+
|
| 202 |
+
768x768,without Lora:
|
| 203 |
+

|
| 204 |
+
768x768,with Lora:
|
| 205 |
+

|
| 206 |
+
832x1216,without lora:
|
| 207 |
+

|
| 208 |
+
832x1216,with Lora:
|
| 209 |
+

|
| 210 |
+
|
| 211 |
+
**SDXL,测试模型animagineXLV31,测试姿势也是手部姿势**
|
| 212 |
+
|
| 213 |
+
**SDXL: Testing animagineXLV31 model with hand poses.**
|
| 214 |
+
|
| 215 |
+
768x768:
|
| 216 |
+

|
| 217 |
+
832x1216:
|
| 218 |
+

|
| 219 |
+

|
| 220 |
+
|
| 221 |
+
<a id="section11"></a>
|
| 222 |
+
## how to use(This has become outdated, but it will be retained)
|
| 223 |
+
|
| 224 |
+
**step.1:** 打开`sd-webui-aki-v4.6\repositories\k-diffusion\k_diffusion`文件夹,打开其中的`sampling.py`文件(可以用记事本打开,称为文件1)
|
| 225 |
+
|
| 226 |
+
**Step 1:** Navigate to the `k_diffusion` folder within the `sd-webui-aki-v4.6\repositories\k-diffusion` directory and open the `sampling.py` file within it (this can be done using a text editor like Notepad, which will be referred to as File 1).
|
| 227 |
+

|
| 228 |
+
|
| 229 |
+
**step.2:** 复制本仓库中的`sampling.py`中的所有内容并粘贴到文件1末尾
|
| 230 |
+
|
| 231 |
+
**Step 2:** Copy the entire content from the `sampling.py` file in the current repository and paste it at the end of File 1.
|
| 232 |
+

|
| 233 |
+
(To present the complete picture, I have utilized PyTorch's abbreviation feature.)
|
| 234 |
+
|
| 235 |
+
**Step 3:** Open the `sd_samplers_kdiffusion.py` file located in the `sd-webui-aki-v4.6\modules` directory (refer to this as File 2).
|
| 236 |
+

|
| 237 |
+
|
| 238 |
+
**Step 4:** Copy the following two lines from this repository:
|
| 239 |
+

|
| 240 |
+
|
| 241 |
+
Paste them into File 2:
|
| 242 |
+

|
| 243 |
+
|
| 244 |
+
**Step 5:** Restart the webui, and you will see:
|
| 245 |
+

|
| 246 |
+
|
| 247 |
+
现在你就可以使用它们了。在图生图中可能有一些bug,欢迎向我汇报(请带上截图/报错声明)
|
| 248 |
+
|
| 249 |
+
Now you can start using them. There may be some bugs in the image generation process, and I welcome you to report any issues to me (please provide screenshots or error statements).
|
| 250 |
+
|
| 251 |
+
<a id="section12"></a>
|
| 252 |
+
## The technical principles
|
| 253 |
+
|
| 254 |
+
简单地讲,dyn方法有规律地取出图片中的一部分,去噪后加回原图。在理论上这应当等同于euler a,但其加噪环节被替代为有引导的噪声。
|
| 255 |
+
|
| 256 |
+
而smea方法将图片潜空间放大再压缩回原本的大小,这增加了图片的可能性。很抱歉我没能实现Nai3中smea让图片微微发光的效果。
|
| 257 |
+
|
| 258 |
+
一点忠告:不要相信pytorch的插值放大和缩小方法,不会对改善图像带来任何帮助。同时用有条件引导取代随机噪声也是有希望的道路。
|
| 259 |
+
|
| 260 |
+
In simple terms, the dyn method regularly extracts a portion of the image, denoises it, and then adds it back to the original image. Theoretically, this should be equivalent to the Euler A method, but its noise addition step is replaced with guided noise.
|
| 261 |
+
|
| 262 |
+
The SMEA method enlarges the image's latent space and then compresses it back to its original dimensions, thereby increasing the range of possible image variations. I apologize that I was unable to achieve the subtle glowing effect in Nai3 with the SMEA method.
|
| 263 |
+
|
| 264 |
+
A piece of advice: Do not trust PyTorch's interpolation methods for enlarging and shrinking images; they will not contribute to improving image quality. Additionally, replacing random noise with conditional guidance is also a promising path forward.
|
| 265 |
+
|
| 266 |
+
<a id="section13"></a>
|
| 267 |
+
## Contact the author
|
| 268 |
+
|
| 269 |
+
Email:872324454@qq.com
|
| 270 |
+
|
| 271 |
+
Bilibili:星河主炮发射
|