device_handlers
最后更新
modelconverter.utils.device_handlers用于驱动物理设备的处理器。RVC4 模型的基准测试和分析是在真实设备上进行的,而不是在转换容器中:模型及其输入被推送到设备,在那里运行命令,然后将结果拉回。此模块将用于此目的的两种传输——ADB 和 SSH——封装在一个接口后面,因此调用者不必关心设备可以通过哪种方式访问。类
AdbHandler
方法
init
Python
1def __init__(device_id: str | None = None, silent: bool = True):device_id(str | None): 可选的 ADB 设备标识符。silent(bool): 如果为True,则抑制命令日志记录。
RuntimeError: 如果设备枚举失败或没有可用的连接设备。ValueError: 如果指定的设备未连接。FileNotFoundError: 如果adb可执行文件不可用。
pull
Python
1def pull(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 设备上的源路径。dst(PathType): 本地计算机上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
push
Python
1def push(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 本地计算机上的源路径。dst(PathType): 设备上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
run
Python
1def run(*args, check: bool = True, **kwargs) -> tuple[int, str, str]:*args: 传递给subprocess.run的位置命令参数。check(bool): 如果为True,则将子进程失败作为异常传播。silent: 如果为True,则抑制命令日志记录。**kwargs: 转发给subprocess.run的其他关键字参数。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
subprocess.CalledProcessError: 如果check已启用且子进程以非零状态退出。
shell
Python
1def shell(cmd: str, *, check: bool = True, silent: bool | None = None) -> tuple[int, str, str]:cmd(str): 要在设备上执行的 shell 命令。check(bool): 如果为True,则将子进程失败作为异常传播。silent(bool | None): 如果为True,则抑制命令日志记录。如果为None,则使用处理器的默认日志记录行为。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
DeviceHandler
方法
init
Python
1def __init__(silent: bool = True):silent(bool): 如果为True,则默认抑制命令日志记录。
pull
Python
1def pull(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 设备上的源路径。dst(PathType): 本地计算机上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
push
Python
1def push(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 本地计算机上的源路径。dst(PathType): 设备上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
run
Python
1def run(*args, check: bool = False, silent: bool = True, **kwargs) -> tuple[int, str, str]:*args: 传递给subprocess.run的位置命令参数。check(bool): 如果为True,则将子进程失败作为异常传播。silent(bool): 如果为True,则抑制命令日志记录。**kwargs: 转发给subprocess.run的其他关键字参数。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
subprocess.CalledProcessError: 如果check已启用且子进程以非零状态退出。
shell
Python
1def shell(cmd: str, *, check: bool = True, silent: bool | None = None) -> tuple[int, str, str]:cmd(str): 要在设备上执行的 shell 命令。check(bool): 如果为True,则将子进程失败作为异常传播。silent(bool | None): 如果为True,则抑制命令日志记录。如果为None,则使用处理器的默认日志记录行为。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
SSHHandler
方法
init
Python
1def __init__(ip: str, silent: bool = True):ip(str): 目标设备 IP 地址。silent(bool): 如果为True,则抑制命令日志记录。
pull
Python
1def pull(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 设备上的源路径。dst(PathType): 本地计算机上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
push
Python
1def push(src: PathType, dst: PathType, *, check: bool = True) -> tuple[int, str, str]:src(PathType): 本地计算机上的源路径。dst(PathType): 设备上的目标路径。check(bool): 如果为True,则将子进程失败作为异常传播。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
shell
Python
1def shell(cmd: str, *, check: bool = True, silent: bool | None = None) -> tuple[int, str, str]:cmd(str): 要在设备上执行的 shell 命令。check(bool): 如果为True,则将子进程失败作为异常传播。silent(bool | None): 如果为True,则抑制命令日志记录。如果为None,则使用处理器的默认日志记录行为。
tuple[int, str, str]: 包含返回码、标准输出和标准错误的元组。
函数
create_handler
Python
1def create_handler(device_ip: str | None, device_adb_id: str | None) -> DeviceHandler:device_ip(str | None): 设备的 IP 地址,用于 SSH 回退。如果没有回退,则为None。device_adb_id(str | None): 设备的 ADB 标识符,如果使用第一个连接的设备,则为None。
DeviceHandler: 设备的处理器。
RuntimeError: 如果没有连接 ADB 设备,或者无法查询 ADB,并且没有提供 IP 地址。ValueError: 如果请求的 ADB 设备未连接且没有提供 IP 地址。FileNotFoundError: 如果adb可执行文件不可用且没有提供 IP 地址。