public void Recognise(string fileName)
        {
            FileSource    = BitmapFrame.Create(new Uri(fileName));
            ImageFileName = fileName;

            try
            {
                using (_inceptionGraph = new Inception())
                {
                    _fileName = fileName;
                    _inceptionGraph.OnDownloadCompleted += OnDownloadComplete;
                    if (!string.IsNullOrEmpty(DownloadURL) &&
                        !string.IsNullOrEmpty(InceptionGraphFileName) &&
                        !string.IsNullOrEmpty(OutputLabelsFileName))
                    {
                        _inceptionGraph.Init(new string[] { InceptionGraphFileName, OutputLabelsFileName }, DownloadURL);
                    }
                    else
                    {
                        _inceptionGraph.Init();
                    }
                }
            }
            catch (Exception ex)
            {
                _exceptionLogDataAccess.LogException(ex.ToString());
                IsModalVisible = false;
            }
        }
예제 #2
0
        public override void OnButtonClicked(Object sender, EventArgs args)
        {
            base.OnButtonClicked(sender, args);

            if (_buttonMode == ButtonMode.WaitingModelDownload)
            {
                if (_model == Model.Flower)
                {
                    //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");
                }
                else
                {
                    //The inception model
                    _inceptionGraph.Init();
                }
            }
            else
            {
                if (_model == Model.Flower)
                {
                    LoadImages(new string[] { "tulips.jpg" });
                }
                else
                {
                    LoadImages(new string[] { "space_shuttle.jpg" });
                }
            }
        }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        bool loaded = TfInvoke.CheckLibraryLoaded();

        _inceptionGraph = new Inception();
        _liveCameraView = false;

        /*
         * WebCamDevice[] devices = WebCamTexture.devices;
         * cameraCount = devices.Length;
         *
         * if (cameraCount == 0)
         * {
         *  _liveCameraView = false;
         * }
         * else
         * {
         *  _liveCameraView = true;
         *  webcamTexture = new WebCamTexture(devices[0].name);
         *
         *  baseRotation = transform.rotation;
         *  webcamTexture.Play();
         *  //data = new Color32[webcamTexture.width * webcamTexture.height];
         * }*/

        StartCoroutine(_inceptionGraph.Init());
    }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        bool loaded = TfInvoke.Init();

        _inceptionGraph = new Inception();

        //Change the following flag to set default detection based on image / live camera view
        _liveCameraView = false;

        if (_liveCameraView)
        {
            _devices     = WebCamTexture.devices;
            _cameraCount = _devices.Length;

            if (_cameraCount == 0)
            {
                _liveCameraView = false;
            }
            else
            {
                _liveCameraView = true;
                _webcamTexture  = new WebCamTexture(_devices[0].name);

                baseRotation = transform.rotation;
                _webcamTexture.Play();
                //data = new Color32[webcamTexture.width * webcamTexture.height];
            }
        }

        StartCoroutine(_inceptionGraph.Init());
    }
예제 #5
0
        async void inceptionClicked(NSObject sender)
        {
            SetMessage("Please wait while we download Inception model from internet...");
            SetImage(null);

            if (_inceptionGraph == null)
            {
                _inceptionGraph = new Inception();
                _inceptionGraph.OnDownloadProgressChanged += OnDownloadProgressChanged;
                //_inceptionGraph.OnDownloadCompleted += inceptionGraph_OnDownloadCompleted;
            }
            await _inceptionGraph.Init();

            String fileName = "space_shuttle.jpg";

            //Tensor imageTensor = Emgu.TF.Models.ImageIO.ReadTensorFromImageFile<float>(fileName, 224, 224, 128.0f, 1.0f / 128.0f);
            Tensor imageTensor        = Emgu.TF.Models.ImageIO.ReadTensorFromImageFile <float>(fileName, 224, 224, 128.0f, 1.0f);
            var    recognitionResults = _inceptionGraph.Recognize(imageTensor);
            String resStr             = String.Empty;

            if (recognitionResults != null && recognitionResults.Length > 0)
            {
                resStr = String.Format("Object is {0} with {1}% probability.", recognitionResults[0].Label, recognitionResults[0].Probability * 100);
            }
            SetMessage(resStr);
            SetImage(new NSImage(fileName));
        }
예제 #6
0
        private async void OnButtonClicked(Object sender, EventArgs args)
        {
            SetMessage("Please wait while the Inception Model is being downloaded...");
            await _inception.Init();

            if (!_inception.Imported)
            {
                SetMessage("Failed to initialize Inception Model.");
                return;
            }
            SetImage();
            String[] imageFiles = await LoadImages(new string[] { "tulips.jpg" });

            //handle user cancel
            if (imageFiles == null || (imageFiles.Length > 0 && imageFiles[0] == null))
            {
                SetMessage("");
                return;
            }

            Stopwatch watch  = Stopwatch.StartNew();
            var       result = _inception.Recognize(imageFiles[0]);

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

            SetImage(imageFiles[0]);
            SetMessage(resStr);
        }
