load static method

Future<NsfwDetector> load({
  1. double threshold = _kNSFWThreshold,
  2. bool useGpu = false,
})

Loads the NSFW detector with default parameters.

When useGpu is true, the detector will try the platform GPU delegate first and transparently fall back to CPU execution if delegate creation or model loading fails.

Implementation

static Future<NsfwDetector> load({
  double threshold = _kNSFWThreshold,
  bool useGpu = false,
}) async {
  _validateThreshold(threshold);

  if (useGpu && (Platform.isAndroid || Platform.isIOS)) {
    try {
      return await _loadWithGpu(threshold);
    } catch (_) {
      // Fall through to the CPU path.
    }
  }

  try {
    final interpreter = await Interpreter.fromAsset(_kModelPath);
    return NsfwDetector._create(interpreter, threshold);
  } catch (error, stackTrace) {
    throw NsfwDetectorException(
      'Failed to load NSFW detector model from asset.',
      cause: error,
      stackTrace: stackTrace,
    );
  }
}