loadFromBytes method

Interpreter loadFromBytes(
  1. Uint8List modelBytes, {
  2. String? cacheKey,
  3. int numThreads = 2,
})

Loads a TFLite model from raw bytes.

Useful for models downloaded at runtime or bundled differently.

Implementation

Interpreter loadFromBytes(
  Uint8List modelBytes, {
  String? cacheKey,
  int numThreads = 2,
}) {
  if (cacheKey != null && _cache.containsKey(cacheKey)) {
    return _cache[cacheKey]!;
  }

  final options = InterpreterOptions()..threads = numThreads;

  final interpreter = Interpreter.fromBuffer(
    modelBytes,
    options: options,
  );

  if (cacheKey != null) {
    _cache[cacheKey] = interpreter;
  }

  return interpreter;
}