mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
couple of img2img fixes
This commit is contained in:
@@ -270,7 +270,6 @@ def resize_image(resize_mode, im, width, height, upscaler_name=None, output_type
|
||||
re_nonletters = re.compile(r'[\s' + string.punctuation + ']+')
|
||||
re_pattern = re.compile(r"(.*?)(?:\[([^\[\]]+)\]|$)")
|
||||
re_pattern_arg = re.compile(r"(.*)<([^>]*)>$")
|
||||
# re_attention = re.compile(r'\((\w+):\d+(\.\d+)?\)')
|
||||
re_attention = re.compile(r'[\(*\[*](\w+)(:\d+(\.\d+))?[\)*\]*]|')
|
||||
re_network = re.compile(r'\<\w+:(\w+)(:\d+(\.\d+))?\>|')
|
||||
re_brackets = re.compile(r'[\([{})\]]')
|
||||
|
||||
@@ -169,6 +169,7 @@ class StableDiffusionProcessing:
|
||||
self.s_tmax = float('inf') # not representable as a standard ui option
|
||||
self.comments = {}
|
||||
self.is_api = False
|
||||
self.resize_mode: int = 0
|
||||
shared.opts.data['clip_skip'] = clip_skip
|
||||
|
||||
@property
|
||||
@@ -1000,6 +1001,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
|
||||
shared.state.job_count = self.n_iter
|
||||
shared.state.job_count = shared.state.job_count * 2
|
||||
shared.state.processing_has_refined_job_count = True
|
||||
hypertile_set(self, hr=True)
|
||||
shared.log.debug(f'Init hires: upscaler="{self.hr_upscaler}" sampler="{self.latent_sampler}" resize={self.hr_resize_x}x{self.hr_resize_y} upscale={self.hr_upscale_to_x}x{self.hr_upscale_to_y}')
|
||||
|
||||
def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts):
|
||||
|
||||
@@ -12,6 +12,7 @@ import modules.sd_models as sd_models
|
||||
import modules.sd_vae as sd_vae
|
||||
import modules.taesd.sd_vae_taesd as sd_vae_taesd
|
||||
import modules.images as images
|
||||
import modules.errors as errors
|
||||
from modules.processing import StableDiffusionProcessing
|
||||
import modules.prompt_parser_diffusers as prompt_parser_diffusers
|
||||
from modules.sd_hijack_hypertile import hypertile_set
|
||||
@@ -28,6 +29,9 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
|
||||
if p.init_images[0].width != tgt_width or p.init_images[0].height != tgt_height:
|
||||
shared.log.debug(f'Resizing init images: original={p.init_images[0].width}x{p.init_images[0].height} target={tgt_width}x{tgt_height}')
|
||||
p.init_images = [images.resize_image(1, image, tgt_width, tgt_height, upscaler_name=None) for image in p.init_images]
|
||||
p.height = tgt_height
|
||||
p.width = tgt_width
|
||||
hypertile_set(p)
|
||||
if p.mask is not None:
|
||||
p.mask = images.resize_image(1, p.mask, tgt_width, tgt_height, upscaler_name=None)
|
||||
if p.mask_for_overlay is not None:
|
||||
@@ -373,6 +377,8 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
|
||||
except ValueError as e:
|
||||
shared.state.interrupted = True
|
||||
shared.log.error(f'Processing: {e}')
|
||||
if shared.cmd_opts.debug:
|
||||
errors.display(e, 'Processing')
|
||||
|
||||
if hasattr(shared.sd_model, 'embedding_db') and len(shared.sd_model.embedding_db.embeddings_used) > 0:
|
||||
p.extra_generation_params['Embeddings'] = ', '.join(shared.sd_model.embedding_db.embeddings_used)
|
||||
|
||||
@@ -43,19 +43,24 @@ def parse_list(x: list[int], /) -> str:
|
||||
@contextmanager
|
||||
def split_attention(layer: nn.Module, tile_size: int=256, min_tile_size: int=256, swap_size: int=1, depth: int=0):
|
||||
# hijacks AttnBlock from ldm and attention from diffusers
|
||||
global reset_needed # pylint: disable=global-statement
|
||||
ar = height / width # Aspect ratio
|
||||
reset_needed = True
|
||||
nhs = possible_tile_sizes(height, tile_size, min_tile_size, swap_size) # possible sub-grids that fit into the image
|
||||
nws = possible_tile_sizes(width, tile_size, min_tile_size, swap_size)
|
||||
# random sub-grid indices # TODO remove randomness. seed?
|
||||
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
|
||||
|
||||
def reset_nhs():
|
||||
nonlocal nhs
|
||||
nonlocal nws, make_ns, ar
|
||||
ar = height / width # Aspect ratio
|
||||
nhs = possible_tile_sizes(height, tile_size, min_tile_size, swap_size)
|
||||
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
|
||||
|
||||
def reset_nws():
|
||||
nonlocal nws
|
||||
nonlocal nws, make_ns, ar
|
||||
ar = height / width # Aspect ratio
|
||||
nws = possible_tile_sizes(width, tile_size, min_tile_size, swap_size)
|
||||
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
|
||||
|
||||
def self_attn_forward(forward: Callable) -> Callable:
|
||||
@wraps(forward)
|
||||
|
||||
@@ -118,7 +118,7 @@ class Script(scripts.Script):
|
||||
prompt_txt.change(lambda tb: gr.update(lines=7) if ("\n" in tb) else gr.update(lines=2), inputs=[prompt_txt], outputs=[prompt_txt], show_progress=False)
|
||||
return [checkbox_iterate, checkbox_iterate_batch, prompt_txt]
|
||||
|
||||
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_txt: str):
|
||||
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_txt: str): # pylint: disable=arguments-differ
|
||||
lines = [x.strip() for x in prompt_txt.splitlines()]
|
||||
lines = [x for x in lines if len(x) > 0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user