public GetClassifiersPerClassifierVerbose GetClassifier(string classifierId)
        {
            if (string.IsNullOrEmpty(classifierId))
            {
                throw new ArgumentNullException(nameof(classifierId));
            }

            GetClassifiersPerClassifierVerbose result = null;

            try
            {
                result = this.Client.GetAsync($"{this.Endpoint}{string.Format(PATH_CLASSIFIER, classifierId)}")
                         .WithArgument("api_key", ApiKey)
                         .WithArgument("version", VERSION_DATE_2016_05_20)
                         .WithFormatter(new MediaTypeHeaderValue("application/octet-stream"))
                         .As <GetClassifiersPerClassifierVerbose>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Example #2
0
    private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
    {
        Log.Debug("ExampleVisualRecognition", "VisualRecognition - TrainClassifier Response: {0}", data);

#if DELETE_TRAINED_CLASSIFIER
        _classifierToDelete = classifier.classifier_id;
#endif
        _trainClassifierTested = true;
    }
Example #3
0
        public GetClassifiersPerClassifierVerbose CreateClassifier(string classifierName, Dictionary <string, byte[]> positiveExamplesData, byte[] negativeExamplesData = null)
        {
            GetClassifiersPerClassifierVerbose result = null;

            if (string.IsNullOrEmpty(classifierName))
            {
                throw new ArgumentNullException(nameof(classifierName));
            }

            if (positiveExamplesData == null)
            {
                throw new ArgumentNullException(nameof(positiveExamplesData));
            }

            if (positiveExamplesData.Count < 2 && negativeExamplesData == null)
            {
                throw new ArgumentNullException("Training a Visual Recognition classifier requires at least two positive example files or one positive example and negative example file.");
            }

            try
            {
                var formData = new MultipartFormDataContent();

                foreach (var kvp in positiveExamplesData)
                {
                    var positiveExampleDataContent = new ByteArrayContent(kvp.Value);
                    positiveExampleDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/zip");
                    formData.Add(positiveExampleDataContent, string.Format("{0}_positive_examples", kvp.Key), string.Format("{0}_positive_examples.zip", kvp.Key));
                }

                if (negativeExamplesData != null)
                {
                    var negativeExamplesDataContent = new ByteArrayContent(negativeExamplesData);
                    negativeExamplesDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/zip");
                    formData.Add(negativeExamplesDataContent, "negative_examples", "negative_examples.zip");
                }

                var nameDataContent = new StringContent(classifierName, Encoding.UTF8, HttpMediaType.TEXT_PLAIN);
                nameDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                formData.Add(nameDataContent, "name");

                result = this.Client.PostAsync($"{ this.Endpoint}{PATH_CLASSIFIERS}")
                         .WithArgument("version", VERSION_DATE_2016_05_20)
                         .WithArgument("api_key", ApiKey)
                         .WithBodyContent(formData)
                         .WithFormatter(new MediaTypeHeaderValue("application/octet-stream"))
                         .As <GetClassifiersPerClassifierVerbose>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Example #4
0
    private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, Dictionary <string, object> customData)
    {
        Log.Debug("ExampleVisualRecognition.OnTrainClassifier()", "{0}", customData["json"].ToString());

#if DELETE_TRAINED_CLASSIFIER
        _classifierToDelete = classifier.classifier_id;
#endif
        _classifierID          = classifier.classifier_id;
        _trainClassifierTested = true;
    }
Example #5
0
        private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)
        {
            Test(classifier != null);
            if (classifier != null)
            {
                Log.Debug("TestVisualRecognition", "Classifier {0} found! Classifier name: {1}", classifier.classifier_id, classifier.name);
            }

            m_GetClassifierTested = true;
        }
 private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
 {
     if (classifier != null)
     {
         Log.Debug("ExampleVisualRecognition", "Classifier is training! " + classifier);
     }
     else
     {
         Log.Debug("ExampleVisualRecognition", "Failed to train classifier!");
     }
 }
 private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
 {
     if (classifier != null)
     {
         Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierID + " found! Classifier name: " + classifier.name);
     }
     else
     {
         Log.Debug("ExampleVisualRecognition", "Failed to find classifier by ID!");
     }
 }
 private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
 {
     if (classifier != null)
     {
         Log.Debug("ExampleVisualRecognition", "Classifier " + m_classifierName + " found! ClassifierID: " + classifier.classifier_id);
     }
     else
     {
         Log.Debug("ExampleVisualRecognition", "Failed to find classifier by name!");
     }
 }
Example #9
0
 private void OnDeleteClassifierFinal(GetClassifiersPerClassifierVerbose classifier)
 {
     if (classifier == null)
     {
         Log.Debug("TestVisualRecognition", "Classifier not found! Delete sucessful!");
     }
     else
     {
         Log.Debug("TestVisualRecognition", "Classifier {0} found! Delete failed!", classifier.name);
     }
 }
Example #10
0
        private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, string customData)
        {
            Test(classifier != null);
            if (classifier != null)
            {
                Log.Status("TestVisualRecognition", "Classifier ID: {0}, Classifier name: {1}, Status: {2}", classifier.classifier_id, classifier.name, classifier.status);
                //  store classifier id
                m_ClassifierId = classifier.classifier_id;
            }

            m_TrainClasifierTested = true;
        }
Example #11
0
        private bool ContainsClass(GetClassifiersPerClassifierVerbose result, string classname)
        {
            bool containsClass = false;

            foreach (ModelClass _class in result.Classes)
            {
                if (_class._Class == classname)
                    containsClass = true;
            }

            return containsClass;
        }
