예제 #1
0
        static void Main(string[] args)
        {
            //Constructing a new interpreter instance from the modelfile
            TFLite.Interpreter interpreter = new TFLite.Interpreter("modelpath/modelfile.tflite");
            Console.WriteLine("Interpreter Built Successfully");

            //Setting the number of threads of the interpreter
            interpreter.SetNumThreads(1);

            //Declaring input and output variables;
            Array input = new int[5] {
                1, 2, 3, 4, 5
            };
            Array output = new int[5];

            //Call to invoke the interpreter and run the inference to populate output
            interpreter.Run(input, out output);
            Console.WriteLine("Output generated Successfully");

            //get input, output indices
            Console.WriteLine("Input index for tensorname: " + interpreter.GetInputIndex("tensorname"));
            Console.WriteLine("Output index for tensorname: " + interpreter.GetOutputIndex("tensorname"));

            //Resizing the dimensions
            int[] dims = new int[3] {
                1, 2, 3
            };
            interpreter.ResizeInput(1, dims);

            //Disposing the interpreter to free resources at the end
            interpreter.Dispose();

            Console.WriteLine("Run Complete");
        }
예제 #2
0
        public App()
        {
            TFLite.Interpreter interpreter = null;
            try
            {
                interpreter = new TFLite.Interpreter(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mobilenet_v1_1.0_224.tflite");
            }
            catch (Exception e)
            {
                Tizen.Log.Debug("tflite", "Error: " + e);
            }

            Tizen.Log.Debug("tflite", "Interpreter Initialised");
            Array Output = new byte[1000];

            Array input = new byte[150582];

            input = File.ReadAllBytes(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mouse_224.bmp");

            interpreter.Run(input, ref Output);
            //val variable to check if the Output array is being populated or not.
            byte val = ((byte[])Output)[0];

            // The root page of your application
            MainPage = new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        new Label {
                            HorizontalTextAlignment = TextAlignment.Center,
                            Text = "Welcome to Xamarin Forms!"
                        }
                    }
                }
            };
        }