private IEnumerator Examples() { // Get all classifiers Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiersBrief(OnGetClassifiers, OnFail)) { Log.Debug("ExampleVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("ExampleVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("ExampleVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif // Classify get Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("ExampleVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif _visualRecognition.DownloadCoreMLModel(_classifierID, _coreMLDownloadPath); while (!_getCoreMLModelTested) { yield return(null); } Log.Debug("ExampleVisualRecognition.Examples()", "Visual Recogition tests complete"); }