initialize static method
Loads the ONNX model into an OrtSession. Safe to call multiple times.
Implementation
static Future<void> initialize() async {
if (_session != null) {
return;
}
try {
// Ensure assets exist and copy both model.onnx and model.data to a readable path.
final modelPath = await _materializeModelFiles();
final sessionOptions = OrtSessionOptions();
_session = await _runtime.createSession(
modelPath,
options: sessionOptions,
);
if (_session == null) {
throw StateError('Failed to create ONNX session for FaceValidator');
}
final inputNames = _session!.inputNames;
if (inputNames.isEmpty) {
throw StateError('Face detection model has no inputs');
}
_inputName = inputNames.first;
_outputNames = _session!.outputNames;
if (_outputNames.length < 3) {
throw StateError(
'Face detection model is expected to expose 3 outputs',
);
}
print(
'FaceValidator initialized. Input=$_inputName, Outputs=${_outputNames.join(', ')}',
);
} catch (e) {
print('FaceValidator initialization failed: $e');
rethrow;
}
}