mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-01-26 19:29:54 +00:00
feat: skip img2img args, size 128 when img2img skip
This commit is contained in:
@@ -1 +1 @@
|
||||
__version__ = "23.11.1"
|
||||
__version__ = "23.12.0.dev0"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import UserList
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property, partial
|
||||
from typing import Any, Literal, NamedTuple, Optional
|
||||
|
||||
@@ -21,6 +22,14 @@ cn_model_regex = r".*(inpaint|tile|scribble|lineart|openpose).*|^None$"
|
||||
cn_module_regex = r".*(inpaint|tile|pidi|lineart|openpose).*|^None$"
|
||||
|
||||
|
||||
@dataclass
|
||||
class SkipImg2ImgOrig:
|
||||
steps: int
|
||||
sampler_name: str
|
||||
width: int
|
||||
height: int
|
||||
|
||||
|
||||
class Arg(NamedTuple):
|
||||
attr: str
|
||||
name: str
|
||||
|
||||
@@ -26,7 +26,7 @@ from adetailer import (
|
||||
mediapipe_predict,
|
||||
ultralytics_predict,
|
||||
)
|
||||
from adetailer.args import ALL_ARGS, BBOX_SORTBY, ADetailerArgs
|
||||
from adetailer.args import ALL_ARGS, BBOX_SORTBY, ADetailerArgs, SkipImg2ImgOrig
|
||||
from adetailer.common import PredictOutput
|
||||
from adetailer.mask import (
|
||||
filter_by_ratio,
|
||||
@@ -107,18 +107,24 @@ def preseve_prompts(p):
|
||||
|
||||
@contextmanager
|
||||
def change_skip_img2img_args(p):
|
||||
if not hasattr(p, "_ad_skip_img2img") or not p._ad_skip_img2img:
|
||||
yield
|
||||
else:
|
||||
if hasattr(p, "_ad_orig"):
|
||||
steps = p.steps
|
||||
sampler_name = p.sampler_name
|
||||
width = p.width
|
||||
height = p.height
|
||||
try:
|
||||
p.steps = p._ad_orig_steps
|
||||
p.sampler_name = p._ad_orig_sampler_name
|
||||
p.steps = p._ad_orig.steps
|
||||
p.sampler_name = p._ad_orig.sampler_name
|
||||
p.width = p._ad_orig.width
|
||||
p.height = p._ad_orig.height
|
||||
yield
|
||||
finally:
|
||||
p.steps = steps
|
||||
p.sampler_name = sampler_name
|
||||
p.width = width
|
||||
p.height = height
|
||||
else:
|
||||
yield
|
||||
|
||||
|
||||
class AfterDetailerScript(scripts.Script):
|
||||
@@ -221,10 +227,16 @@ class AfterDetailerScript(scripts.Script):
|
||||
if len(args_) >= 2 and isinstance(args_[1], bool):
|
||||
p._ad_skip_img2img = args_[1]
|
||||
if args_[1]:
|
||||
p._ad_orig_steps = p.steps
|
||||
p._ad_orig_sampler_name = p.sampler_name
|
||||
p._ad_orig = SkipImg2ImgOrig(
|
||||
steps=p.steps,
|
||||
sampler_name=p.sampler_name,
|
||||
width=p.width,
|
||||
height=p.height,
|
||||
)
|
||||
p.steps = 1
|
||||
p.sampler_name = "Euler"
|
||||
p.width = 128
|
||||
p.height = 128
|
||||
else:
|
||||
p._ad_skip_img2img = False
|
||||
|
||||
@@ -359,6 +371,9 @@ class AfterDetailerScript(scripts.Script):
|
||||
if args.ad_use_inpaint_width_height:
|
||||
width = args.ad_inpaint_width
|
||||
height = args.ad_inpaint_height
|
||||
elif hasattr(p, "_ad_orig"):
|
||||
width = p._ad_orig.width
|
||||
height = p._ad_orig.height
|
||||
else:
|
||||
width = p.width
|
||||
height = p.height
|
||||
@@ -368,8 +383,8 @@ class AfterDetailerScript(scripts.Script):
|
||||
def get_steps(self, p, args: ADetailerArgs) -> int:
|
||||
if args.ad_use_steps:
|
||||
return args.ad_steps
|
||||
if hasattr(p, "_ad_orig_steps"):
|
||||
return p._ad_orig_steps
|
||||
if hasattr(p, "_ad_orig"):
|
||||
return p._ad_orig.steps
|
||||
return p.steps
|
||||
|
||||
def get_cfg_scale(self, p, args: ADetailerArgs) -> float:
|
||||
@@ -378,8 +393,8 @@ class AfterDetailerScript(scripts.Script):
|
||||
def get_sampler(self, p, args: ADetailerArgs) -> str:
|
||||
if args.ad_use_sampler:
|
||||
return args.ad_sampler
|
||||
if hasattr(p, "_ad_orig_sampler_name"):
|
||||
return p._ad_orig_sampler_name
|
||||
if hasattr(p, "_ad_orig"):
|
||||
return p._ad_orig.sampler_name
|
||||
return p.sampler_name
|
||||
|
||||
def get_override_settings(self, p, args: ADetailerArgs) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user