예제 #1
0
        public Interpreter(byte[] modelData, bool useGPU = false)
        {
            GCHandle modelDataHandle = GCHandle.Alloc(modelData, GCHandleType.Pinned);
            IntPtr   modelDataPtr    = modelDataHandle.AddrOfPinnedObject();

            model = TfLiteModelCreate(modelDataPtr, modelData.Length);
            if (model == IntPtr.Zero)
            {
                throw new Exception("Failed to create TensorFlowLite Model");
            }

            interpreterOptions = TfLiteInterpreterOptionsCreate();
            TfLiteInterpreterOptionsSetNumThreads(interpreterOptions, numThreads);

            TFLInterpreterErrorReporter reporter = InterpreterErrorReporter;

            TfLiteInterpreterOptionsSetErrorReporter(interpreterOptions, reporter, interpreter);

            if (useGPU)
            {
                GpuDelegateCreate();
            }

            interpreter = TfLiteInterpreterCreate(model, interpreterOptions);
            if (interpreter == IntPtr.Zero)
            {
                throw new Exception("Failed to create TensorFlowLite Interpreter");
            }

            if (!useGPU)
            {
                AllocateTensors();
            }
        }
예제 #2
0
 private static extern unsafe void TfLiteInterpreterOptionsSetErrorReporter(TfLiteInterpreterOptions options,
                                                                            TFLInterpreterErrorReporter reporter, IntPtr userData);