/* * 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); }
public void CheckPerformance() { this.images.Clear(); View.ClearImages(); log.LogNewLine("eval starts.."); Train(classifier, tomatoSets[SetType.TRANING]); foreach (Tomato tomato in tomatoSets[SetType.VALIDATION]) { log.Log("."); double score = 0; var result = classifier.Classify(tomato.ColoredImage, tomato.GrayImage1, tomato.GrayImage2, out score); if (result != (int)tomato.Type) { this.images.Add(new VisualEvent("WRONG! expeted : " + tomato.Type, tomato.ColoredImage.ToBitmap())); //this makes process extraction visualization possible: imageExtractor.ExtractDescriptor(tomato.ColoredImage, tomato.GrayImage1, tomato.GrayImage2, (int)tomato.Type); } } log.LogNewLine(""); View.AddImages(this.images); }
/* * 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("..."); }