예제 #7
0
        partial void inceptionClicked(NSObject sender)
        {
            SetMessage("Please wait while we download Inception model from internet...");
            SetImage(null);

            if (_inceptionGraph == null)
            {
                _inceptionGraph = new Inception();
                _inceptionGraph.OnDownloadProgressChanged += OnDownloadProgressChanged;
                _inceptionGraph.OnDownloadCompleted       += inceptionGraph_OnDownloadCompleted;
            }
            _inceptionGraph.Init();
        }
예제 #8
0
        public override void OnButtonClicked(Object sender, EventArgs args)
        {
            base.OnButtonClicked(sender, args);

            if (_buttonMode == ButtonMode.WaitingModelDownload)
            {
                _inceptionGraph.Init();
            }
            else
            {
                LoadImages(new string[] { "space_shuttle.jpg" });
            }
        }
예제 #9
0
파일: MainForm.cs 프로젝트: ko9ma7/emgucv-1
        public MainForm()
        {
            InitializeComponent();

            TfInvoke.CheckLibraryLoaded();
            messageLabel.Text = String.Empty;
            cameraButton.Text = "Start Camera";

            DisableUI();

            //Use the following code for the full inception model
            inceptionGraph = new Inception();
            inceptionGraph.OnDownloadProgressChanged += OnDownloadProgressChangedEventHandler;
            inceptionGraph.OnDownloadCompleted       += onDownloadCompleted;

            inceptionGraph.Init();
        }
예제 #10
0
        private async void OnButtonClicked(Object sender, EventArgs args)
        {
            SetMessage("Please wait while the Inception Model is being downloaded...");
            await _inception.Init();

            SetImage();
            String[] imageFiles = await LoadImages(new string[] { "tulips.jpg" });

            Stopwatch watch  = Stopwatch.StartNew();
            var       result = _inception.Recognize(imageFiles[0]);

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

            SetImage(imageFiles[0]);
            SetMessage(resStr);
        }
예제 #11
0
파일: UnitTest1.cs 프로젝트: emgucv/emgutf
        public async Task TestInceptionBatch()
        {
            //using (Tensor imageTensor = ImageIO.ReadTensorFromImageFile<float>("grace_hopper.jpg", 224, 224, 128.0f, 1.0f))
            using (Tensor imageTensor = ImageIO.ReadTensorFromImageFiles <float>(
                       new String[] { "grace_hopper.jpg", "grace_hopper.jpg" },
                       224,
                       224,
                       128.0f,
                       1.0f))
                using (Inception inceptionGraph = new Inception())
                {
                    await inceptionGraph.Init();

                    Inception.RecognitionResult[][] results = inceptionGraph.Recognize(imageTensor);

                    Trace.WriteLine(String.Format("Object is {0} with {1}% probability", results[0][0].Label, results[0][0].Probability * 100));
                }
        }
예제 #12
0
파일: MainForm.cs 프로젝트: johnsaad/emgutf
        public MainForm()
        {
            InitializeComponent();

            TfInvoke.CheckLibraryLoaded();
            messageLabel.Text = String.Empty;

            DisableUI();


            inceptionGraph = new Inception();
            inceptionGraph.OnDownloadProgressChanged += OnDownloadProgressChangedEventHandler;
            inceptionGraph.OnDownloadCompleted       += onDownloadCompleted;

            //Use the following code for the full inception model
            inceptionGraph.Init();

            //Uncomment the following code to use a retrained model to recognize followers, downloaded from the internet
            //inceptionGraph.Init(new string[] {"optimized_graph.pb", "output_labels.txt"}, "https://github.com/emgucv/models/raw/master/inception_flower_retrain/", "Mul", "final_result");
        }
예제 #13
0
        public InceptionPage()
            : base()
        {
            var button = this.GetButton();

            button.Text     = "Perform Image Classification";
            button.Clicked += OnButtonClicked;

            _inception = new Inception();

            OnImagesLoaded += (sender, imageFiles) =>
            {
                SetMessage("Please wait...");
                SetImage();
                _imageFiles = imageFiles;

#if !DEBUG
                try
#endif
                {
                    if (_inception.Imported)
                    {
                        onDownloadCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(null, false, null));
                    }
                    else
                    {
                        SetMessage("Please wait while the Inception Model is being downloaded...");
                        _inception.OnDownloadProgressChanged += onDownloadProgressChanged;
                        _inception.OnDownloadCompleted       += onDownloadCompleted;
                        _inception.Init();
                    }
                }
#if !DEBUG
                catch (Exception e)
                {
                    String msg = e.Message.Replace(System.Environment.NewLine, " ");
                    SetMessage(msg);
                }
#endif
            };
        }
