From bf14e6ed6d476de3d661686fbcb66ec141ea50e3 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 10 Feb 2024 08:10:24 -0500 Subject: [PATCH] fix mask missing options and system paths --- extensions-builtin/Lora/networks.py | 1 - modules/control/run.py | 2 +- modules/masking.py | 2 +- modules/onnx_impl/__init__.py | 3 --- modules/paths.py | 2 ++ modules/postprocess/codeformer_model.py | 7 +++++-- modules/postprocess/gfpgan_model.py | 7 +++++-- modules/sd_models.py | 2 -- modules/shared.py | 5 ++--- modules/ui_control_helpers.py | 17 ++++++++++------- modules/upscaler.py | 7 +++++-- wiki | 2 +- 12 files changed, 32 insertions(+), 25 deletions(-) diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 4b0e58281..50a2de90c 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -438,7 +438,6 @@ def list_available_networks(): forbidden_network_aliases.clear() available_network_hash_lookup.clear() forbidden_network_aliases.update({"none": 1, "Addams": 1}) - os.makedirs(shared.cmd_opts.lora_dir, exist_ok=True) directories = [] if os.path.exists(shared.cmd_opts.lora_dir): directories.append(shared.cmd_opts.lora_dir) diff --git a/modules/control/run.py b/modules/control/run.py index 00337a56d..52f7a2532 100644 --- a/modules/control/run.py +++ b/modules/control/run.py @@ -85,7 +85,7 @@ def control_run(units: List[unit.Unit], inputs, inits, mask, unit_type: str, is_ n_iter = batch_count, batch_size = batch_size, inpaint_full_res = masking.opts.mask_only, - inpaint_full_res_padding = masking.opts.mask_padding, + # inpaint_full_res_padding = masking.opts.mask_padding, inpainting_mask_invert = 1 if masking.opts.invert else 0, inpainting_fill = 1, hdr_mode=hdr_mode, hdr_brightness=hdr_brightness, hdr_color=hdr_color, hdr_sharpen=hdr_sharpen, hdr_clamp=hdr_clamp, diff --git a/modules/masking.py b/modules/masking.py index fac742d78..a23cafcef 100644 --- a/modules/masking.py +++ b/modules/masking.py @@ -385,7 +385,7 @@ def run_mask(input_image: gr.Image, input_mask: gr.Image = None, return_type: st return_type = return_type or opts.preview_type - shared.log.debug(f'Mask: size={input_image.width}x{input_image.height} masked={mask_size}px area={area_size/total_size:.2f} auto={opts.auto_mask} type={return_type} time={t1-t0:.2f}') + shared.log.debug(f'Mask: size={input_image.width}x{input_image.height} masked={mask_size}px area={area_size/total_size:.2f} auto={opts.auto_mask} blur={opts.mask_blur} erode={opts.mask_erode} dilate={opts.mask_dilate} type={return_type} time={t1-t0:.2f}') if return_type == 'None': return input_mask elif return_type == 'Binary': diff --git a/modules/onnx_impl/__init__.py b/modules/onnx_impl/__init__.py index d1785da9b..815c54cfc 100644 --- a/modules/onnx_impl/__init__.py +++ b/modules/onnx_impl/__init__.py @@ -199,9 +199,6 @@ def initialize_onnx(): from modules.paths import models_path from modules.shared import opts from .execution_providers import ExecutionProvider, TORCH_DEVICE_TO_EP, available_execution_providers - onnx_dir = os.path.join(models_path, "ONNX") - if not os.path.isdir(onnx_dir): - os.mkdir(onnx_dir) if devices.backend == "rocm": TORCH_DEVICE_TO_EP["cuda"] = ExecutionProvider.ROCm from .pipelines.onnx_stable_diffusion_pipeline import OnnxStableDiffusionPipeline diff --git a/modules/paths.py b/modules/paths.py index 7295f6575..1b6f4a389 100644 --- a/modules/paths.py +++ b/modules/paths.py @@ -28,6 +28,7 @@ models_config = cli.models_dir or config.get('models_dir') or 'models' models_path = models_config if os.path.isabs(models_config) else os.path.join(data_path, models_config) extensions_dir = os.path.join(data_path, "extensions") extensions_builtin_dir = "extensions-builtin" +onnx_dir = os.path.join(models_path, "ONNX") sd_configs_path = os.path.join(script_path, "configs") sd_default_config = os.path.join(sd_configs_path, "v1-inference.yaml") sd_model_file = cli.ckpt or os.path.join(script_path, 'model.ckpt') # not used @@ -94,6 +95,7 @@ def create_paths(opts): create_path(sd_configs_path) create_path(extensions_dir) create_path(extensions_builtin_dir) + create_path(onnx_dir) create_path(fix_path('temp_dir')) create_path(fix_path('ckpt_dir')) create_path(fix_path('diffusers_dir')) diff --git a/modules/postprocess/codeformer_model.py b/modules/postprocess/codeformer_model.py index 59a990ce2..4a812fdb7 100644 --- a/modules/postprocess/codeformer_model.py +++ b/modules/postprocess/codeformer_model.py @@ -17,8 +17,11 @@ codeformer = None def setup_model(dirname): - if not os.path.exists(model_path): - os.makedirs(model_path) + try: + if not os.path.exists(model_path): + os.makedirs(model_path) + except Exception: + pass path = modules.paths.paths.get("CodeFormer", None) if path is None: return diff --git a/modules/postprocess/gfpgan_model.py b/modules/postprocess/gfpgan_model.py index b85c900e6..e466acb53 100644 --- a/modules/postprocess/gfpgan_model.py +++ b/modules/postprocess/gfpgan_model.py @@ -66,8 +66,11 @@ gfpgan_constructor = None def setup_model(dirname): - if not os.path.exists(model_path): - os.makedirs(model_path) + try: + if not os.path.exists(model_path): + os.makedirs(model_path) + except Exception: + pass try: import gfpgan import facexlib diff --git a/modules/sd_models.py b/modules/sd_models.py index c4ae53a24..c7ea1b79a 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -122,8 +122,6 @@ class NoWatermark: def setup_model(): - if not os.path.exists(model_path): - os.makedirs(model_path, exist_ok=True) list_models() if shared.backend == shared.Backend.ORIGINAL: enable_midas_autodownload() diff --git a/modules/shared.py b/modules/shared.py index 95db8f170..8fbd81bd9 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -486,13 +486,12 @@ options_templates.update(options_section(('system-paths', "System Paths"), { "swinir_models_path": OptionInfo(os.path.join(paths.models_path, 'SwinIR'), "Folder with SwinIR models", folder=True), "ldsr_models_path": OptionInfo(os.path.join(paths.models_path, 'LDSR'), "Folder with LDSR models", folder=True), "clip_models_path": OptionInfo(os.path.join(paths.models_path, 'CLIP'), "Folder with CLIP models", folder=True), - "onnx_cached_models_path": OptionInfo(os.path.join(paths.models_path, 'ONNX', 'cache'), "Folder with ONNX cached models", folder=True), - "other_paths_sep_options": OptionInfo("

Other paths

", "", gr.HTML), "openvino_cache_path": OptionInfo('cache', "Directory for OpenVINO cache", folder=True), + "onnx_cached_models_path": OptionInfo(os.path.join(paths.models_path, 'ONNX', 'cache'), "Folder with ONNX cached models", folder=True), + "onnx_temp_dir": OptionInfo(os.path.join(paths.models_path, 'ONNX', 'temp'), "Directory for ONNX conversion and Olive optimization process", folder=True), "temp_dir": OptionInfo("", "Directory for temporary images; leave empty for default", folder=True), "clean_temp_dir_at_start": OptionInfo(True, "Cleanup non-default temporary directory when starting webui"), - "onnx_temp_dir": OptionInfo(os.path.join(paths.models_path, 'ONNX', 'temp'), "Directory for ONNX conversion and Olive optimization process", folder=True), })) options_templates.update(options_section(('saving-images', "Image Options"), { diff --git a/modules/ui_control_helpers.py b/modules/ui_control_helpers.py index 0662a724b..507fab614 100644 --- a/modules/ui_control_helpers.py +++ b/modules/ui_control_helpers.py @@ -33,13 +33,16 @@ def initialize(): masking.cache_dir = os.path.join(shared.opts.control_dir, 'segment') unit.default_device = devices.device unit.default_dtype = devices.dtype - os.makedirs(shared.opts.control_dir, exist_ok=True) - os.makedirs(controlnet.cache_dir, exist_ok=True) - os.makedirs(xs.cache_dir, exist_ok=True) - os.makedirs(lite.cache_dir, exist_ok=True) - os.makedirs(t2iadapter.cache_dir, exist_ok=True) - os.makedirs(processors.cache_dir, exist_ok=True) - os.makedirs(masking.cache_dir, exist_ok=True) + try: + os.makedirs(shared.opts.control_dir, exist_ok=True) + os.makedirs(controlnet.cache_dir, exist_ok=True) + os.makedirs(xs.cache_dir, exist_ok=True) + os.makedirs(lite.cache_dir, exist_ok=True) + os.makedirs(t2iadapter.cache_dir, exist_ok=True) + os.makedirs(processors.cache_dir, exist_ok=True) + os.makedirs(masking.cache_dir, exist_ok=True) + except Exception: + pass scripts.scripts_current = scripts.scripts_control scripts.scripts_current.initialize_scripts(is_img2img=True) diff --git a/modules/upscaler.py b/modules/upscaler.py index 75b2485cc..70e61384e 100644 --- a/modules/upscaler.py +++ b/modules/upscaler.py @@ -44,8 +44,11 @@ class Upscaler: shared.log.info(f'Upscaler create: folder="{self.user_path}"') if self.model_path is None and self.name: self.model_path = os.path.join(shared.models_path, self.name) - if self.model_path and create_dirs: - os.makedirs(self.model_path, exist_ok=True) + try: + if self.model_path and create_dirs: + os.makedirs(self.model_path, exist_ok=True) + except Exception: + pass try: import cv2 # pylint: disable=unused-import self.can_tile = True diff --git a/wiki b/wiki index fa981144c..581d85a87 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit fa981144c01e244a70d6d2ce4b6750a8421c1563 +Subproject commit 581d85a87f7fe24963210c7d6f88e571660e0777