createSession method

  1. @override
Future<Map<String, dynamic>> createSession(
  1. String modelPath, {
  2. Map<String, dynamic>? sessionOptions,
})

Implementation

@override
Future<Map<String, dynamic>> createSession(String modelPath, {Map<String, dynamic>? sessionOptions}) async {
  try {
    // Initialize session options for onnxruntime-web
    final jsSessionOptions = createJsSessionOptions(sessionOptions);

    // Create the session using onnxruntime-web
    final session = await createInferenceSession(modelPath, jsSessionOptions);

    // Generate a unique session ID
    final sessionId = DateTime.now().millisecondsSinceEpoch.toString();

    // Get input and output names
    final inputNames = getInputNames(session);
    final outputNames = getOutputNames(session);

    // Store the session for later use
    _sessions[sessionId] = session;

    // Return the required information
    return {'sessionId': sessionId, 'inputNames': inputNames, 'outputNames': outputNames};
  } catch (e) {
    throw PlatformException(code: 'PLUGIN_ERROR', message: 'Failed to create ONNX session: $e', details: null);
  }
}