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
参数
env
ORT 环境实例。
path
ONNX 模型的路径。
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
发生错误时设置的可选错误信息。
返回值
一个字典,包含输出名称到输出 ORT 值,其中输出是
outputNames
中请求的,如果发生错误则为 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。