mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
warn but do not crash when model scan finds random cruft in models
directory
This commit is contained in:
parent
72209d0cc3
commit
79fc708580
@ -7,8 +7,6 @@
|
|||||||
# Coauthor: Kevin Turner http://github.com/keturn
|
# Coauthor: Kevin Turner http://github.com/keturn
|
||||||
#
|
#
|
||||||
import sys
|
import sys
|
||||||
print("Loading Python libraries...\n",file=sys.stderr)
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
@ -706,18 +704,6 @@ def write_opts(opts: Namespace, init_file: Path):
|
|||||||
def default_output_dir() -> Path:
|
def default_output_dir() -> Path:
|
||||||
return config.root_path / "outputs"
|
return config.root_path / "outputs"
|
||||||
|
|
||||||
# # -------------------------------------
|
|
||||||
# def default_embedding_dir() -> Path:
|
|
||||||
# return config.root_path / "embeddings"
|
|
||||||
|
|
||||||
# # -------------------------------------
|
|
||||||
# def default_lora_dir() -> Path:
|
|
||||||
# return config.root_path / "loras"
|
|
||||||
|
|
||||||
# # -------------------------------------
|
|
||||||
# def default_controlnet_dir() -> Path:
|
|
||||||
# return config.root_path / "controlnets"
|
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
def write_default_options(program_opts: Namespace, initfile: Path):
|
def write_default_options(program_opts: Namespace, initfile: Path):
|
||||||
opt = default_startup_options(initfile)
|
opt = default_startup_options(initfile)
|
||||||
|
@ -155,8 +155,6 @@ class ModelInstall(object):
|
|||||||
def install(self, selections: InstallSelections):
|
def install(self, selections: InstallSelections):
|
||||||
job = 1
|
job = 1
|
||||||
jobs = len(selections.remove_models) + len(selections.install_models)
|
jobs = len(selections.remove_models) + len(selections.install_models)
|
||||||
# if selections.scan_directory:
|
|
||||||
# jobs += 1
|
|
||||||
|
|
||||||
# remove requested models
|
# remove requested models
|
||||||
for key in selections.remove_models:
|
for key in selections.remove_models:
|
||||||
@ -218,7 +216,7 @@ class ModelInstall(object):
|
|||||||
# the model from being probed twice in the event that it has already been probed.
|
# the model from being probed twice in the event that it has already been probed.
|
||||||
def _install_path(self, path: Path, info: ModelProbeInfo=None)->Path:
|
def _install_path(self, path: Path, info: ModelProbeInfo=None)->Path:
|
||||||
try:
|
try:
|
||||||
logger.info(f'Probing {path}')
|
# logger.debug(f'Probing {path}')
|
||||||
info = info or ModelProbe().heuristic_probe(path,self.prediction_helper)
|
info = info or ModelProbe().heuristic_probe(path,self.prediction_helper)
|
||||||
model_name = path.stem if info.format=='checkpoint' else path.name
|
model_name = path.stem if info.format=='checkpoint' else path.name
|
||||||
if self.mgr.model_exists(model_name, info.base_type, info.model_type):
|
if self.mgr.model_exists(model_name, info.base_type, info.model_type):
|
||||||
|
@ -714,9 +714,12 @@ class ModelManager(object):
|
|||||||
|
|
||||||
if model_path.is_relative_to(self.app_config.root_path):
|
if model_path.is_relative_to(self.app_config.root_path):
|
||||||
model_path = model_path.relative_to(self.app_config.root_path)
|
model_path = model_path.relative_to(self.app_config.root_path)
|
||||||
model_config: ModelConfigBase = model_class.probe_config(str(model_path))
|
try:
|
||||||
self.models[model_key] = model_config
|
model_config: ModelConfigBase = model_class.probe_config(str(model_path))
|
||||||
new_models_found = True
|
self.models[model_key] = model_config
|
||||||
|
new_models_found = True
|
||||||
|
except NotImplementedError as e:
|
||||||
|
self.logger.warning(e)
|
||||||
|
|
||||||
imported_models = self.autoimport()
|
imported_models = self.autoimport()
|
||||||
|
|
||||||
@ -737,10 +740,10 @@ class ModelManager(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
installed = set()
|
installed = set()
|
||||||
|
scanned_dirs = set()
|
||||||
|
|
||||||
config = self.app_config
|
config = self.app_config
|
||||||
known_paths = {(self.app_config.root_path / x['path']) for x in self.list_models()}
|
known_paths = {(self.app_config.root_path / x['path']) for x in self.list_models()}
|
||||||
scanned_dirs = set()
|
|
||||||
|
|
||||||
for autodir in [config.autoimport_dir,
|
for autodir in [config.autoimport_dir,
|
||||||
config.lora_dir,
|
config.lora_dir,
|
||||||
@ -748,19 +751,25 @@ class ModelManager(object):
|
|||||||
config.controlnet_dir]:
|
config.controlnet_dir]:
|
||||||
if autodir is None:
|
if autodir is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
self.logger.info(f'Scanning {autodir} for models to import')
|
||||||
|
|
||||||
autodir = self.app_config.root_path / autodir
|
autodir = self.app_config.root_path / autodir
|
||||||
if not autodir.exists():
|
if not autodir.exists():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
items_scanned = 0
|
||||||
|
new_models_found = set()
|
||||||
|
|
||||||
for root, dirs, files in os.walk(autodir):
|
for root, dirs, files in os.walk(autodir):
|
||||||
|
items_scanned += len(dirs) + len(files)
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
path = Path(root) / d
|
path = Path(root) / d
|
||||||
if path in known_paths or path.parent in scanned_dirs:
|
if path in known_paths or path.parent in scanned_dirs:
|
||||||
scanned_dirs.add(path)
|
scanned_dirs.add(path)
|
||||||
continue
|
continue
|
||||||
if any([(path/x).exists() for x in {'config.json','model_index.json','learned_embeds.bin'}]):
|
if any([(path/x).exists() for x in {'config.json','model_index.json','learned_embeds.bin'}]):
|
||||||
installed.update(installer.heuristic_install(path))
|
new_models_found.update(installer.heuristic_install(path))
|
||||||
scanned_dirs.add(path)
|
scanned_dirs.add(path)
|
||||||
|
|
||||||
for f in files:
|
for f in files:
|
||||||
@ -768,7 +777,11 @@ class ModelManager(object):
|
|||||||
if path in known_paths or path.parent in scanned_dirs:
|
if path in known_paths or path.parent in scanned_dirs:
|
||||||
continue
|
continue
|
||||||
if path.suffix in {'.ckpt','.bin','.pth','.safetensors','.pt'}:
|
if path.suffix in {'.ckpt','.bin','.pth','.safetensors','.pt'}:
|
||||||
installed.update(installer.heuristic_install(path))
|
new_models_found.update(installer.heuristic_install(path))
|
||||||
|
|
||||||
|
self.logger.info(f'Scanned {items_scanned} files and directories, imported {len(new_models_found)} models')
|
||||||
|
installed.update(new_models_found)
|
||||||
|
|
||||||
return installed
|
return installed
|
||||||
|
|
||||||
def heuristic_import(self,
|
def heuristic_import(self,
|
||||||
|
@ -69,7 +69,7 @@ class StableDiffusion1Model(DiffusersModel):
|
|||||||
in_channels = unet_config['in_channels']
|
in_channels = unet_config['in_channels']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Not supported stable diffusion diffusers format(possibly onnx?)")
|
raise NotImplementedError(f"{path} is not a supported stable diffusion diffusers format")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Unknown stable diffusion 1.* format: {model_format}")
|
raise NotImplementedError(f"Unknown stable diffusion 1.* format: {model_format}")
|
||||||
|
@ -316,31 +316,6 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# label = "Directory to scan for models to automatically import (<tab> autocompletes):"
|
|
||||||
# self.nextrely += 1
|
|
||||||
# widgets.update(
|
|
||||||
# autoload_directory = self.add_widget_intelligent(
|
|
||||||
# FileBox,
|
|
||||||
# max_height=3,
|
|
||||||
# name=label,
|
|
||||||
# value=str(config.root_path / config.autoimport_dir) if config.autoimport_dir else None,
|
|
||||||
# select_dir=True,
|
|
||||||
# must_exist=True,
|
|
||||||
# use_two_lines=False,
|
|
||||||
# labelColor="DANGER",
|
|
||||||
# begin_entry_at=len(label)+1,
|
|
||||||
# scroll_exit=True,
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# widgets.update(
|
|
||||||
# autoscan_on_startup = self.add_widget_intelligent(
|
|
||||||
# npyscreen.Checkbox,
|
|
||||||
# name="Scan and import from this directory each time InvokeAI starts",
|
|
||||||
# value=config.autoimport_dir is not None,
|
|
||||||
# relx=4,
|
|
||||||
# scroll_exit=True,
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
def resize(self):
|
def resize(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user