Skip to content

Commit 433b3ab

Browse files
committed
Revert "Merge pull request AUTOMATIC1111#7931 from space-nuko/img2img-enhance"
This reverts commit 4268759, reversing changes made to 1b63afb.
1 parent 4268759 commit 433b3ab

File tree

7 files changed

+13
-131
lines changed

7 files changed

+13
-131
lines changed

javascript/ui.js

+1-21
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,7 @@ function create_tab_index_args(tabId, args){
132132

133133
function get_img2img_tab_index() {
134134
let res = args_to_array(arguments)
135-
res.splice(-2) // gradio also sends outputs to the arguments, pop them off
136-
res[0] = get_tab_index('mode_img2img')
137-
return res
138-
}
139-
140-
function get_img2img_tab_index_for_res_preview() {
141-
let res = args_to_array(arguments)
142-
res.splice(-1) // gradio also sends outputs to the arguments, pop them off
135+
res.splice(-2)
143136
res[0] = get_tab_index('mode_img2img')
144137
return res
145138
}
@@ -368,16 +361,3 @@ function selectCheckpoint(name){
368361
desiredCheckpointName = name;
369362
gradioApp().getElementById('change_checkpoint').click()
370363
}
371-
372-
373-
function onCalcResolutionImg2Img(mode, scale, width, height, resize_mode, init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint){
374-
i2iScale = gradioApp().getElementById('img2img_scale')
375-
i2iWidth = gradioApp().getElementById('img2img_width')
376-
i2iHeight = gradioApp().getElementById('img2img_height')
377-
378-
setInactive(i2iScale, scale == 1)
379-
setInactive(i2iWidth, scale > 1)
380-
setInactive(i2iHeight, scale > 1)
381-
382-
return [];
383-
}

modules/generation_parameters_copypaste.py

-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ def parse_generation_parameters(x: str):
282282
res["Hires resize-1"] = 0
283283
res["Hires resize-2"] = 0
284284

285-
if "Img2Img upscale" not in res:
286-
res["Img2Img upscale"] = 1
287-
288285
restore_old_hires_fix_params(res)
289286

290287
return res

modules/img2img.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args):
7878
processed_image.save(os.path.join(output_dir, filename))
7979

8080

81-
def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_index: int, mask_blur: int, mask_alpha: float, inpainting_fill: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, height: int, width: int, scale: float, upscaler: str, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, *args):
81+
def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_index: int, mask_blur: int, mask_alpha: float, inpainting_fill: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, height: int, width: int, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, *args):
8282
override_settings = create_override_settings_dict(override_settings_texts)
8383

8484
is_batch = mode == 5
@@ -149,8 +149,6 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s
149149
inpaint_full_res_padding=inpaint_full_res_padding,
150150
inpainting_mask_invert=inpainting_mask_invert,
151151
override_settings=override_settings,
152-
scale=scale,
153-
upscaler=upscaler,
154152
)
155153

156154
p.scripts = modules.scripts.scripts_txt2img

modules/processing.py

+5-32
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def save_intermediate(image, index):
946946
class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
947947
sampler = None
948948

949-
def __init__(self, init_images: Optional[list] = None, resize_mode: int = 0, denoising_strength: float = 0.75, image_cfg_scale: Optional[float] = None, mask: Any = None, mask_blur: int = 4, inpainting_fill: int = 0, inpaint_full_res: bool = True, inpaint_full_res_padding: int = 0, inpainting_mask_invert: int = 0, initial_noise_multiplier: Optional[float] = None, scale: float = 0, upscaler: Optional[str] = None, **kwargs):
949+
def __init__(self, init_images: list = None, resize_mode: int = 0, denoising_strength: float = 0.75, image_cfg_scale: float = None, mask: Any = None, mask_blur: int = 4, inpainting_fill: int = 0, inpaint_full_res: bool = True, inpaint_full_res_padding: int = 0, inpainting_mask_invert: int = 0, initial_noise_multiplier: float = None, **kwargs):
950950
super().__init__(**kwargs)
951951

