createCompiledFromBuffer static method
Future<FaceDetection>
createCompiledFromBuffer(
- Uint8List modelBytes,
- FaceDetectionModel model, {
- Set<
Accelerator> accelerators = const {Accelerator.gpu, Accelerator.cpu}, - Precision precision = Precision.fp16,
Creates a face detection model backed by LiteRT CompiledModel.
Implementation
static Future<FaceDetection> createCompiledFromBuffer(
Uint8List modelBytes,
FaceDetectionModel model, {
Set<Accelerator> accelerators = const {Accelerator.gpu, Accelerator.cpu},
Precision precision = Precision.fp16,
}) async {
if (model == FaceDetectionModel.fullSparse) {
// Upstream LiteRT bug (reproduced in Google's own Python API): GPU
// compilation of this model's DENSIFY op aborts the process with an
// uncatchable SIGABRT, even with CPU fallback in the accelerator set.
throw UnsupportedError(
'FaceDetectionModel.fullSparse is not supported with the '
'CompiledModel engine; use the Interpreter engine for this model.',
);
}
final SSDAnchorOptions opts = ssdOptionsFor(model);
final int inW = opts.inputSizeWidth;
final int inH = opts.inputSizeHeight;
final List<List<double>> anchors = generateAnchors(opts);
final CompiledModel compiledModel = _isDefaultAccelerators(accelerators)
? CompiledModel.fromBufferWithGpuFallback(
modelBytes,
precision: precision,
onFallback: _onGpuFallback,
)
: CompiledModel.fromBuffer(
modelBytes,
accelerators: accelerators,
precision: precision,
);
final obj = FaceDetection._compiled(compiledModel, inW, inH, anchors);
try {
obj._initializeCompiledModel();
return obj;
} catch (_) {
obj.dispose();
rethrow;
}
}