""" 部署模型加载工具。 这里只负责从已导出的 `.keras` 模型文件恢复推理模型,并按调用方提供的加载函数返回项目内部模型产物。 训练检查点恢复由各 Pipeline 自己负责。 """ from collections.abc import Callable from .checkpoint import describe_checkpoint_lookup, resolve_checkpoint from deep_learning.models.spec import ModelArtifact def load_inference_artifact( checkpoint_rule: dict, load_inference_artifact_fn: Callable, resource_factory: Callable = lambda: None ) -> tuple[ModelArtifact, object]: checkpoint_path, _ = resolve_checkpoint(**checkpoint_rule) if checkpoint_path is None: lookup_info = describe_checkpoint_lookup( dirs=checkpoint_rule.get("dirs"), path=checkpoint_rule.get("path"), suffix=checkpoint_rule.get("suffix") ) raise FileNotFoundError(f"未找到任何部署模型文件。查找信息: {lookup_info}") if checkpoint_path.suffix.lower() != ".keras": raise ValueError(f"部署推理只支持完整 .keras 模型: {checkpoint_path}") return load_inference_artifact_fn(checkpoint_path), resource_factory()