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 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);
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)); }
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); }