コード例 #1
0
        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();
        }
コード例 #2
0
        public async void ImageClassifierServiceSmokeTest()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("TestData/appsettings.json", optional: false, reloadOnChange: true);
            var factory = new ImageClassifierFactory();

            using var service = new ImageClassifierService(new NullLogger <ImageClassifierService>(), factory,
                                                           configuration.Build());
            await service.StartAsync(default);
コード例 #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));
        }
コード例 #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);
        }