952952
self.init_images = init_images
@@ -966,37 +966,11 @@ def __init__(self, init_images: Optional[list] = None, resize_mode: int = 0, den
966966
self.mask = None
967967
self.nmask = None
968968
self.image_conditioning = None
969-
self.scale = scale
970-
self.upscaler = upscaler
971-
972-
def get_final_size(self):
973-
if self.scale > 1:
974-
img = self.init_images[0]
975-
width = int(img.width * self.scale)
976-
height = int(img.height * self.scale)
977-
return width, height
978-
else:
979-
return self.width, self.height
980-
981969

982970
def init(self, all_prompts, all_seeds, all_subseeds):
983971
self.sampler = sd_samplers.create_sampler(self.sampler_name, self.sd_model)
984972
crop_region = None
985973

986-
if self.scale > 1:
987-
self.extra_generation_params["Img2Img upscale"] = self.scale
988-
989-
# Non-latent upscalers are run before sampling
990-
# Latent upscalers are run during sampling
991-
init_upscaler = None
992-
if self.upscaler is not None:
993-
self.extra_generation_params["Img2Img upscaler"] = self.upscaler
994-
if self.upscaler not in shared.latent_upscale_modes:
995-
assert len([x for x in shared.sd_upscalers if x.name == self.upscaler]) > 0, f"could not find upscaler named {self.upscaler}"
996-
init_upscaler = self.upscaler
997-
998-
self.width, self.height = self.get_final_size()
999-
1000974
image_mask = self.image_mask
1001975

1002976
if image_mask is not None:
@@ -1019,7 +993,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
1019993
image_mask = images.resize_image(2, mask, self.width, self.height)
1020994
self.paste_to = (x1, y1, x2-x1, y2-y1)
1021995
else:
1022-
image_mask = images.resize_image(self.resize_mode, image_mask, self.width, self.height, init_upscaler)
996+
image_mask = images.resize_image(self.resize_mode, image_mask, self.width, self.height)
1023997
np_mask = np.array(image_mask)
1024998
np_mask = np.clip((np_mask.astype(np.float32)) * 2, 0, 255).astype(np.uint8)
1025999
self.mask_for_overlay = Image.fromarray(np_mask)
@@ -1036,7 +1010,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
10361010
image = images.flatten(img, opts.img2img_background_color)
10371011

10381012
if crop_region is None and self.resize_mode != 3:
1039-
image = images.resize_image(self.resize_mode, image, self.width, self.height, init_upscaler)
1013+
image = images.resize_image(self.resize_mode, image, self.width, self.height)
10401014

10411015
if image_mask is not None:
10421016
image_masked = Image.new('RGBa', (image.width, image.height))
@@ -1081,9 +1055,8 @@ def init(self, all_prompts, all_seeds, all_subseeds):
10811055

10821056
self.init_latent = self.sd_model.get_first_stage_encoding(self.sd_model.encode_first_stage(image))
10831057

1084-
latent_scale_mode = shared.latent_upscale_modes.get(self.upscaler, None) if self.upscaler is not None else shared.latent_upscale_modes.get(shared.latent_upscale_default_mode, "nearest")
1085-
if latent_scale_mode is not None:
1086-
self.init_latent = torch.nn.functional.interpolate(self.init_latent, size=(self.height // opt_f, self.width // opt_f), mode=latent_scale_mode["mode"], antialias=latent_scale_mode["antialias"])
1058+
if self.resize_mode == 3:
1059+
self.init_latent = torch.nn.functional.interpolate(self.init_latent, size=(self.height // opt_f, self.width // opt_f), mode="bilinear")
10871060

10881061
if image_mask is not None:
10891062
init_mask = latent_mask

modules/ui.py

+4-69
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import gradio as gr
1616
import gradio.routes
1717
import gradio.utils
18-
from gradio.events import Releaseable
1918
import numpy as np
2019
from PIL import Image, PngImagePlugin
2120
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call
@@ -128,26 +127,6 @@ def calc_resolution_hires(enable, width, height, hr_scale, hr_resize_x, hr_resiz
128127
return f"resize: from <span class='resolution'>{p.width}x{p.height}</span> to <span class='resolution'>{p.hr_resize_x or p.hr_upscale_to_x}x{p.hr_resize_y or p.hr_upscale_to_y}</span>"
129128

130129

131-
def calc_resolution_img2img(mode, scale, resize_x, resize_y, resize_mode, *i2i_images):
132-
init_img = None
133-
if mode in {0, 1, 3, 4}:
134-
init_img = i2i_images[mode]
135-
elif mode == 2:
136-
init_img = i2i_images[mode]["image"]
137-
138-
if not init_img:
139-
return ""
140-
141-
if scale > 1:
142-
width = int(init_img.width * scale)
143-
height = int(init_img.height * scale)
144-
else:
145-
width = resize_x
146-
height = resize_y
147-
148-
return f"resize: from <span class='resolution'>{init_img.width}x{init_img.height}</span> to <span class='resolution'>{width}x{height}</span>"
149-
150-
151130
def apply_styles(prompt, prompt_neg, styles):
152131
prompt = shared.prompt_styles.apply_styles_to_prompt(prompt, styles)
153132
prompt_neg = shared.prompt_styles.apply_negative_styles_to_prompt(prompt_neg, styles)
@@ -756,7 +735,7 @@ def copy_image(img):
756735
)
757736

758737
with FormRow():
759-
resize_mode = gr.Radio(label="Resize mode", elem_id="resize_mode", choices=["Just resize", "Crop and resize", "Resize and fill"], type="index", value="Just resize")
738+
resize_mode = gr.Radio(label="Resize mode", elem_id="resize_mode", choices=["Just resize", "Crop and resize", "Resize and fill", "Just resize (latent upscale)"], type="index", value="Just resize")
760739

761740
for category in ordered_ui_categories():
762741
if category == "sampler":
@@ -765,13 +744,8 @@ def copy_image(img):
765744
elif category == "dimensions":
766745
with FormRow():
767746
with gr.Column(elem_id="img2img_column_size", scale=4):
768-
with FormRow(variant="compact"):
769-
final_resolution = FormHTML(value="", elem_id="img2img_finalres", label="Upscaled resolution", interactive=False)
770-
with FormRow(variant="compact"):
771-
scale = gr.Slider(minimum=1.0, maximum=4.0, step=0.05, label="Upscale by", value=1.0, elem_id="img2img_scale")
772-
with FormRow(variant="compact"):
773-
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
774-
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
747+
width = gr.Slider(minimum=64, maximum=2048, step=8, label="Width", value=512, elem_id="img2img_width")
748+
height = gr.Slider(minimum=64, maximum=2048, step=8, label="Height", value=512, elem_id="img2img_height")
775749

776750
with gr.Column(elem_id="img2img_dimensions_row", scale=1, elem_classes="dimensions-tools"):
777751
res_switch_btn = ToolButton(value=switch_values_symbol, elem_id="img2img_res_switch_btn")
@@ -786,9 +760,7 @@ def copy_image(img):
786760
with FormRow():
787761
cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='CFG Scale', value=7.0, elem_id="img2img_cfg_scale")
788762
image_cfg_scale = gr.Slider(minimum=0, maximum=3.0, step=0.05, label='Image CFG Scale', value=1.5, elem_id="img2img_image_cfg_scale", visible=shared.sd_model and shared.sd_model.cond_stage_key == "edit")
789-
with FormRow():
790-
upscaler = gr.Dropdown(label="Upscaler", elem_id="img2img_upscaler", choices=[*shared.latent_upscale_modes, *[x.name for x in shared.sd_upscalers]], value=shared.latent_upscale_default_mode)
791-
denoising_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Denoising strength', value=0.75, elem_id="img2img_denoising_strength")
763+
denoising_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Denoising strength', value=0.75, elem_id="img2img_denoising_strength")
792764

793765
elif category == "seed":
794766
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox = create_seed_inputs('img2img')
@@ -841,39 +813,6 @@ def select_img2img_tab(tab):
841813
outputs=[inpaint_controls, mask_alpha],
842814
)
843815

844-
img2img_resolution_preview_inputs = [dummy_component, # filled in by selected img2img tab index in _js
845-
scale, width, height, resize_mode,
846-
init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint]
847-
for input in img2img_resolution_preview_inputs[1:]:
848-
if isinstance(input, Releaseable):
849-
input.release(
850-
fn=calc_resolution_img2img,
851-
_js="get_img2img_tab_index_for_res_preview",
852-
inputs=img2img_resolution_preview_inputs,
853-
outputs=[final_resolution],
854-
show_progress=False,
855-
).success(
856-
None,
857-
_js="onCalcResolutionImg2Img",
858-
inputs=img2img_resolution_preview_inputs,
859-
outputs=[],
860-
show_progress=False,
861-
)
862-
else:
863-
input.change(
864-
fn=calc_resolution_img2img,
865-
_js="get_img2img_tab_index_for_res_preview",
866-
inputs=img2img_resolution_preview_inputs,
867-
outputs=[final_resolution],
868-
show_progress=False,
869-
).success(
870-
None,
871-
_js="onCalcResolutionImg2Img",
872-
inputs=img2img_resolution_preview_inputs,
873-
outputs=[],
874-
show_progress=False,
875-
)
876-
877816
img2img_gallery, generation_info, html_info, html_log = create_output_panel("img2img", opts.outdir_img2img_samples)
878817

879818
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
@@ -922,8 +861,6 @@ def select_img2img_tab(tab):
922861
subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w, seed_checkbox,
923862
height,
924863
width,
925-
scale,
926-
upscaler,
927864
resize_mode,
928865
inpaint_full_res,
929866
inpaint_full_res_padding,
@@ -1009,8 +946,6 @@ def select_img2img_tab(tab):
1009946
(seed, "Seed"),
1010947
(width, "Size-1"),
1011948
(height, "Size-2"),
1012-
(scale, "Img2Img upscale"),
1013-
(upscaler, "Img2Img upscaler"),
1014949
(batch_size, "Batch size"),
1015950
(subseed, "Variation seed"),
1016951
(subseed_strength, "Variation seed strength"),

scripts/xyz_grid.py

-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def __init__(self, *args, **kwargs):
220220
AxisOption("Clip skip", int, apply_clip_skip),
221221
AxisOption("Denoising", float, apply_field("denoising_strength")),
222222
AxisOptionTxt2Img("Hires upscaler", str, apply_field("hr_upscaler"), choices=lambda: [*shared.latent_upscale_modes, *[x.name for x in shared.sd_upscalers]]),
223-
AxisOptionImg2Img("Upscaler", str, apply_field("upscaler"), choices=lambda: [*shared.latent_upscale_modes, *[x.name for x in shared.sd_upscalers]]),
224223
AxisOptionImg2Img("Cond. Image Mask Weight", float, apply_field("inpainting_mask_weight")),
225224
AxisOption("VAE", str, apply_vae, cost=0.7, choices=lambda: list(sd_vae.vae_dict)),
226225
AxisOption("Styles", str, apply_styles, choices=lambda: list(shared.prompt_styles.styles)),

style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ button.custom-button{
287287
border-radius: 0 0.5rem 0.5rem 0;
288288
}
289289

290-
#txtimg_hr_finalres, #img2img_finalres {
290+
#txtimg_hr_finalres{
291291
min-height: 0 !important;
292292
padding: .625rem .75rem;
293293
margin-left: -0.75em
294294
}
295295

296-
#txtimg_hr_finalres .resolution, #img2img_finalres .resolution{
296+
#txtimg_hr_finalres .resolution{
297297
font-weight: bold;
298298
}
299299

0 commit comments

Comments
 (0)