getInputInfo method

  1. @override
Future<List<Map<String, dynamic>>> getInputInfo(
  1. String sessionId
)

Get input info about the model

sessionId is the ID of the session to get input info from

Returns information about the model's inputs such as name, type, and shape.

Implementation

@override
Future<List<Map<String, dynamic>>> getInputInfo(String sessionId) async {
  try {
    // Check if the session exists
    if (!_sessions.containsKey(sessionId)) {
      throw PlatformException(code: "INVALID_SESSION", message: "Session not found", details: null);
    }

    final session = _sessions[sessionId]!;
    final inputInfoList = <Map<String, dynamic>>[];

    // Get input metadata from session if available
    if (hasProperty(session, 'inputMetadata')) {
      final inputMetadata = getProperty(session, 'inputMetadata');
      final length = getProperty(inputMetadata, 'length') as int;

      for (var i = 0; i < length; i++) {
        final info = callMethod(inputMetadata, 'at', [i]);
        final infoMap = <String, dynamic>{};

        // Add name
        infoMap['name'] = getProperty(info, 'name').toString();

        // Check if it's a tensor
        final isTensor = getProperty(info, 'isTensor') as bool;

        if (isTensor) {
          // Add shape if available
          if (hasProperty(info, 'shape')) {
            final shape = getProperty(info, 'shape');
            final shapeLength = getProperty(shape, 'length') as int;
            final shapeList = <int>[];

            for (var j = 0; j < shapeLength; j++) {
              final dim = callMethod(shape, 'at', [j]);
              // Handle both numeric dimensions and symbolic dimensions
              if (dim is num) {
                shapeList.add(dim.toInt());
              } else {
                // For symbolic dimensions, use -1 as a placeholder
                shapeList.add(-1);
              }
            }

            infoMap['shape'] = shapeList;
          } else {
            infoMap['shape'] = <int>[];
          }

          // Add type if available
          if (hasProperty(info, 'type')) {
            infoMap['type'] = getProperty(info, 'type').toString();
          } else {
            infoMap['type'] = 'unknown';
          }
        } else {
          // For non-tensor types, provide empty shape
          infoMap['shape'] = <int>[];
          infoMap['type'] = 'non-tensor';
        }

        inputInfoList.add(infoMap);
      }
    } else {
      // Fallback: use input names to create basic info entries
      final inputNames = getInputNames(session);
      for (final name in inputNames) {
        inputInfoList.add({'name': name, 'shape': <int>[], 'type': 'unknown'});
      }
    }

    return inputInfoList;
  } catch (e) {
    if (e is PlatformException) {
      rethrow;
    }
    throw PlatformException(code: "PLUGIN_ERROR", message: "Failed to get input info: $e", details: null);
  }
}