/// <summary> /// for other params, <see>AbstractProgram</see> /// </summary> /// <param name="classifier">The classifier to train and to evalaute</param> /// <param name="testIndexName">index files that link each image in the test set</param> public ConsoleCompetitionOutput(string tomatoDirPath, string indexFileName, SplitStrategy split, TomatoClassifier classifier, string testIndexName) : base(tomatoDirPath, indexFileName, split) { this.indexName = testIndexName; this.classifier = classifier; }
/// <summary> /// /// </summary> /// <param name="tomatoSets"> /// The tomato set divided into training and validation. /// In the training set, the classificator learns the svm params. /// The classifier predicts label on the validation set. /// </param> public Controller( IDictionary <SetType, List <Tomato> > tomatoSets) { this.images = new List <VisualEvent>(); imageExtractor = new LBPExtractor(true); imageExtractor.VisualEventManager += OnImageComputed; classifier = new TomatoClassifier(new LBPExtractor(false), SVMClassifier.Linear(0.43f)); this.tomatoSets = tomatoSets; }
/* * for each prediction, this method create a line following this schema: * {image_name} {label} {score} */ private List <string> ExportClassificationResult(TomatoClassifier classifier, List <Tomato> testTomatoes) { var classifiedResult = new List <string>(); log.LogNewLine("compute label on test images.."); foreach (Tomato tomato in testTomatoes) { var score = 0.0; var res = classifier.Classify(tomato.ColoredImage, tomato.GrayImage1, tomato.GrayImage2, out score); classifiedResult.Add(tomato.Name + " " + (int)res + " " + score); } return(classifiedResult); }
/* * this method eval the classifier performance in the validation set. * the metrics used are: * - precision; * - recall; * - accuracy; * - confusion matrix. */ private void EvalPerformance(TomatoClassifier classifier, List <Tomato> tomatoes) { var falsePositive = 0.0; var falseNegative = 0.0; var truePositive = 0.0; var trueNegative = 0.0; log.LogNewLine("eval..."); stopWatch.Restart(); foreach (Tomato tomato in tomatoes) { log.Log("."); double score = 0; var predicted = classifier.Classify(tomato.ColoredImage, tomato.GrayImage1, tomato.GrayImage2, out score); if (predicted == (int)tomato.Type) { var updated = predicted == (int)(TomatoType.BAD) ? trueNegative++ : truePositive++; } else { var updated = predicted == (int)(TomatoType.BAD) ? falseNegative++ : falsePositive++; } } stopWatch.Stop(); log.LogNewLine(""); log.LogNewLine("predict " + tomatoes.Count / stopWatch.Elapsed.Seconds + " tomatoes per second"); log.LogNewLine("ends.."); log.LogNewLine("precision : " + truePositive / (truePositive + falsePositive)); log.LogNewLine("recall : " + truePositive / (truePositive + falseNegative)); log.LogNewLine("accuracy : " + (truePositive + trueNegative) / tomatoes.Count); log.LogNewLine("-- CONFUSION MATRIX --"); log.LogNewLine("BAD\t" + trueNegative + "\t" + falseNegative); log.LogNewLine("OK \t" + falsePositive + "\t" + truePositive); log.LogNewLine(" \tBAD\tOK"); log.LogNewLine("..."); }
private void Train(TomatoClassifier classifier, List <Tomato> tomatoes) { var adapted = TomatoSetHelper.Expand(tomatoes); classifier.Train(adapted.Item1, adapted.Item2, adapted.Item3, adapted.Item4); }