Skip to content

Commit

Permalink
1.3.3 fix single file scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanster committed May 6, 2024
1 parent 64110b0 commit 031846c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions iopaint/download.py
Expand Up @@ -2,7 +2,7 @@
import json
import os
from functools import lru_cache
from typing import List
from typing import List, Optional

from iopaint.schema import ModelType, ModelInfo
from loguru import logger
Expand Down Expand Up @@ -49,7 +49,7 @@ def folder_name_to_show_name(name: str) -> str:


@lru_cache(maxsize=512)
def get_sd_model_type(model_abs_path: str) -> ModelType:
def get_sd_model_type(model_abs_path: str) -> Optional[ModelType]:
if "inpaint" in Path(model_abs_path).name.lower():
model_type = ModelType.DIFFUSERS_SD_INPAINT
else:
Expand All @@ -65,15 +65,19 @@ def get_sd_model_type(model_abs_path: str) -> ModelType:
)
model_type = ModelType.DIFFUSERS_SD_INPAINT
except ValueError as e:
if "Trying to set a tensor of shape torch.Size([320, 4, 3, 3])" in str(e):
if "[320, 4, 3, 3]" in str(e):
model_type = ModelType.DIFFUSERS_SD
else:
logger.info(f"Ignore non sd or sdxl file: {model_abs_path}")
logger.info(f"Ignore non sdxl file: {model_abs_path}")
return
except Exception as e:
logger.error(f"Failed to load {model_abs_path}: {e}")
return
return model_type


@lru_cache()
def get_sdxl_model_type(model_abs_path: str) -> ModelType:
def get_sdxl_model_type(model_abs_path: str) -> Optional[ModelType]:
if "inpaint" in model_abs_path:
model_type = ModelType.DIFFUSERS_SDXL_INPAINT
else:
Expand All @@ -93,10 +97,14 @@ def get_sdxl_model_type(model_abs_path: str) -> ModelType:
else:
model_type = ModelType.DIFFUSERS_SDXL
except ValueError as e:
if "but got torch.Size([320, 4, 3, 3])" in str(e):
if "[320, 4, 3, 3]" in str(e):
model_type = ModelType.DIFFUSERS_SDXL
else:
logger.info(f"Ignore non sd or sdxl file: {model_abs_path}")
logger.info(f"Ignore non sdxl file: {model_abs_path}")
return
except Exception as e:
logger.error(f"Failed to load {model_abs_path}: {e}")
return
return model_type


Expand All @@ -121,6 +129,9 @@ def scan_single_file_diffusion_models(cache_dir) -> List[ModelInfo]:
model_type = model_type_cache.get(it.name)
if model_type is None:
model_type = get_sd_model_type(model_abs_path)
if model_type is None:
continue

model_type_cache[it.name] = model_type
res.append(
ModelInfo(
Expand Down Expand Up @@ -152,6 +163,9 @@ def scan_single_file_diffusion_models(cache_dir) -> List[ModelInfo]:
model_type = sdxl_model_type_cache.get(it.name)
if model_type is None:
model_type = get_sdxl_model_type(model_abs_path)
if model_type is None:
continue

sdxl_model_type_cache[it.name] = model_type
if stable_diffusion_xl_dir.exists():
with open(sdxl_cache_file, "w", encoding="utf-8") as fw:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@ def load_requirements():
# https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files
setuptools.setup(
name="IOPaint",
version="1.3.2",
version="1.3.3",
author="PanicByte",
author_email="cwq1913@gmail.com",
description="Image inpainting, outpainting tool powered by SOTA AI Model",
Expand Down

0 comments on commit 031846c

Please sign in to comment.