예제 #14
0
        public void TestInception()
        {
            using (Tensor imageTensor = ImageIO.ReadTensorFromImageFile <float>("grace_hopper.jpg", 224, 224, 128.0f, 1.0f))
                using (Inception inceptionGraph = new Inception())
                {
                    bool processCompleted = false;
                    inceptionGraph.OnDownloadCompleted += (sender, e) =>
                    {
                        HashSet <string> opNames        = new HashSet <string>();
                        HashSet <string> couldBeInputs  = new HashSet <string>();
                        HashSet <string> couldBeOutputs = new HashSet <string>();
                        foreach (Operation op in inceptionGraph.Graph)
                        {
                            String name = op.Name;
                            opNames.Add(name);

                            if (op.NumInputs == 0 && op.OpType.Equals("Placeholder"))
                            {
                                couldBeInputs.Add(op.Name);
                                AttrMetadata dtypeMeta   = op.GetAttrMetadata("dtype");
                                AttrMetadata shapeMeta   = op.GetAttrMetadata("shape");
                                DataType     type        = op.GetAttrType("dtype");
                                Int64[]      shape       = op.GetAttrShape("shape");
                                Buffer       valueBuffer = op.GetAttrValueProto("shape");
                                Buffer       shapeBuffer = op.GetAttrTensorShapeProto("shape");
                                Tensorflow.TensorShapeProto shapeProto =
                                    Tensorflow.TensorShapeProto.Parser.ParseFrom(shapeBuffer.Data);
                            }

                            if (op.OpType.Equals("Const"))
                            {
                                AttrMetadata dtypeMeta = op.GetAttrMetadata("dtype");
                                AttrMetadata valueMeta = op.GetAttrMetadata("value");
                                using (Tensor valueTensor = op.GetAttrTensor("value"))
                                {
                                    var dim = valueTensor.Dim;
                                }
                            }

                            if (op.OpType.Equals("Conv2D"))
                            {
                                AttrMetadata stridesMeta = op.GetAttrMetadata("strides");
                                AttrMetadata paddingMeta = op.GetAttrMetadata("padding");
                                AttrMetadata boolMeta    = op.GetAttrMetadata("use_cudnn_on_gpu");
                                Int64[]      strides     = op.GetAttrIntList("strides");
                                bool         useCudnn    = op.GetAttrBool("use_cudnn_on_gpu");
                                String       padding     = op.GetAttrString("padding");
                            }

                            foreach (Output output in op.Outputs)
                            {
                                int[] shape = inceptionGraph.Graph.GetTensorShape(output);
                                if (output.NumConsumers == 0)
                                {
                                    couldBeOutputs.Add(name);
                                }
                            }

                            Buffer           buffer = inceptionGraph.Graph.GetOpDef(op.OpType);
                            Tensorflow.OpDef opDef  = Tensorflow.OpDef.Parser.ParseFrom(buffer.Data);
                        }

                        using (Buffer versionDef = inceptionGraph.Graph.Versions())
                        {
                            int l = versionDef.Length;
                        }

                        Inception.RecognitionResult[] results = inceptionGraph.Recognize(imageTensor);

                        Trace.WriteLine(String.Format("Object is {0} with {1}% probability", results[0].Label, results[0].Probability * 100));

                        processCompleted = true;
                    };

                    inceptionGraph.Init();
                    while (!processCompleted)
                    {
                        Thread.Sleep(1000);
                    }
                }
        }
예제 #15
0
        public void TestInception()
        {
            using (Tensor imageTensor = ImageIO.ReadTensorFromImageFile("grace_hopper.jpg", 224, 224, 128.0f, 1.0f))
                using (Inception inceptionGraph = new Inception())
                {
                    bool processCompleted = false;
                    inceptionGraph.OnDownloadCompleted += (sender, e) =>
                    {
                        HashSet <string> opNames        = new HashSet <string>();
                        HashSet <string> couldBeInputs  = new HashSet <string>();
                        HashSet <string> couldBeOutputs = new HashSet <string>();
                        foreach (Operation op in inceptionGraph.Graph)
                        {
                            String name = op.Name;
                            opNames.Add(name);

                            if (op.NumInputs == 0 && op.OpType.Equals("Placeholder"))
                            {
                                couldBeInputs.Add(op.Name);
                            }

                            foreach (Output output in op.Outputs)
                            {
                                int[] shape = inceptionGraph.Graph.GetTensorShape(output);
                                if (output.NumConsumers == 0)
                                {
                                    couldBeOutputs.Add(name);
                                }
                            }
                        }
                        using (Buffer versionDef = inceptionGraph.Graph.Versions())
                        {
                            int l = versionDef.Length;
                        }

                        float[] probability = inceptionGraph.Recognize(imageTensor);
                        if (probability != null)
                        {
                            String[] labels = inceptionGraph.Labels;
                            float    maxVal = 0;
                            int      maxIdx = 0;
                            for (int i = 0; i < probability.Length; i++)
                            {
                                if (probability[i] > maxVal)
                                {
                                    maxVal = probability[i];
                                    maxIdx = i;
                                }
                            }
                            Trace.WriteLine(String.Format("Object is {0} with {1}% probability", labels[maxIdx], maxVal * 100));
                        }
                        processCompleted = true;
                    };

                    inceptionGraph.Init();
                    while (!processCompleted)
                    {
                        Thread.Sleep(1000);
                    }
                }
        }