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。