getInputInfo method
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 (session.has('inputMetadata')) {
final inputMetadata = session.getProperty('inputMetadata'.toJS) as JSObject;
final length = (inputMetadata.getProperty('length'.toJS) as JSNumber).toDartInt;
for (var i = 0; i < length; i++) {
final info = inputMetadata.getProperty(i.toJS) as JSObject;
final infoMap = <String, dynamic>{};
// Add name
infoMap['name'] = info.getProperty('name'.toJS).toString();
// Check if it's a tensor
final isTensorProperty = info.getProperty('isTensor'.toJS);
final isTensor = (isTensorProperty as JSBoolean?)?.toDart ?? true;
if (isTensor) {
// Add shape if available
if (info.has('shape')) {
final shape = info.getProperty('shape'.toJS) as JSObject;
final shapeLength = (shape.getProperty('length'.toJS) as JSNumber).toDartInt;
final shapeList = <int>[];
for (var j = 0; j < shapeLength; j++) {
final dim = shape.getProperty(j.toString().toJS);
// Handle both numeric dimensions and symbolic dimensions
if (dim != null) {
try {
final numValue = (dim as JSNumber).toDartInt;
shapeList.add(numValue);
} catch (e) {
// For symbolic dimensions or non-numeric values, use -1 as a placeholder
shapeList.add(-1);
}
} else {
// For null values, use -1 as a placeholder
shapeList.add(-1);
}
}
infoMap['shape'] = shapeList;
} else {
infoMap['shape'] = <int>[];
}
// Add type if available
if (info.has('type')) {
infoMap['type'] = info.getProperty('type'.toJS).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);
}
}