Example #12
0
        private void OnCheckUpdatedClassifierStatus(GetClassifiersPerClassifierVerbose classifier, string customData = default(string))
        {
            Log.Debug("TestVisualRecognition", "classifier {0} is {1}!", classifier.classifier_id, classifier.status);

            if (classifier.status == "retraining")
            {
                CheckClassifierStatus(OnCheckUpdatedClassifierStatus);
            }
            else if (classifier.status == "ready")
            {
                m_IsUpdatedClassifierReady = true;
            }
        }
Example #13
0
        public GetClassifiersPerClassifierVerbose UpdateClassifier(string classifierId, Dictionary <string, byte[]> positiveExamplesData = null, byte[] negativeExamplesData = null)
        {
            GetClassifiersPerClassifierVerbose result = null;

            if (string.IsNullOrEmpty(classifierId))
            {
                throw new ArgumentNullException(nameof(classifierId));
            }

            if (positiveExamplesData == null && negativeExamplesData == null)
            {
                throw new ArgumentNullException("Positive example data and/or negative example data are required to update a classifier.");
            }

            try
            {
                var formData = new MultipartFormDataContent();

                if (positiveExamplesData != null)
                {
                    foreach (var kvp in positiveExamplesData)
                    {
                        var positiveExampleDataContent = new ByteArrayContent(kvp.Value);
                        positiveExampleDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/zip");
                        formData.Add(positiveExampleDataContent, string.Format("{0}_positive_examples", kvp.Key), string.Format("{0}_positive_examples.zip", kvp.Key));
                    }
                }

                if (negativeExamplesData != null)
                {
                    var negativeExamplesDataContent = new ByteArrayContent(negativeExamplesData);
                    negativeExamplesDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/zip");
                    formData.Add(negativeExamplesDataContent, "negative_examples", "negative_examples.zip");
                }

                result = this.Client.PostAsync($"{ this.Endpoint}{string.Format(PATH_CLASSIFIER, classifierId)}")
                         .WithArgument("version", VERSION_DATE_2016_05_20)
                         .WithArgument("api_key", ApiKey)
                         .WithBodyContent(formData)
                         .WithFormatter(new MediaTypeHeaderValue("application/octet-stream"))
                         .As <GetClassifiersPerClassifierVerbose>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Example #14
0
        private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier, string customData)
        {
            Test(classifier != null);
            if (classifier != null)
            {
                Log.Debug("TestVisualRecognition", "Classifier {0} found! Classifier name: {1}", classifier.classifier_id, classifier.name);
                foreach (Class classifierClass in classifier.classes)
                {
                    if (classifierClass.m_Class == m_ClassName_Turtle)
                    {
                        m_HasUpdatedClassifier = true;
                    }
                }
            }

            m_GetClassifierTested = true;
        }
Example #15
0
        private void OnUpdateClassifier(GetClassifiersPerClassifierVerbose classifier, string customData)
        {
            if (classifier != null)
            {
                Log.Status("TestVisualRecognition", "Classifier ID: {0}, Classifier name: {1}, Status: {2}", classifier.classifier_id, classifier.name, classifier.status);
                foreach (Class classifierClass in classifier.classes)
                {
                    if (classifierClass.m_Class == m_ClassName_Turtle)
                    {
                        m_HasUpdatedClassifier = true;
                    }
                }
                //  store classifier id
                //m_ClassifierId = classifier.classifier_id;
            }

            m_UpdateClassifierTested = true;
        }
Example #16
0
 private void OnCheckClassifierStatus(GetClassifiersPerClassifierVerbose classifier, string customData)
 {
     Log.Debug("TestVisualRecognition", "classifier {0} is {1}!", classifier.classifier_id, classifier.status);
     if (classifier.status == "unavailable" || classifier.status == "failed")
     {
         Log.Debug("TestVisualRecognition", "Deleting classifier!");
         //  classifier failed - delete!
         if (!m_VisualRecognition.DeleteClassifier(OnCheckClassifierStatusDelete, classifier.classifier_id))
         {
             Log.Debug("TestVisualRecognition", "Failed to delete classifier {0}!", m_ClassifierId);
         }
     }
     else if (classifier.status == "training")
     {
         CheckClassifierStatus(OnCheckClassifierStatus);
     }
     else if (classifier.status == "ready")
     {
         m_IsClassifierReady = true;
         m_ClassifierId      = classifier.classifier_id;
     }
 }
Example #17
0
        private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier, string customData)
        {
            if (classifier != null)
            {
                Log.Status("TestVisualRecognition", "Find Result, Classifier ID: {0}, Status: {1}", classifier.classifier_id, classifier.status);
                if (classifier.status == "ready")
                {
                    m_TrainClassifier   = false;
                    m_IsClassifierReady = true;
                    m_ClassifierId      = classifier.classifier_id;
                }
                else
                {
                    m_TrainClassifier = false;
                }
            }
            else
            {
                m_TrainClassifier = true;
            }

            m_FindClassifierTested = true;
        }
Example #18
0
 private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier, Dictionary <string, object> customData)
 {
     Log.Debug("ExampleVisualRecognition.OnGetClassifier()", "VisualRecognition - GetClassifier Response: {0}", customData["json"].ToString());
     _getClassifierTested = true;
 }
 private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
 {
     Log.Debug("ExampleVisualRecognition", "VisualRecognition - GetClassifier Response: {0}", data);
     Test(classifier != null);
     _getClassifierTested = true;
 }