mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +00:00
fix(ml): model downloading improvements (#3988)
* handle ort `NoSuchFile` error, stricter file check * keep exception order
This commit is contained in:
parent
454737ca79
commit
3cf0f5f11b
2 changed files with 6 additions and 2 deletions
|
@ -8,7 +8,7 @@ from typing import Any
|
||||||
from zipfile import BadZipFile
|
from zipfile import BadZipFile
|
||||||
|
|
||||||
import onnxruntime as ort
|
import onnxruntime as ort
|
||||||
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidProtobuf # type: ignore
|
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidProtobuf, NoSuchFile # type: ignore
|
||||||
|
|
||||||
from ..config import get_cache_dir, log, settings
|
from ..config import get_cache_dir, log, settings
|
||||||
from ..schemas import ModelType
|
from ..schemas import ModelType
|
||||||
|
@ -57,7 +57,7 @@ class InferenceModel(ABC):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loader(**model_kwargs)
|
loader(**model_kwargs)
|
||||||
except (OSError, InvalidProtobuf, BadZipFile):
|
except (OSError, InvalidProtobuf, BadZipFile, NoSuchFile):
|
||||||
log.warn(
|
log.warn(
|
||||||
(
|
(
|
||||||
f"Failed to load {self.model_type.replace('_', ' ')} model '{self.model_name}'."
|
f"Failed to load {self.model_type.replace('_', ' ')} model '{self.model_name}'."
|
||||||
|
|
|
@ -131,6 +131,10 @@ class CLIPEncoder(InferenceModel):
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cached(self) -> bool:
|
||||||
|
return (self.cache_dir / "textual.onnx").is_file() and (self.cache_dir / "visual.onnx").is_file()
|
||||||
|
|
||||||
|
|
||||||
# same as `_transform_blob` without `_blob2image`
|
# same as `_transform_blob` without `_blob2image`
|
||||||
def _transform_pil_image(n_px: int) -> Compose:
|
def _transform_pil_image(n_px: int) -> Compose:
|
||||||
|
|
Loading…
Reference in a new issue