Пример #1
0
                public override void Run(InnerProgram program)
                {
                    ////string test = @"Z:\Test\Classification2\Data\t95_r285_q954_test.txt";
                    ////string source = @"Z:\Test\Classification2\Data\Gerber_test.txt";
                    ////string truth = @"Z:\Test\Classification2\Data\t95_r285_q954_truth.txt";
                    ////string truth = @"Z:\Test\Classification2\Data\Gerber_truth.txt";

                    PointsOfInterestClassifier classifier = null;

                    program.Test(classifier, this.Source, this.Truth);
                }
Пример #2
0
            private PointsOfInterestClassifier Learn(string sourcePath, string truthPath)
            {
                this.WriteLine(null, "Learning...");

                PointsOfInterestClassifier classifier = new PointsOfInterestClassifier();

                using (DirectoryDataProvider dataProvider = new DirectoryDataProvider())
                {
                    dataProvider.Add(sourcePath, false, truthPath, "#Class");

                    ClassifierProgress <TestImage> progress = new ClassifierProgress <TestImage>(
                        (source, index) =>
                    {
                        this.StopwatchRestart();
                    },
                        (source, index, answer, exception) =>
                    {
                        long duration = this.StopwatchStop();
                        Interlocked.Increment(ref this.totalImages);

                        this.Write(
                            null,
                            "({0})\tFile: {1} ... ",
                            index,
                            source.SourceId.ToFileName(false));

                        if (exception != null)
                        {
                            this.WriteLine(null, "ERROR.");
                            this.WriteException(null, exception);
                        }
                        else
                        {
                            this.WriteLine(null, "OK ({0} ms)", duration);
                        }
                    });

                    classifier.Train <TestImage>(
                        dataProvider.Generate(null),
                        (x, cancellationToken) => new ImageSource(x.SourceId, x.Image),
                        x => string.Concat(x.Labels),
                        progress,
                        CancellationToken.None);
                }

                return(classifier);
            }
Пример #3
0
            private void Test(PointsOfInterestClassifier classifier, string sourcePath, string truthPath)
            {
                this.WriteLine(null, "Testing...");

                List <ClassificationResult <string> > results = new List <ClassificationResult <string> >();

                using (DirectoryDataProvider dataProvider = new DirectoryDataProvider())
                {
                    dataProvider.Add(sourcePath, false, truthPath, "#Class");

                    ClassifierProgress <TestImage> progress = new ClassifierProgress <TestImage>(
                        (source, index) =>
                    {
                        this.StopwatchRestart();
                    },
                        (source, index, answer, exception) =>
                    {
                        long duration = this.StopwatchStop();
                        Interlocked.Increment(ref this.totalImages);

                        this.Write(
                            null,
                            "({0})\tFile: {1} ... ",
                            index,
                            source.SourceId.ToFileName(false));

                        if (exception != null)
                        {
                            this.WriteLine(null, "ERROR.");
                            this.WriteException(null, exception);
                        }
                        else
                        {
                            this.WriteLine(
                                null,
                                "OK ({0} ms) {1} {2:F4}",
                                duration,
                                answer?.ClassName ?? string.Empty,
                                answer?.Confidence ?? 0.0);
                        }
                    });

                    foreach ((TestImage image, Answer answer) in classifier.Classify <TestImage>(
                                 dataProvider.Generate(null),
                                 (x, cancellationToken) => new ImageSource(x.SourceId, x.Image),
                                 progress,
                                 CancellationToken.None))
                    {
                        results.Add(new ClassificationResult <string>(
                                        answer.Id,
                                        answer.ClassName,
                                        string.Concat(image.Labels),
                                        answer.Confidence,
                                        answer.Confidence >= 0.2f));
                    }
                }

                // write report
                ClassificationReport <string> testReport = new ClassificationReport <string>(results);

                using (StreamWriter outputFile = new StreamWriter(Console.OpenStandardOutput()))
                ////using (StreamWriter outputFile = File.CreateText(this.options.OutputFileName))
                {
                    ClassificationReportWriter <string> .WriteReport(outputFile, testReport, ClassificationReportMode.All);
                }
            }