getOutputInfo method
Get output info about the model
sessionId
is the ID of the session to get output info from
Returns information about the model's outputs such as name, type, and shape.
Implementation
@override
Future<List<Map<String, dynamic>>> getOutputInfo(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 outputInfoList = <Map<String, dynamic>>[];
// Get output metadata from session if available
if (session.has('outputMetadata')) {
final outputMetadata = session.getProperty('outputMetadata'.toJS) as JSObject;
final length = (outputMetadata.getProperty('length'.toJS) as JSNumber).toDartInt;
for (var i = 0; i < length; i++) {
final info = outputMetadata.getProperty(i.toString().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';
}
outputInfoList.add(infoMap);
}
} else {
// Fallback: use output names to create basic info entries
final outputNames = getOutputNames(session);
for (final name in outputNames) {
outputInfoList.add({'name': name, 'shape': <int>[], 'type': 'unknown'});
}
}
return outputInfoList;
} catch (e) {
if (e is PlatformException) {
rethrow;
}
throw PlatformException(code: "PLUGIN_ERROR", message: "Failed to get output info: $e", details: null);
}
}