ORTSession
Objective-C
@interface ORTSession : NSObject
Swift
class ORTSession : NSObject
ORT 会话用于加载并运行模型。
-
不可用
声明
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
创建会话。
声明
Objective-C
- (nullable instancetype)initWithEnv:(nonnull ORTEnv *)env modelPath:(nonnull NSString *)path sessionOptions: (nullable ORTSessionOptions *)sessionOptions error:(NSError *_Nullable *_Nullable)error;Swift
init(env: ORTEnv, modelPath path: String, sessionOptions: ORTSessionOptions?) throws参数
envORT 环境实例。
pathONNX 模型的路径。
sessionOptions可选的会话配置选项。
error如果发生错误,则设置的可选错误信息。
返回值
实例,如果发生错误则为 nil。
-
运行模型。输入和输出均为预分配内存。
声明
Objective-C
- (BOOL)runWithInputs:(nonnull NSDictionary<NSString *, ORTValue *> *)inputs outputs:(nonnull NSDictionary<NSString *, ORTValue *> *)outputs runOptions:(nullable ORTRunOptions *)runOptions error:(NSError *_Nullable *_Nullable)error;Swift
func run(withInputs inputs: [String : ORTValue], outputs: [String : ORTValue], runOptions: ORTRunOptions?) throws参数
inputs输入名称到输入 ORT 值的字典。
outputs输出名称到输出 ORT 值的字典。
runOptions可选的运行配置选项。
error如果发生错误,则设置的可选错误信息。
返回值
模型是否运行成功。
-
运行模型。输入为预分配内存,输出由 ORT 分配。
声明
Objective-C
- (nullable NSDictionary<NSString *, ORTValue *> *) runWithInputs:(nonnull NSDictionary<NSString *, ORTValue *> *)inputs outputNames:(nonnull NSSet<NSString *> *)outputNames runOptions:(nullable ORTRunOptions *)runOptions error:(NSError *_Nullable *_Nullable)error;Swift
func run(withInputs inputs: [String : ORTValue], outputNames: Set<String>, runOptions: ORTRunOptions?) throws -> [String : ORTValue]参数
inputs输入名称到输入 ORT 值的字典。
outputNames输出名称集合。
runOptions可选的运行配置选项。
error如果发生错误,则设置的可选错误信息。
返回值
包含
outputNames中所请求输出的输出名称到输出 ORT 值的字典;如果发生错误,则返回 nil。 -
获取模型的输入名称。
声明
Objective-C
- (nullable NSArray<NSString *> *)inputNamesWithError: (NSError *_Nullable *_Nullable)error;Swift
func inputNames() throws -> [String]参数
error如果发生错误,则设置的可选错误信息。
返回值
输入名称数组;如果发生错误,则返回 nil。
-
获取模型的可覆盖初始化器名称。
声明
Objective-C
- (nullable NSArray<NSString *> *)overridableInitializerNamesWithError: (NSError *_Nullable *_Nullable)error;Swift
func overridableInitializerNames() throws -> [String]参数
error如果发生错误,则设置的可选错误信息。
返回值
可覆盖初始化器名称数组;如果发生错误,则返回 nil。
-
获取模型的输出名称。
声明
Objective-C
- (nullable NSArray<NSString *> *)outputNamesWithError: (NSError *_Nullable *_Nullable)error;Swift
func outputNames() throws -> [String]参数
error如果发生错误,则设置的可选错误信息。
返回值
输出名称数组;如果发生错误,则返回 nil。
在 GitHub 上查看
ORTSession 类参考