From 982b513af3d2491dcec0cb9417d1f5fbc4497dc0 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:50:02 +1100 Subject: [PATCH] tidy(config): move a few get_config calls to inside the functions where they are needed --- invokeai/backend/image_util/lama.py | 2 -- invokeai/backend/image_util/patchmatch.py | 4 +--- invokeai/backend/image_util/safety_checker.py | 6 ++---- invokeai/backend/image_util/txt2mask.py | 5 ++--- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/invokeai/backend/image_util/lama.py b/invokeai/backend/image_util/lama.py index e18ba9ef28..5b3fc3a9c7 100644 --- a/invokeai/backend/image_util/lama.py +++ b/invokeai/backend/image_util/lama.py @@ -9,8 +9,6 @@ import invokeai.backend.util.logging as logger from invokeai.app.services.config.config_default import get_config from invokeai.backend.util.devices import choose_torch_device -config = get_config() - def norm_img(np_img): if len(np_img.shape) == 2: diff --git a/invokeai/backend/image_util/patchmatch.py b/invokeai/backend/image_util/patchmatch.py index 44df904524..8b7b468397 100644 --- a/invokeai/backend/image_util/patchmatch.py +++ b/invokeai/backend/image_util/patchmatch.py @@ -10,8 +10,6 @@ import numpy as np import invokeai.backend.util.logging as logger from invokeai.app.services.config.config_default import get_config -config = get_config() - class PatchMatch: """ @@ -28,7 +26,7 @@ class PatchMatch: def _load_patch_match(self): if self.tried_load: return - if config.patchmatch: + if get_config().patchmatch: from patchmatch import patch_match as pm if pm.patchmatch_available: diff --git a/invokeai/backend/image_util/safety_checker.py b/invokeai/backend/image_util/safety_checker.py index a5a72d9efc..a93d15ed73 100644 --- a/invokeai/backend/image_util/safety_checker.py +++ b/invokeai/backend/image_util/safety_checker.py @@ -14,8 +14,6 @@ from invokeai.app.services.config.config_default import get_config from invokeai.backend.util.devices import choose_torch_device from invokeai.backend.util.silence_warnings import SilenceWarnings -config = get_config() - CHECKER_PATH = "core/convert/stable-diffusion-safety-checker" @@ -34,8 +32,8 @@ class SafetyChecker: return try: - cls.safety_checker = StableDiffusionSafetyChecker.from_pretrained(config.models_path / CHECKER_PATH) - cls.feature_extractor = AutoFeatureExtractor.from_pretrained(config.models_path / CHECKER_PATH) + cls.safety_checker = StableDiffusionSafetyChecker.from_pretrained(get_config().models_path / CHECKER_PATH) + cls.feature_extractor = AutoFeatureExtractor.from_pretrained(get_config().models_path / CHECKER_PATH) logger.info("NSFW checker initialized") except Exception as e: logger.warning(f"Could not load NSFW checker: {str(e)}") diff --git a/invokeai/backend/image_util/txt2mask.py b/invokeai/backend/image_util/txt2mask.py index 5a7652ba71..2f34ed673c 100644 --- a/invokeai/backend/image_util/txt2mask.py +++ b/invokeai/backend/image_util/txt2mask.py @@ -37,7 +37,6 @@ from invokeai.app.services.config.config_default import get_config CLIPSEG_MODEL = "CIDAS/clipseg-rd64-refined" CLIPSEG_SIZE = 352 -config = get_config() class SegmentedGrayscale(object): @@ -78,8 +77,8 @@ class Txt2Mask(object): # BUG: we are not doing anything with the device option at this time self.device = device - self.processor = AutoProcessor.from_pretrained(CLIPSEG_MODEL, cache_dir=config.cache_dir) - self.model = CLIPSegForImageSegmentation.from_pretrained(CLIPSEG_MODEL, cache_dir=config.cache_dir) + self.processor = AutoProcessor.from_pretrained(CLIPSEG_MODEL, cache_dir=get_config().cache_dir) + self.model = CLIPSegForImageSegmentation.from_pretrained(CLIPSEG_MODEL, cache_dir=get_config().cache_dir) @torch.no_grad() def segment(self, image: Image.Image, prompt: str) -> SegmentedGrayscale: