Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ControlNet implementation suggestion #139

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fc966ce
UI work in progress
Jorge0998 Mar 30, 2023
3dccbec
UI work in progress
Mar 30, 2023
7c1d26b
Merge branch 'personal-controlnet-implementation' of https://github.c…
JasonS09 Mar 30, 2023
c1f337a
Added controlnet preprocessors settings
Jorge0998 Mar 31, 2023
75ead57
Added controlnet preprocessors settings
JasonS09 Mar 31, 2023
4a2f7d1
Merge branch 'personal-controlnet-implementation' of https://github.c…
Jorge0998 Mar 31, 2023
78c216e
Merge branch 'personal-controlnet-implementation' of https://github.c…
JasonS09 Mar 31, 2023
c7c4e33
Merge branch 'personal-controlnet-implementation' of https://github.c…
JasonS09 Mar 31, 2023
a9984e0
Added controlnet base layout
JasonS09 Apr 1, 2023
44a473a
Added the ability to paste copied image to the image loader layout.
JasonS09 Apr 1, 2023
0ab4579
Get the models and modules from the backend
JasonS09 Apr 2, 2023
f87f803
Added the ability to preview annotators
JasonS09 Apr 2, 2023
a0a3f55
txt2img work in progress
JasonS09 Apr 3, 2023
8dccecd
Working txt2img
JasonS09 Apr 4, 2023
ac41be9
Img2img work in progress
JasonS09 Apr 4, 2023
3a031ed
Working im2img
JasonS09 Apr 5, 2023
6e64766
Remove QMessageBox for debugging
JasonS09 Apr 5, 2023
b6f7bc7
Merge pull request #1 from Interpause/main
JasonS09 Apr 17, 2023
0768ccd
Fixed bug that restarted threshold values every 3 seconds.
JasonS09 Apr 17, 2023
b7a58ad
Merge pull request #2 from Interpause/main
JasonS09 Apr 17, 2023
efbbc87
Merge branch 'personal-controlnet-implementation' of https://github.c…
JasonS09 Apr 17, 2023
8eb2736
Fixed bug that prevented to run controlnet with img2img
JasonS09 Apr 17, 2023
de2156b
Fixed preprocessor preview bug
JasonS09 May 1, 2023
a0c7c4f
Merge pull request #3 from Interpause/main
JasonS09 May 5, 2023
285b0da
Merge pull request #4 from Interpause/main
JasonS09 May 5, 2023
b3acf84
UI work in progress
Mar 30, 2023
eb36174
Added controlnet preprocessors settings
JasonS09 Mar 31, 2023
3204891
Added controlnet base layout
JasonS09 Apr 1, 2023
da1507f
Added the ability to paste copied image to the image loader layout.
JasonS09 Apr 1, 2023
6d4ef4a
Get the models and modules from the backend
JasonS09 Apr 2, 2023
e223b86
Added the ability to preview annotators
JasonS09 Apr 2, 2023
91d08cb
txt2img work in progress
JasonS09 Apr 3, 2023
c906cde
Working txt2img
JasonS09 Apr 4, 2023
e00f8d7
Img2img work in progress
JasonS09 Apr 4, 2023
2e0d344
Working im2img
JasonS09 Apr 5, 2023
f1c7e0a
Remove QMessageBox for debugging
JasonS09 Apr 5, 2023
54e262b
Fixed bug that restarted threshold values every 3 seconds.
JasonS09 Apr 17, 2023
50277eb
Fixed bug that prevented to run controlnet with img2img
JasonS09 Apr 17, 2023
3af1846
Fixed preprocessor preview bug
JasonS09 May 1, 2023
90d1344
Transparency mask for inpainting WIP
JasonS09 May 1, 2023
b9accbb
Update controlnet
JasonS09 May 15, 2023
e8d7e90
Merge branch 'personal-controlnet-implementation' of https://github.c…
JasonS09 May 15, 2023
0bce1b8
Fixed errors
JasonS09 May 15, 2023
8520418
Fixed issue with controlnet threshold spin boxes
JasonS09 May 16, 2023
94fd0dc
More bug fixes
JasonS09 May 16, 2023
f2eef08
horrible, broken transparency mask for inpainting
drhead Jun 6, 2023
4895381
Fixed preprocessor options bug at start.
JasonS09 Jun 6, 2023
9105bbe
Switch controlnet unit at start.
JasonS09 Jun 6, 2023
fb7fabe
Merge pull request #5 from drhead/drhead-patch-1
JasonS09 Jun 6, 2023
14f839d
Working implementation of transparency mask
drhead Jun 6, 2023
d670f7c
Better race condition handling
drhead Jun 7, 2023
1f1a291
Merge pull request #6 from drhead/personal-controlnet-implementation
JasonS09 Jun 7, 2023
e7e4b25
Implement img2img upscale and update mask converter
drhead Jun 7, 2023
cdc2029
Implement upscale postprocess API call function
drhead Jun 7, 2023
eafff05
fix inpainting without selection
drhead Jun 8, 2023
d1a0826
Regression bug fix
JasonS09 Jun 8, 2023
bd7c878
Merge branch 'JasonS09:personal-controlnet-implementation' into perso…
drhead Jun 8, 2023
a99774b
Bypass upscaling call when it is not needed
drhead Jun 8, 2023
14e776b
changed mask generation to only affect group (may break old api)
drhead Jun 9, 2023
2859a75
fix txt2img and simplify glayer creation
drhead Jun 9, 2023
bc6fa51
desperation
drhead Jun 9, 2023
5391954
QTimer-based approach to avoiding mask race condition
drhead Jun 13, 2023
91f5ad8
Fixed mask shredding bug.
drhead Jun 13, 2023
c72b9a8
Regression bug fix
JasonS09 Jun 8, 2023
d8ac876
Regression bug fix
JasonS09 Jun 8, 2023
72a4af5
Fix handling of no selection in inpaint
drhead Jun 13, 2023
cc142c2
Fixed pixel perfect bug
JasonS09 Jun 15, 2023
0d0e476
fixed mask positioning bug
drhead Jun 21, 2023
bfa6e90
Merge branch 'personal-controlnet-implementation' into personal-contr…
JasonS09 Jul 4, 2023
c3fae53
Merge pull request #7 from drhead/personal-controlnet-implementation
JasonS09 Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontends/krita/krita_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TAB_SDCOMMON,
TAB_TXT2IMG,
TAB_UPSCALE,
TAB_CONTROLNET
)
from .docker import create_docker
from .extension import SDPluginExtension
Expand All @@ -18,6 +19,7 @@
SDCommonPage,
Txt2ImgPage,
UpscalePage,
ControlNetPage
)
from .pages.preview import PreviewPage
from .script import script
Expand Down Expand Up @@ -60,6 +62,13 @@
create_docker(UpscalePage),
)
)
instance.addDockWidgetFactory(
DockWidgetFactory(
TAB_CONTROLNET,
DockWidgetFactoryBase.DockLeft,
create_docker(ControlNetPage),
)
)
instance.addDockWidgetFactory(
DockWidgetFactory(
TAB_CONFIG,
Expand Down
306 changes: 303 additions & 3 deletions frontends/krita/krita_diff/client.py

Large diffs are not rendered by default.

274 changes: 274 additions & 0 deletions frontends/krita/krita_diff/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
THREADED = True
ROUTE_PREFIX = "/sdapi/interpause/"
OFFICIAL_ROUTE_PREFIX = "/sdapi/v1/"
CONTROLNET_ROUTE_PREFIX = "/controlnet/"
CONTROLNET_ROUTE_PREFIX = "/controlnet/"

# error messages
ERR_MISSING_CONFIG = "Report this bug, developer missed out a config key somewhere."
Expand All @@ -39,8 +41,135 @@
TAB_IMG2IMG = "krita_diff_img2img"
TAB_INPAINT = "krita_diff_inpaint"
TAB_UPSCALE = "krita_diff_upscale"
TAB_CONTROLNET = "krita_diff_controlnet"
TAB_CONTROLNET = "krita_diff_controlnet"
TAB_PREVIEW = "krita_diff_preview"

# controlnet
CONTROLNET_PREPROCESSOR_SETTINGS = {
"canny": {
"resolution_label": "Annotator resolution",
"threshold_a_label": "Canny low threshold",
"threshold_b_label": "Canny high threshold",
"threshold_a_value": 100,
"threshold_b_value": 200,
"threshold_a_min_value": 1,
"threshold_a_max_value": 255,
"threshold_b_min_value": 1,
"threshold_b_max_value": 255
},
"depth_leres": {
"resolution_label": "LeReS resolution",
"threshold_a_label": "Remove near %",
"threshold_b_label": "Remove background %",
"threshold_a_min_value": 0,
"threshold_a_max_value": 100,
"threshold_b_min_value": 0,
"threshold_b_max_value": 100
},
"depth_leres++": {
"resolution_label": "LeReS resolution",
"threshold_a_label": "Remove near %",
"threshold_b_label": "Remove background %",
"threshold_a_min_value": 0,
"threshold_a_max_value": 100,
"threshold_b_min_value": 0,
"threshold_b_max_value": 100
},
"mediapipe_face": {
"threshold_a_label": "Max Faces",
"threshold_b_label": "Min Face Confidence",
"threshold_a_min_value": 1,
"threshold_a_max_value": 10,
"threshold_b_min_value": 0.01,
"threshold_b_max_value": 1,
"threshold_b_step": 0.01
},
"normal_midas": {
"threshold_a_label": "Normal background threshold",
"threshold_a_value": 0.4,
"threshold_a_min_value": 0,
"threshold_a_max_value": 1,
"threshold_step": 0.01
},
"reference_adain": {
"threshold_a_label": "Style Fidelity (only for \"Balanced\" mode)",
"threshold_a_value": 0.5,
"threshold_a_min_value": 0,
"threshold_a_max_value": 1,
"threshold_step": 0.01
},
"reference_adain+attn": {
"threshold_a_label": "Style Fidelity (only for \"Balanced\" mode)",
"threshold_a_value": 0.5,
"threshold_a_min_value": 0,
"threshold_a_max_value": 1,
"threshold_step": 0.01
},
"reference_only": {
"threshold_a_label": "Style Fidelity (only for \"Balanced\" mode)",
"threshold_a_value": 0.5,
"threshold_a_min_value": 0,
"threshold_a_max_value": 1,
"threshold_step": 0.01
},
"scribble_xdog": {
"threshold_a_label": "XDoG Threshold",
"threshold_a_value": 32,
"threshold_a_min_value": 1,
"threshold_a_max_value": 64
},
"threshold": {
"threshold_a_label": "Binarization Threshold",
"threshold_a_value": 127,
"threshold_a_min_value": 0,
"threshold_a_max_value": 255
},
"tile_resample": {
"threshold_a_label": "Down Sampling Rate",
"threshold_a_value": 1,
"threshold_a_min_value": 1,
"threshold_a_max_value": 8,
"threshold_step": 0.01
},
"hed": {
"resolution_label": "HED resolution",
},
"mlsd": {
"resolution_label": "Hough resolution",
"threshold_a_label": "Hough value threshold (MLSD)",
"threshold_b_label": "Hough distance threshold (MLSD)",
"threshold_a_value": 0.1,
"threshold_b_value": 0.1,
"threshold_a_min_value": 0.01,
"threshold_b_max_value": 2,
"threshold_a_min_value": 0.01,
"threshold_b_max_value": 20,
"threshold_step": 0.01
},
"normal_map": {
"threshold_a_label": "Normal background threshold",
"threshold_a_value": 0.4,
"threshold_a_min_value": 0,
"threshold_a_max_value": 1,
"threshold_step": 0.01
},
"openpose": {},
"openpose_hand": {},
"clip_vision": {},
"color": {},
"pidinet": {},
"scribble": {},
"fake_scribble": {
"resolution_label": "HED resolution",
},
"segmentation": {},
"binary": {
"threshold_a_label": "Binary threshold",
"threshold_a_min_value": 0,
"threshold_a_max_value": 255,
}
}

@dataclass(frozen=True)
class Defaults:
Expand Down Expand Up @@ -128,5 +257,150 @@ class Defaults:
upscale_upscaler_name: str = "None"
upscale_downscale_first: bool = False

controlnet_unit: str = "0"
controlnet_unit_list: List[str] = field(default_factory=lambda: list(str(i) for i in range(10)))
controlnet_preprocessor_list: List[str] = field(default_factory=lambda: [ERROR_MSG])
controlnet_model_list: List[str] = field(default_factory=lambda: [ERROR_MSG])
controlnet_control_mode_list: List[str] = field(default_factory=lambda: ["Balanced", "My prompt is more important", "ControlNet is more important"])

controlnet0_enable: bool = False
controlnet0_low_vram: bool = False
controlnet0_pixel_perfect: bool = False
controlnet0_preprocessor: str = "None"
controlnet0_model: str = "None"
controlnet0_weight: float = 1.0
controlnet0_guidance_start: float = 0
controlnet0_guidance_end: float = 1
controlnet0_preprocessor_resolution: int = 512
controlnet0_threshold_a: float = 0
controlnet0_threshold_b: float = 0
controlnet0_input_image: str = ""
controlnet0_control_mode: str = "Balanced"

controlnet1_enable: bool = False
controlnet1_low_vram: bool = False
controlnet1_pixel_perfect: bool = False
controlnet1_preprocessor: str = "None"
controlnet1_model: str = "None"
controlnet1_weight: float = 1.0
controlnet1_guidance_start: float = 0
controlnet1_guidance_end: float = 1
controlnet1_preprocessor_resolution: int = 512
controlnet1_threshold_a: float = 0
controlnet1_threshold_b: float = 0
controlnet1_input_image: str = ""
controlnet1_control_mode: str = "Balanced"

controlnet2_enable: bool = False
controlnet2_low_vram: bool = False
controlnet2_pixel_perfect: bool = False
controlnet2_preprocessor: str = "None"
controlnet2_model: str = "None"
controlnet2_weight: float = 1.0
controlnet2_guidance_start: float = 0
controlnet2_guidance_end: float = 1
controlnet2_preprocessor_resolution: int = 512
controlnet2_threshold_a: float = 0
controlnet2_threshold_b: float = 0
controlnet2_input_image: str = ""
controlnet2_control_mode: str = "Balanced"

controlnet3_enable: bool = False
controlnet3_low_vram: bool = False
controlnet3_pixel_perfect: bool = False
controlnet3_preprocessor: str = "None"
controlnet3_model: str = "None"
controlnet3_weight: float = 1.0
controlnet3_guidance_start: float = 0
controlnet3_guidance_end: float = 1
controlnet3_preprocessor_resolution: int = 512
controlnet3_threshold_a: float = 0
controlnet3_threshold_b: float = 0
controlnet3_input_image: str = ""
controlnet3_control_mode: str = "Balanced"

controlnet4_enable: bool = False
controlnet4_low_vram: bool = False
controlnet4_pixel_perfect: bool = False
controlnet4_preprocessor: str = "None"
controlnet4_model: str = "None"
controlnet4_weight: float = 1.0
controlnet4_guidance_start: float = 0
controlnet4_guidance_end: float = 1
controlnet4_preprocessor_resolution: int = 512
controlnet4_threshold_a: float = 0
controlnet4_threshold_b: float = 0
controlnet4_input_image: str = ""
controlnet4_control_mode: str = "Balanced"

controlnet5_enable: bool = False
controlnet5_low_vram: bool = False
controlnet5_pixel_perfect: bool = False
controlnet5_preprocessor: str = "None"
controlnet5_model: str = "None"
controlnet5_weight: float = 1.0
controlnet5_guidance_start: float = 0
controlnet5_guidance_end: float = 1
controlnet5_preprocessor_resolution: int = 512
controlnet5_threshold_a: float = 0
controlnet5_threshold_b: float = 0
controlnet5_input_image: str = ""
controlnet5_control_mode: str = "Balanced"

controlnet6_enable: bool = False
controlnet6_low_vram: bool = False
controlnet6_pixel_perfect: bool = False
controlnet6_preprocessor: str = "None"
controlnet6_model: str = "None"
controlnet6_weight: float = 1.0
controlnet6_guidance_start: float = 0
controlnet6_guidance_end: float = 1
controlnet6_preprocessor_resolution: int = 512
controlnet6_threshold_a: float = 0
controlnet6_threshold_b: float = 0
controlnet6_input_image: str = ""
controlnet6_control_mode: str = "Balanced"

controlnet7_enable: bool = False
controlnet7_low_vram: bool = False
controlnet7_pixel_perfect: bool = False
controlnet7_preprocessor: str = "None"
controlnet7_model: str = "None"
controlnet7_weight: float = 1.0
controlnet7_guidance_start: float = 0
controlnet7_guidance_end: float = 1
controlnet7_preprocessor_resolution: int = 512
controlnet7_threshold_a: float = 0
controlnet7_threshold_b: float = 0
controlnet7_input_image: str = ""
controlnet7_control_mode: str = "Balanced"

controlnet8_enable: bool = False
controlnet8_low_vram: bool = False
controlnet8_pixel_perfect: bool = False
controlnet8_preprocessor: str = "None"
controlnet8_model: str = "None"
controlnet8_weight: float = 1.0
controlnet8_guidance_start: float = 0
controlnet8_guidance_end: float = 1
controlnet8_preprocessor_resolution: int = 512
controlnet8_threshold_a: float = 0
controlnet8_threshold_b: float = 0
controlnet8_input_image: str = ""
controlnet8_control_mode: str = "Balanced"

controlnet9_enable: bool = False
controlnet9_low_vram: bool = False
controlnet9_pixel_perfect: bool = False
controlnet9_preprocessor: str = "None"
controlnet9_model: str = "None"
controlnet9_weight: float = 1.0
controlnet9_guidance_start: float = 0
controlnet9_guidance_end: float = 1
controlnet9_preprocessor_resolution: int = 512
controlnet9_threshold_a: float = 0
controlnet9_threshold_b: float = 0
controlnet9_input_image: str = ""
controlnet9_control_mode: str = "Balanced"

DEFAULTS = Defaults()
1 change: 1 addition & 0 deletions frontends/krita/krita_diff/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from .preview import PreviewPage
from .txt2img import Txt2ImgPage
from .upscale import UpscalePage
from .controlnet import ControlNetPage
2 changes: 2 additions & 0 deletions frontends/krita/krita_diff/pages/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def cfg_connect(self):
self.base_url.textChanged.connect(partial(script.cfg.set, "base_url"))
# NOTE: this triggers on every keystroke; theres no focus lost signal...
self.base_url.textChanged.connect(lambda: script.action_update_config())
self.base_url.textChanged.connect(lambda: script.action_update_controlnet_config())
self.base_url_reset.released.connect(
lambda: self.base_url.setText(DEFAULTS.base_url)
)
Expand All @@ -178,6 +179,7 @@ def restore_defaults():
script.cfg.set("first_setup", False)
# retrieve list of available stuff again
script.action_update_config()
script.action_update_controlnet_config()

self.refresh_btn.released.connect(lambda: script.action_update_config())
self.restore_defaults.released.connect(restore_defaults)
Expand Down
Loading