createWithCustomConfig static method

OrtSessionWrapper createWithCustomConfig(
  1. String modelPath, {
  2. OnnxRuntime? runtime,
  3. required void configure(
    1. OrtProviders providers,
    2. Pointer<OrtSessionOptions> options
    ),
})

Creates a session with a custom configuration callback for full control over session options and providers.

Implementation

static OrtSessionWrapper createWithCustomConfig(
  String modelPath, {
  OnnxRuntime? runtime,
  required void Function(
    OrtProviders providers,
    Pointer<OrtSessionOptions> options,
  )
  configure,
}) {
  final rt = runtime ?? OnnxRuntime.instance;
  rt.ensureInitialized();

  final wrapper = OrtSessionWrapper._(rt);
  wrapper._sessionOptions = rt.createSessionOptions();

  final providers = OrtProviders(rt);
  configure(providers, wrapper._sessionOptions);

  wrapper._session = rt.createSession(modelPath, wrapper._sessionOptions);
  wrapper._inputNames = rt.getSessionInputNames(wrapper._session);
  wrapper._outputNames = rt.getSessionOutputNames(wrapper._session);

  return wrapper;
}