telemetry
最后更新
modelconverter.utils.telemetrymodelconverter CLI 报告的遥测事件。构建 CLI 通过 luxonis_ml.telemetry 为转换运行发送的属性负载:运行了哪个命令,如何配置转换,以及转换如何结束。报告的值是枚举值、布尔值、数字设置和从配置派生的分桶计数,而不是原始模型名称、路径或文件内容。通过环境变量传播的转换运行 ID 将主机端命令事件与转换 Docker 容器内部发出的事件关联起来。类
ArchiveOutputMode
native) 或 Luxonis NN 存档 (nn_archive)。属性
NATIVE
NN_ARCHIVE
CalibrationSource
属性
IMAGE_DIRECTORY
RANDOM
REMOTE_LINK
CommandName
属性
CONVERT
CommandResult
属性
FAILED
INTERRUPTED
SUCCESS
ConfigSource
属性
ARCHIVE_DIRECTORY
DIRECT_MODEL_INPUT
NN_ARCHIVE
YAML_CONFIG
ConversionPhase
属性
CONFIGURATION
CONVERSION
UPLOAD_INTERMEDIATE
UPLOAD_OUTPUT
FailureReason
属性
CONFIG_ERROR
CONVERSION_ERROR
RUNTIME_ERROR
UPLOAD_ERROR
USER_INTERRUPT
TelemetryFlowStep
属性
CONFIGURATION_RESOLVED
RESULT_RECORDED
函数
bucket_count
Python
1def bucket_count(value: int | None) -> str | None:示例
Pycon
1>>> bucket_count(0)
2'0'
3>>> bucket_count(3)
4'2_4'
5>>> bucket_count(9)
6'5_plus'value(int | None): 要报告的计数。分桶可防止遥测事件携带转换模型的精确形状。
str | None:"0"、"1"、"2_4"或"5_plus"之一,如果value为None,则为None。
bucket_memory_bytes
Python
1def bucket_memory_bytes(value: int | None) -> str | None:示例
Pycon
1>>> bucket_memory_bytes(256 * 1024**2)
2'under_512m'
3>>> bucket_memory_bytes(2 * 1024**3)
4'1g_4g'value(int | None): 以字节为单位的内存大小,如 peak_ram_usage_bytes 所测量。
str | None:"under_512m"、"512m_1g"、"1g_4g"或"above_4g"之一,如果value为None,则为None。
build_command_properties
Python
1def build_command_properties(*, conversion_run_id: str, platform: Platform, runs_in_docker: bool, dev_image: bool, gpu_enabled: bool, tool_version: str | None, custom_image_provided: bool, memory_limit_set: bool, cpu_limit_set: bool, result: CommandResult, duration_ms: int, failure_reason: FailureReason | None = None) -> dict[str, ParamValue]:conversion_run_id(str): 将事件与转换运行关联的 ID。platform(Platform): 命令调用的平台。runs_in_docker(bool): 转换是否在 Docker 容器内运行。dev_image(bool): 是否使用开发镜像标签。gpu_enabled(bool): 是否请求了 GPU 访问。tool_version(str | None): 平台的已解析工具版本,如果由自定义镜像标签决定,则为None。custom_image_provided(bool): 是否提供了自定义 Docker 镜像。镜像名称本身从不报告。memory_limit_set(bool): 是否设置了内存限制。限制本身从不报告。cpu_limit_set(bool): 是否设置了 CPU 限制。限制本身从不报告。result(CommandResult): 命令的结果。duration_ms(int): 命令的挂钟持续时间(毫秒)。failure_reason(FailureReason | None): 命令失败的原因,如果未失败,则为None。
dict[str, ParamValue]: 事件属性,None值已删除。
build_conversion_result_properties
Python
1def build_conversion_result_properties(*, result: CommandResult, duration_ms: int, uploaded_output: bool, uploaded_intermediate_outputs: bool, failure_reason: FailureReason | None = None, output_artifact_count: int | None = None, peak_ram_bytes: int | None = None) -> dict[str, ParamValue]:result(CommandResult): 转换的结果。duration_ms(int): 转换的挂钟持续时间(毫秒)。uploaded_output(bool): 输出模型是否已上传到远程位置。uploaded_intermediate_outputs(bool): 中间输出是否已上传到远程位置。failure_reason(FailureReason | None): 转换失败的原因,如果未失败,则为None。output_artifact_count(int | None): 生成的输出工件数量。在报告之前由 bucket_count 分桶。peak_ram_bytes(int | None): 峰值 RAM 使用量(字节)。在报告之前由 bucket_memory_bytes 分桶。
dict[str, ParamValue]: 事件属性,None值已删除。
build_conversion_summary
Python
1def build_conversion_summary(cfg: Config, *, platform: Platform, config_source: ConfigSource, archive_output_mode: ArchiveOutputMode, archive_preprocess: bool, main_stage_provided: bool) -> dict[str, ParamValue]:cfg(Config): 已解析的转换配置。platform(Platform): 模型转换的平台。config_source(ConfigSource): 配置的来源。archive_output_mode(ArchiveOutputMode): 输出的交付形式。archive_preprocess(bool): 预处理是否添加到 NN 存档而不是模型。main_stage_provided(bool): 是否明确提供了主阶段的名称。
dict[str, ParamValue]: 事件属性,None值已删除。
build_flow_properties
Python
1def build_flow_properties(conversion_run_id: str, flow_step: TelemetryFlowStep, properties: Mapping[str, ParamValue]) -> dict[str, ParamValue]:conversion_run_id(str): 将事件与转换运行关联的 ID。flow_step(TelemetryFlowStep): 事件所属的转换流步骤。properties(Mapping[str, ParamValue]): 要扩展的事件属性。
dict[str, ParamValue]: 属性,已添加流名称、转换运行 ID 和流步骤。
command_failure_reason_from_exception
Python
1def command_failure_reason_from_exception(exc: BaseException | None) -> FailureReason | None:exc(BaseException | None): 终止命令的异常,如果命令正常完成,则为None。
FailureReason | None: 如果命令未失败,则为None;对于键盘中断或退出代码130,则为FailureReason.USER_INTERRUPT;否则为FailureReason.RUNTIME_ERROR。
command_result_from_exception
Python
1def command_result_from_exception(exc: BaseException | None) -> CommandResult:exc(BaseException | None): 终止命令的异常,如果命令正常完成,则为None。
CommandResult: 对于没有异常或代码为None或0的SystemExit,则为CommandResult.SUCCESS;对于键盘中断或退出代码130,则为CommandResult.INTERRUPTED;否则为CommandResult.FAILED。
detect_config_source
Python
1def detect_config_source(path: str | None, opts: list[str], archive_cfg: NNArchiveConfig | None) -> ConfigSource:path(str | None): 命令行上给定的路径(如果有)。opts(list[str]): CLI 配置覆盖,作为交替的键和值令牌。archive_cfg(NNArchiveConfig | None): 从 NN 存档中提取的配置,如果输入是存档或存档目录。
ConfigSource: 当给定存档配置时为ConfigSource.NN_ARCHIVE或ConfigSource.ARCHIVE_DIRECTORY;当给定模型文件或input_model覆盖时为ConfigSource.DIRECT_MODEL_INPUT;否则为ConfigSource.YAML_CONFIG。
get_component_telemetry
Python
1def get_component_telemetry() -> Telemetry:Telemetry: 为 modelconverter 注册的Telemetry实例。
get_conversion_run_id
Python
1def get_conversion_run_id() -> str:MODELCONVERTER_CONVERSION_RUN_ID 环境变量中,并在首次使用时生成,以便主机端命令和 Docker 容器内运行的转换报告相同的 ID。返回str: 当前进程的转换运行 ID。
peak_ram_usage_bytes
Python
1def peak_ram_usage_bytes() -> int:resource.getrusage,其 ru_maxrss 在 macOS 上以字节报告,在其他地方以 kibibytes 报告。返回int: 峰值驻留集大小(字节)。
resolve_tool_version
Python
1def resolve_tool_version(*, platform: Platform, tool_version: str | None, image: str | None) -> str | None:platform(Platform): 模型转换的平台。tool_version(str | None): 明确请求的工具版本(如果有)。image(str | None): 自定义 Docker 镜像(如果有)。
str | None: 请求的工具版本,或平台的默认版本。当给定带有显式标签的自定义镜像时,返回None,因为版本由该标签决定。
runtime_failure_reason_from_exception
Python
1def runtime_failure_reason_from_exception(exc: BaseException | None, *, phase: ConversionPhase) -> FailureReason | None:exc(BaseException | None): 结束转换的异常,如果转换正常完成,则为None。phase(ConversionPhase): 转换结束时所处的转换阶段。
FailureReason | None: 如果没有异常,则为None;对于键盘中断或退出代码130,则为FailureReason.USER_INTERRUPT;否则为与阶段匹配的失败原因。
telemetry_environment
Python
1def telemetry_environment() -> dict[str, str]:dict[str, str]: 当前环境中设置的转换运行 ID 和LUXONIS_TELEMETRY_*变量。未设置的变量将被省略。