public async void ImageClassifierWorkerPoolSmokeTest()
        {
            var configuration = new ImageClassifierConfiguration
            {
                ClassifierType = "MNISTClassifier",
                ImageHeight    = 28, ImageWidth = 28,
                Labels         = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                PathToModel    = "TestData/traced_model.pt"
            };
            var factory = new ImageClassifierFactory();
            var pool    = new ImageClassifierWorkerPool(factory, configuration, 5);

            using var source = new CancellationTokenSource();
            await pool.StartWorkers(source.Token);

            var image   = Image.FromFile("TestData/seven.png");
            var results = new List <Task <string> >();

            for (var i = 0; i < 100; i++)
            {
                results.Add(pool.Classify(image));
            }

            var labels = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

            foreach (var taskResult in results)
            {
                Assert.Contains(await taskResult, labels);
            }

            source.Cancel();
            await pool.StopWorkers();
        }
        public void ModelNotLoadedExceptionThrownTest()
        {
            var configuration = new ImageClassifierConfiguration
            {
                ImageHeight = 28, ImageWidth = 28,
                Labels      = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                PathToModel = "TestData/not_exist.pt"
            };
            var classifier = new MnistImageClassifier(configuration);

            Assert.Throws <ModelNotLoadedException>(() => classifier.LoadModel());
        }
Exemplo n.º 3
0
        public void UnknowClassifierTypeExceptionThrownTest()
        {
            var configuration = new ImageClassifierConfiguration
            {
                ClassifierType = "Unknown",
                ImageHeight    = 28, ImageWidth = 28,
                Labels         = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                PathToModel    = "TestData/traced_model.pt"
            };
            var factory = new ImageClassifierFactory();

            Assert.Throws <UnknownClassifierTypeException>(() => factory.GetClassifier(configuration));
        }
Exemplo n.º 4
0
        public void SmokeTestClassifierFactory()
        {
            var configuration = new ImageClassifierConfiguration
            {
                ClassifierType = "MNISTClassifier",
                ImageHeight    = 28, ImageWidth = 28,
                Labels         = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                PathToModel    = "TestData/traced_model.pt"
            };
            var factory    = new ImageClassifierFactory();
            var classifier = factory.GetClassifier(configuration);

            Assert.IsType <MnistImageClassifier>(classifier);
        }
        public void RecognizeNumberTest()
        {
            var configuration = new ImageClassifierConfiguration
            {
                ImageHeight = 28, ImageWidth = 28,
                Labels      = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                PathToModel = "TestData/traced_model.pt"
            };
            var classifier = new MnistImageClassifier(configuration);

            classifier.LoadModel();
            var image = Image.FromFile("TestData/seven.png");
            var label = classifier.ClassifyImage(image);

            Assert.Contains(label, configuration.Labels);
        }
Exemplo n.º 6
0
        public async Task SmokeTestWorkers()
        {
            using var cancellationTokenSource = new CancellationTokenSource();
            var workers = new List <IImageClassifierWorker>();

            for (var i = 0; i < 5; ++i)
            {
                var configuration = new ImageClassifierConfiguration
                {
                    ImageHeight = 28, ImageWidth = 28,
                    Labels      = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
                    PathToModel = "TestData/traced_model.pt"
                };
                var classifier = new MnistImageClassifier(configuration);
                var worker     = new ImageClassifierWorker(classifier);
                await worker.StartWorker(cancellationTokenSource.Token);

                workers.Add(worker);
            }

            var image   = Image.FromFile("TestData/seven.png");
            var results = new List <Task <string> >();

            foreach (var worker in workers)
            {
                for (var i = 0; i < 10; i++)
                {
                    results.Add(worker.Classify(image));
                }
            }

            var labels = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

            foreach (var taskResult in results)
            {
                Assert.Contains(await taskResult, labels);
            }

            cancellationTokenSource.Cancel();
            foreach (var worker in workers)
            {
                worker.StopWorker();
            }
        }