nn_archive
最后更新
modelconverter.utils.nn_archivemodelconverter 配置和 NN 归档之间的转换。NN 归档是 Luxonis 的打包格式:一个 tar 文件,其中包含一个或多个模型文件以及一个 config.json 文件,该文件描述了它们的输入、输出、预处理和头部。它位于转换的两端——一个归档可以交给转换器,在这种情况下,它会被解包并转换为一个 Config,然后转换后的模型会被打包回一个新的归档,其配置由该模块构建。函数
archive_from_model
Python
1def archive_from_model(model_path: Path) -> NNArchiveConfig:model_path(Path): 要描述的模型文件的路径。
NNArchiveConfig: 描述模型的归档配置。
default_archive_input_type
Python
1def default_archive_input_type(*, is_raw_input: bool) -> Literal['raw', 'image']:generate_archive
Python
1def generate_archive(platform: Platform, cfg: Config, main_stage: str, out_models: list[Path], output_path: Path, archive_cfg: NNArchiveConfig | None, preprocessing: dict[str, PreprocessingBlock], inference_model_path: Path, archive_name: str | None, preprocessing_input_types: dict[str, Literal['raw', 'image']] | None = None) -> Path:platform(Platform): 模型构建的平台。cfg(Config): 运行转换时使用的配置。main_stage(str): 包含主模型的阶段的键。out_models(list[Path]): 要放入归档的转换后的模型文件。output_path(Path): 归档写入的目录,以及buildinfo.json的获取位置。archive_cfg(NNArchiveConfig | None): 转换开始时使用的归档配置,如果不是从归档开始,则为None。preprocessing(dict[str, PreprocessingBlock]): 要附加的预处理块,以输入名称为键。inference_model_path(Path): 从中读取形状和数据类型的模型的路径。archive_name(str | None): 归档的基本名称。如果为None,则使用配置的名称。preprocessing_input_types(dict[str, Literal['raw', 'image']] | None): 在将预处理外部化之前捕获的原始输入类型。
Path: 创建的归档的路径。
get_archive_input
Python
1def get_archive_input(cfg: NNArchiveConfig, name: str) -> NNArchiveInput:cfg(NNArchiveConfig): 要搜索的归档配置。name(str): 要查找的输入的名称。
NNArchiveInput: 匹配的归档输入。
ValueError: 如果配置未声明该名称的输入。
make_dai_type
Python
1def make_dai_type(encoding: Encoding, data_type: DataType, layout: str | None) -> str:modelconverter_config_to_nn
Python
1def modelconverter_config_to_nn(config: Config, model_name: Path, orig_nn: NNArchiveConfig | None, preprocessing: dict[str, PreprocessingBlock], main_stage_key: str, model_path: Path, platform: Platform, preprocessing_input_types: dict[str, Literal['raw', 'image']] | None = None) -> NNArchiveConfig:preprocessing 显式提供。参数config(Config): 运行转换时使用的配置。model_name(Path): 转换后的模型在归档中存储的文件名。orig_nn(NNArchiveConfig | None): 转换开始时使用的归档配置,如果不是从归档开始,则为None。preprocessing(dict[str, PreprocessingBlock]): 要附加的预处理块,以输入名称为键。main_stage_key(str): 包含主模型的阶段的键。model_path(Path): 从中读取形状和数据类型的模型的路径。platform(Platform): 模型构建的平台。preprocessing_input_types(dict[str, Literal['raw', 'image']] | None): 在外部化预处理清除转换配置的编码之前捕获的原始输入类型。
NNArchiveConfig: 转换模型的归档配置。
NotImplementedError: 如果配置有两个以上的阶段。ValueError: 如果多阶段配置的归档未声明头部。
process_nn_archive
Python
1def process_nn_archive(platform: Platform, path: Path, overrides: Params | None) -> tuple[Config, NNArchiveConfig, str]:platform(Platform): 配置构建的平台。path(Path): 归档的路径。它要么是一个要解包的 tar 文件,要么是一个已经包含解包归档的目录。overrides(Params | None): 在归档自身配置之上应用的 CLI 覆盖。
tuple[Config, NNArchiveConfig, str]: 解析后的 Config、NNArchiveConfig和主阶段键的元组。
RuntimeError: 如果路径既不是目录也不是 tar 文件,或者如果归档不包含config.json。