|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Runtime.InteropServices; |
| 4 | +using System.Text; |
| 5 | +using Tensorflow.Lite; |
| 6 | + |
| 7 | +namespace Tensorflow |
| 8 | +{ |
| 9 | + public class c_api_lite |
| 10 | + { |
| 11 | + public const string TensorFlowLibName = "tensorflowlite_c"; |
| 12 | + |
| 13 | + public static string StringPiece(IntPtr handle) |
| 14 | + { |
| 15 | + return handle == IntPtr.Zero ? String.Empty : Marshal.PtrToStringAnsi(handle); |
| 16 | + } |
| 17 | + |
| 18 | + [DllImport(TensorFlowLibName)] |
| 19 | + public static extern IntPtr TfLiteVersion(); |
| 20 | + |
| 21 | + [DllImport(TensorFlowLibName)] |
| 22 | + public static extern SafeTfLiteModelHandle TfLiteModelCreateFromFile(string model_path); |
| 23 | + |
| 24 | + [DllImport(TensorFlowLibName)] |
| 25 | + public static extern void TfLiteModelDelete(IntPtr model); |
| 26 | + |
| 27 | + [DllImport(TensorFlowLibName)] |
| 28 | + public static extern SafeTfLiteInterpreterOptionsHandle TfLiteInterpreterOptionsCreate(); |
| 29 | + |
| 30 | + [DllImport(TensorFlowLibName)] |
| 31 | + public static extern void TfLiteInterpreterOptionsDelete(IntPtr options); |
| 32 | + |
| 33 | + [DllImport(TensorFlowLibName)] |
| 34 | + public static extern void TfLiteInterpreterOptionsSetNumThreads(SafeTfLiteInterpreterOptionsHandle options, int num_threads); |
| 35 | + |
| 36 | + [DllImport(TensorFlowLibName)] |
| 37 | + public static extern SafeTfLiteInterpreterHandle TfLiteInterpreterCreate(SafeTfLiteModelHandle model, SafeTfLiteInterpreterOptionsHandle optional_options); |
| 38 | + |
| 39 | + [DllImport(TensorFlowLibName)] |
| 40 | + public static extern void TfLiteInterpreterDelete(IntPtr interpreter); |
| 41 | + |
| 42 | + [DllImport(TensorFlowLibName)] |
| 43 | + public static extern TfLiteStatus TfLiteInterpreterAllocateTensors(SafeTfLiteInterpreterHandle interpreter); |
| 44 | + |
| 45 | + [DllImport(TensorFlowLibName)] |
| 46 | + public static extern int TfLiteInterpreterGetInputTensorCount(SafeTfLiteInterpreterHandle interpreter); |
| 47 | + |
| 48 | + [DllImport(TensorFlowLibName)] |
| 49 | + public static extern int TfLiteInterpreterGetOutputTensorCount(SafeTfLiteInterpreterHandle interpreter); |
| 50 | + |
| 51 | + [DllImport(TensorFlowLibName)] |
| 52 | + public static extern TfLiteStatus TfLiteInterpreterResizeInputTensor(SafeTfLiteInterpreterHandle interpreter, |
| 53 | + int input_index, int[] input_dims, int input_dims_size); |
| 54 | + |
| 55 | + [DllImport(TensorFlowLibName)] |
| 56 | + public static extern TfLiteTensor TfLiteInterpreterGetInputTensor(SafeTfLiteInterpreterHandle interpreter, int input_index); |
| 57 | + |
| 58 | + [DllImport(TensorFlowLibName)] |
| 59 | + public static extern TF_DataType TfLiteTensorType(TfLiteTensor tensor); |
| 60 | + |
| 61 | + [DllImport(TensorFlowLibName)] |
| 62 | + public static extern int TfLiteTensorNumDims(TfLiteTensor tensor); |
| 63 | + |
| 64 | + [DllImport(TensorFlowLibName)] |
| 65 | + public static extern int TfLiteTensorDim(TfLiteTensor tensor, int dim_index); |
| 66 | + |
| 67 | + [DllImport(TensorFlowLibName)] |
| 68 | + public static extern int TfLiteTensorByteSize(TfLiteTensor tensor); |
| 69 | + |
| 70 | + [DllImport(TensorFlowLibName)] |
| 71 | + public static extern IntPtr TfLiteTensorData(TfLiteTensor tensor); |
| 72 | + |
| 73 | + [DllImport(TensorFlowLibName)] |
| 74 | + public static extern IntPtr TfLiteTensorName(TfLiteTensor tensor); |
| 75 | + |
| 76 | + [DllImport(TensorFlowLibName)] |
| 77 | + public static extern TfLiteQuantizationParams TfLiteTensorQuantizationParams(TfLiteTensor tensor); |
| 78 | + |
| 79 | + [DllImport(TensorFlowLibName)] |
| 80 | + public static extern TfLiteStatus TfLiteTensorCopyFromBuffer(TfLiteTensor tensor, IntPtr input_data, int input_data_size); |
| 81 | + } |
| 82 | +} |
0 commit comments