1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 package org.tensorflow.lite; 17 18 import java.io.File; 19 import java.nio.ByteBuffer; 20 import org.checkerframework.checker.nullness.qual.NonNull; 21 import org.tensorflow.lite.nnapi.NnApiDelegate; 22 23 /** 24 * Private interface specifying factory for constructing InterpreterApi instances. This interface is 25 * an implementation detail of InterpreterFactory and should only be used from within the TensorFlow 26 * Lite implementation. We can't make it package-private, though, because it is used from both 27 * org.tensorflow.lite.InterpreterFactoryImpl and 28 * com.google.android.gms.tflite.InterpreterFactoryImpl. 29 * 30 * @hide 31 */ 32 public interface InterpreterFactoryApi { 33 /** 34 * Constructs an {@link InterpreterApi} instance, using the specified model and options. The model 35 * will be loaded from a file. 36 * 37 * @param modelFile A file containing a pre-trained TF Lite model. 38 * @param options A set of options for customizing interpreter behavior. 39 * @throws IllegalArgumentException if {@code modelFile} does not encode a valid TensorFlow Lite 40 * model. 41 */ create(@onNull File modelFile, InterpreterApi.Options options)42 InterpreterApi create(@NonNull File modelFile, InterpreterApi.Options options); 43 44 /** 45 * Constructs an {@link InterpreterApi} instance, using the specified model and options. The model 46 * will be read from a {@code ByteBuffer}. 47 * 48 * @param byteBuffer A pre-trained TF Lite model, in binary serialized form. The ByteBuffer should 49 * not be modified after the construction of an {@link InterpreterApi} instance. The {@code 50 * ByteBuffer} can be either a {@code MappedByteBuffer} that memory-maps a model file, or a 51 * direct {@code ByteBuffer} of nativeOrder() that contains the bytes content of a model. 52 * @param options A set of options for customizing interpreter behavior. 53 * @throws IllegalArgumentException if {@code byteBuffer} is not a {@code MappedByteBuffer} nor a 54 * direct {@code ByteBuffer} of nativeOrder. 55 */ create(@onNull ByteBuffer byteBuffer, InterpreterApi.Options options)56 InterpreterApi create(@NonNull ByteBuffer byteBuffer, InterpreterApi.Options options); 57 58 /** Returns the version of the underlying TensorFlowLite runtime. */ runtimeVersion()59 String runtimeVersion(); 60 61 /** 62 * Returns the version of the TensorFlowLite model schema that is supported by the underlying 63 * TensorFlowLite runtime. 64 */ schemaVersion()65 String schemaVersion(); 66 67 /** 68 * Instance method for constructing an NNAPI delegate implementation, using the TF Lite runtime 69 * from the InterpreterFactoryApi. 70 */ createNnApiDelegateImpl(NnApiDelegate.Options options)71 NnApiDelegate.PrivateInterface createNnApiDelegateImpl(NnApiDelegate.Options options); 72 } 73