using System; using UnityEngine; namespace TensorFlowLite { /// /// Extension methods for InterpreterOptions /// public static class InterpreterOptionsExtension { /// /// Find the best delegate and add to options. /// /// An interpreter options /// A desired delegate type /// A type of model input (float, sbyte etc.) public static void AutoAddDelegate( this InterpreterOptions options, TfLiteDelegateType delegateType, Type inputType) { switch (delegateType) { case TfLiteDelegateType.NONE: options.threads = SystemInfo.processorCount; break; case TfLiteDelegateType.NNAPI: if (Application.platform == RuntimePlatform.Android) { #if UNITY_ANDROID && !UNITY_EDITOR // Create NNAPI delegate with default options options.AddDelegate(new NNAPIDelegate()); #endif // UNITY_ANDROID && !UNITY_EDITOR } else { Debug.LogError("NNAPI is only supported on Android"); } break; case TfLiteDelegateType.GPU: options.AddGpuDelegate(); break; case TfLiteDelegateType.XNNPACK: options.threads = SystemInfo.processorCount; options.AddDelegate(XNNPackDelegate.DelegateForType(inputType)); break; default: options.Dispose(); throw new NotImplementedException(); } } } }