ORTSession

Objective-C

@interface ORTSession : NSObject

Swift

class ORTSession : NSObject

An ORT session loads and runs a model.

  • Unavailable

    Declaration

    Objective-C

    - (instancetype)init NS_UNAVAILABLE;
  • Creates a session.

    Declaration

    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

    Parameters

    env

    The ORT Environment instance.

    path

    The path to the ONNX model.

    sessionOptions

    Optional session configuration options.

    error

    Optional error information set if an error occurs.

    Return Value

    The instance, or nil if an error occurs.

  • Runs the model. The inputs and outputs are pre-allocated.

    Declaration

    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

    Parameters

    inputs

    Dictionary of input names to input ORT values.

    outputs

    Dictionary of output names to output ORT values.

    runOptions

    Optional run configuration options.

    error

    Optional error information set if an error occurs.

    Return Value

    Whether the model was run successfully.

  • Runs the model. The inputs are pre-allocated and the outputs are allocated by ORT.

    Declaration

    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]

    Parameters

    inputs

    Dictionary of input names to input ORT values.

    outputNames

    Set of output names.

    runOptions

    Optional run configuration options.

    error

    Optional error information set if an error occurs.

    Return Value

    A dictionary of output names to output ORT values with the outputs requested in outputNames, or nil if an error occurs.

  • Gets the model’s input names.

    Declaration

    Objective-C

    - (nullable NSArray<NSString *> *)inputNamesWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func inputNames() throws -> [String]

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    An array of input names, or nil if an error occurs.

  • Gets the model’s overridable initializer names.

    Declaration

    Objective-C

    - (nullable NSArray<NSString *> *)overridableInitializerNamesWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func overridableInitializerNames() throws -> [String]

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    An array of overridable initializer names, or nil if an error occurs.

  • Gets the model’s output names.

    Declaration

    Objective-C

    - (nullable NSArray<NSString *> *)outputNamesWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func outputNames() throws -> [String]

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    An array of output names, or nil if an error occurs.