Exemple #1
0
        private static async Task Run()
        {
            SessionOptions so = new SessionOptions();

            if (TfInvoke.IsGoogleCudaEnabled)
            {
                Tensorflow.ConfigProto config = new Tensorflow.ConfigProto();
                config.GpuOptions             = new Tensorflow.GPUOptions();
                config.GpuOptions.AllowGrowth = true;
                so.SetConfig(config.ToProtobuf());
            }
            _inceptionGraph = new Emgu.TF.Models.Inception(null, so);
            _inceptionGraph.OnDownloadProgressChanged += onDownloadProgressChanged;
            //_inceptionGraph.OnDownloadCompleted += onDownloadCompleted;

            //use a retrained model to recognize followers
            await _inceptionGraph.Init(
                new string[] { "optimized_graph.pb", "output_labels.txt" },
                "https://github.com/emgucv/models/raw/master/inception_flower_retrain/",
                "Placeholder",
                "final_result");

            Stopwatch watch       = Stopwatch.StartNew();
            Tensor    imageTensor = Emgu.TF.Models.ImageIO.ReadTensorFromImageFile <float>(_inputFileInfo.FullName, 299, 299, 0.0f, 1.0f / 255.0f, false, false);
            var       results     = _inceptionGraph.Recognize(imageTensor);

            watch.Stop();
            String resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", results[0].Label, results[0].Probability * 100, watch.ElapsedMilliseconds);

            System.Console.WriteLine(resStr);
        }
Exemple #2
0
        private static async Task Run()
        {
            SessionOptions so = new SessionOptions();

            Tensorflow.ConfigProto config = new Tensorflow.ConfigProto();

#if DEBUG
            config.LogDevicePlacement = true;
#endif

            if (TfInvoke.IsGoogleCudaEnabled)
            {
                config.GpuOptions             = new Tensorflow.GPUOptions();
                config.GpuOptions.AllowGrowth = true;
            }
            so.SetConfig(config.ToProtobuf());

            _inceptionGraph = new Emgu.TF.Models.Inception(null, so);
            _inceptionGraph.OnDownloadProgressChanged += onDownloadProgressChanged;
            //_inceptionGraph.OnDownloadCompleted += onDownloadCompleted;

            System.Console.WriteLine("Initializing model");
            //use a retrained model to recognize followers
            await _inceptionGraph.Init(
                new string[] { "optimized_graph.pb", "output_labels.txt" },
                "https://github.com/emgucv/models/raw/master/inception_flower_retrain/",
                "Placeholder",
                "final_result");

            System.Console.WriteLine("Model initialized.");
            Session.Device[] devices = GetSessionDevices(_inceptionGraph.Session);
            StringBuilder    sb      = new StringBuilder();
            foreach (Session.Device d in devices)
            {
                sb.Append(String.Format("{1}: {0}{2}", d.Name, d.Type, Environment.NewLine));
            }
            System.Console.WriteLine(String.Format("Default Session Devices:{0}{1}", Environment.NewLine, sb.ToString()));


            Stopwatch watch = Stopwatch.StartNew();
            System.Console.WriteLine("Reading image into tensor");
            Tensor imageTensor = Emgu.TF.Models.ImageIO.ReadTensorFromImageFile <float>(_inputFileInfo.FullName, 299, 299, 0.0f, 1.0f / 255.0f, false, false);
            System.Console.WriteLine("Running inference...");
            var results = _inceptionGraph.Recognize(imageTensor);
            watch.Stop();

            String resStr = String.Format("Object is {0} with {1}% probability. Recognition completed in {2} milliseconds.", results[0][0].Label, results[0][0].Probability * 100, watch.ElapsedMilliseconds);
            System.Console.WriteLine(resStr);
        }
Exemple #3
0
        private static void Run()
        {
            SessionOptions so = new SessionOptions();

            if (TfInvoke.IsGoogleCudaEnabled)
            {
                Tensorflow.ConfigProto config = new Tensorflow.ConfigProto();
                config.GpuOptions             = new Tensorflow.GPUOptions();
                config.GpuOptions.AllowGrowth = true;
                so.SetConfig(config.ToProtobuf());
            }
            _inceptionGraph = new Emgu.TF.Models.Inception(null, so);
            _inceptionGraph.OnDownloadProgressChanged += onDownloadProgressChanged;
            _inceptionGraph.OnDownloadCompleted       += onDownloadCompleted;

            //use a retrained model to recognize followers
            _inceptionGraph.Init(
                new string[] { "optimized_graph.pb", "output_labels.txt" },
                "https://github.com/emgucv/models/raw/master/inception_flower_retrain/",
                "Placeholder",
                "final_result");
        }