Exemplo n.º 1
0
        public async void ImageCounts()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "ImageCounts", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var taggedImageCount = await client.GetTaggedImageCountAsync(project.ProjectId);

                    Assert.Equal(10, taggedImageCount);

                    var untaggedImageCount = await client.GetUntaggedImageCountAsync(project.ProjectId);

                    Assert.Equal(0, untaggedImageCount);

                    var iterationId    = (await client.GetIterationsAsync(project.ProjectId))[0].Id;
                    var imagePerfCount = await client.GetImagePerformanceCountAsync(project.ProjectId, iterationId);

                    Assert.Equal(2, imagePerfCount);
                }
            }
        }
Exemplo n.º 2
0
        public async void ObjDetectionPrediction()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "ObjDetectionPrediction", RecorderMode);

                using (var project = CreateTrainedObjDetectionProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                        using (FileStream stream = new FileStream(Path.Combine("TestImages", "od_test_image.jpg"), FileMode.Open))
                        {
                            var imageResult = await client.QuickTestImageAsync(project.ProjectId, stream, project.IterationId);

                            Assert.NotEqual(Guid.Empty, imageResult.Id);
                            Assert.NotEqual(Guid.Empty, imageResult.Iteration);
                            Assert.Equal(project.ProjectId, imageResult.Project);
                            Assert.NotEqual(0, imageResult.Predictions.Count);
                            Assert.InRange(imageResult.Predictions[0].Probability, 0.5, 1);
                            Assert.NotNull(imageResult.Predictions[0].BoundingBox);
                            Assert.InRange(imageResult.Predictions[0].BoundingBox.Left, 0, 1);
                            Assert.InRange(imageResult.Predictions[0].BoundingBox.Top, 0, 1);
                            Assert.InRange(imageResult.Predictions[0].BoundingBox.Width, 0, 1);
                            Assert.InRange(imageResult.Predictions[0].BoundingBox.Height, 0, 1);
                        }
            }
        }
Exemplo n.º 3
0
        public async void QuickTests()
        {
            var dataFileName = "test_image.jpg";

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "QuickTests", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                    {
                        using (FileStream stream = new FileStream(Path.Combine("TestImages", dataFileName), FileMode.Open))
                        {
                            var imageResult = await client.QuickTestImageAsync(project.ProjectId, stream, project.IterationId);

                            Assert.NotEqual(Guid.Empty, imageResult.Id);
                            Assert.NotEqual(Guid.Empty, imageResult.Iteration);
                            Assert.Equal(project.ProjectId, imageResult.Project);
                            Assert.NotEqual(0, imageResult.Predictions.Count);
                            Assert.InRange(imageResult.Predictions[0].Probability, 0.9, 1);
                            Assert.Equal("Tag1", imageResult.Predictions[0].TagName);
                        }

                        string imageUrl  = "https://raw.githubusercontent.com/Microsoft/Cognitive-CustomVision-Windows/master/Samples/Images/Test/test_image.jpg";
                        var    urlResult = await client.QuickTestImageUrlAsync(project.ProjectId, new ImageUrl(imageUrl), project.IterationId);

                        Assert.NotEqual(Guid.Empty, urlResult.Id);
                        Assert.NotEqual(Guid.Empty, urlResult.Iteration);
                        Assert.Equal(project.ProjectId, urlResult.Project);
                        Assert.NotEqual(0, urlResult.Predictions.Count);
                        Assert.InRange(urlResult.Predictions[0].Probability, 0.9, 1);
                        Assert.Equal("Tag1", urlResult.Predictions[0].TagName);
                    }
            }
        }
Exemplo n.º 4
0
        public async void ImageTagManipulation()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "ImageTagManipulation", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var untaggedImages = client.GetUntaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(0, untaggedImages.Count);

                    var taggedImages = client.GetTaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(10, taggedImages.Count);

                    var imageToBeModified = taggedImages[0].Id;
                    var tagToBeModified   = taggedImages[0].Tags[0].TagId;

                    await client.DeleteImageTagsAsync(project.ProjectId, new Guid[] { imageToBeModified }, new Guid[] { tagToBeModified });

                    untaggedImages = client.GetUntaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(1, untaggedImages.Count);

                    var imageTags = new ImageTagCreateEntry(imageToBeModified, tagToBeModified);
                    var result    = client.CreateImageTagsAsync(project.ProjectId, new ImageTagCreateBatch(new ImageTagCreateEntry[] { imageTags })).Result;

                    Assert.Equal(1, result.Created.Count);
                    Assert.Equal(imageToBeModified, result.Created[0].ImageId);
                    Assert.Equal(tagToBeModified, result.Created[0].TagId);
                }
            }
        }
Exemplo n.º 5
0
        public async void ExportTests()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "ExportTests", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject(ProjectBuilderHelper.ExportableDomain))
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var iterations = await client.GetIterationsAsync(project.ProjectId);

                    var exportableIteration = iterations.FirstOrDefault(e => e.Exportable);
                    Assert.NotNull(exportableIteration);

                    var export = await client.ExportIterationAsync(project.ProjectId, exportableIteration.Id, ExportPlatform.TensorFlow);

                    Assert.Equal("Exporting", export.Status);
                    Assert.Null(export.DownloadUri);
                    Assert.Equal(ExportPlatform.TensorFlow, export.Platform);
                    Assert.False(export.NewerVersionAvailable);

                    while (export.Status != "Done")
                    {
                        var exports = await client.GetExportsAsync(project.ProjectId, exportableIteration.Id);

                        Assert.Equal(1, exports.Count);
                        export = exports.Where(e => e.Platform == ExportPlatform.TensorFlow).FirstOrDefault();
                        Assert.NotNull(export);
                        Thread.Sleep(1000);
                    }
                    Assert.NotEmpty(export.DownloadUri);
                }
            }
        }
Exemplo n.º 6
0
        public async void GetIterationPerformance()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "GetIterationPerformance", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var iterations = await client.GetIterationsAsync(project.ProjectId);

                    Assert.True(iterations.Count > 0);

                    var iterationPerf = await client.GetIterationPerformanceAsync(project.ProjectId, iterations[iterations.Count - 1].Id, 0.9);

                    Assert.Equal(1, iterationPerf.Recall);
                    Assert.Equal(0, iterationPerf.RecallStdDeviation);
                    Assert.Equal(1, iterationPerf.Precision);
                    Assert.Equal(0, iterationPerf.PrecisionStdDeviation);
                    Assert.Equal(2, iterationPerf.PerTagPerformance.Count);
                    Assert.Equal("Tag1", iterationPerf.PerTagPerformance[0].Name);
                    Assert.Equal(1, iterationPerf.PerTagPerformance[0].Recall);
                    Assert.Equal(0, iterationPerf.PerTagPerformance[0].RecallStdDeviation);
                    Assert.Equal(1, iterationPerf.PerTagPerformance[0].Precision);
                    Assert.Equal(0, iterationPerf.PerTagPerformance[0].PrecisionStdDeviation);
                    Assert.Equal("Tag2", iterationPerf.PerTagPerformance[1].Name);
                    Assert.Equal(1, iterationPerf.PerTagPerformance[1].Recall);
                    Assert.Equal(0, iterationPerf.PerTagPerformance[1].RecallStdDeviation);
                    Assert.Equal(1, iterationPerf.PerTagPerformance[1].Precision);
                    Assert.Equal(0, iterationPerf.PerTagPerformance[1].PrecisionStdDeviation);
                }
            }
        }
Exemplo n.º 7
0
        public async void GetImagesByIds()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "GetImagesByIds", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var tags = await client.GetTagsAsync(project.ProjectId);

                    var imagesForTag = await client.GetTaggedImagesAsync(project.ProjectId, null, new List <Guid>(new Guid[] { tags[0].Id }));

                    Assert.Equal(5, imagesForTag.Count);

                    var images = await client.GetImagesByIdsAsync(project.ProjectId, imagesForTag.Select(img => img.Id).ToList());

                    Assert.Equal(5, images.Count);

                    foreach (var image in images)
                    {
                        Assert.Equal(1, image.Tags.Count);
                        var tag = image.Tags[0];
                        Assert.Equal(tags[0].Id, tag.TagId);
                        Assert.Equal(tags[0].Name, tag.TagName);
                        Assert.NotNull(image.ThumbnailUri);
                        Assert.NotEmpty(image.OriginalImageUri);
                        Assert.NotEmpty(image.ResizedImageUri);
                        Assert.True(image.Width > 0);
                        Assert.True(image.Height > 0);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public async void QueryPredictionResults()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "QueryPredictionResults", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var token = new PredictionQueryToken()
                    {
                        OrderBy = "Newest",
                    };
                    var result = await client.QueryPredictionsAsync(project.ProjectId, token);

                    Assert.NotEqual(0, result.Results.Count);
                    foreach (var prediction in result.Results)
                    {
                        Assert.Equal(project.ProjectId, prediction.Project);
                        Assert.NotEqual(Guid.Empty, prediction.Id);
                        Assert.NotEqual(Guid.Empty, prediction.Iteration);
                        Assert.NotEmpty(prediction.ThumbnailUri);
                        Assert.NotEmpty(prediction.OriginalImageUri);
                        Assert.NotEmpty(prediction.ResizedImageUri);

                        Assert.NotEqual(0, prediction.Predictions.Count);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public async void QuerySuggestedImageCount()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "QuerySuggestedImageCount", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                    {
                        // Add an untagged image we expect to be classified as tag1
                        var images = new ImageFileCreateEntry[] {
                            new ImageFileCreateEntry("suggest_ic.jpg", File.ReadAllBytes(Path.Combine("TestImages", "suggest_ic.jpg")))
                        };
                        var imageResult = await client.CreateImagesFromFilesAsync(project.ProjectId, new ImageFileCreateBatch(images));

                        Assert.True(imageResult.IsBatchSuccessful);
                        Assert.Equal(1, imageResult.Images.Count);

                        // Ask for suggestions
                        var suggestions = client.SuggestTagsAndRegions(project.ProjectId, project.IterationId, new Guid[] { imageResult.Images[0].Image.Id });

                        // Validate result
                        Assert.Equal(1, suggestions.Count);

                        var tags = await client.GetTagsAsync(project.ProjectId, project.IterationId);

                        // We expect to get Tag1 as the primary suggestion, so query with a high prediction
                        var countMapping = await client.QuerySuggestedImageCountAsync(project.ProjectId, project.IterationId, new TagFilter()
                        {
                            Threshold = 0.75,
                            TagIds    = new Guid[] { tags[0].Id }
                        });

                        Assert.Equal(1, countMapping.Count);
                        Assert.Equal(1, countMapping[tags[0].Id.ToString()]);

                        // We expect to get Tag2 to have a low probabilty, make sure we don't find it with a high threshold
                        countMapping = await client.QuerySuggestedImageCountAsync(project.ProjectId, project.IterationId, new TagFilter()
                        {
                            Threshold = 0.75,
                            TagIds    = new Guid[] { tags[1].Id }
                        });

                        Assert.Equal(1, countMapping.Count);
                        Assert.Equal(0, countMapping[tags[1].Id.ToString()]);

                        // Get results for all tags with a high threshold.
                        countMapping = await client.QuerySuggestedImageCountAsync(project.ProjectId, project.IterationId, new TagFilter()
                        {
                            Threshold = 0.75,
                            TagIds    = tags.Select(t => t.Id).ToList()
                        });

                        Assert.Equal(2, countMapping.Count);
                        Assert.Equal(1, countMapping[tags[0].Id.ToString()]);
                        Assert.Equal(0, countMapping[tags[1].Id.ToString()]);
                    }
            }
        }
Exemplo n.º 10
0
        public async void RegionManipulation()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "RegionManipulation", RecorderMode);

                using (var project = CreateTrainedObjDetectionProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                    {
                        var existingImage = (await client.GetTaggedImagesAsync(project.ProjectId)).First();
                        Assert.NotNull(existingImage);

                        var testTag = await client.CreateTagAsync(project.ProjectId, tagName);

                        var proposal = await client.GetImageRegionProposalsAsync(project.ProjectId, existingImage.Id);

                        Assert.True(proposal.Proposals.Count > 0);
                        Assert.Equal(project.ProjectId, proposal.ProjectId);
                        Assert.Equal(existingImage.Id, proposal.ImageId);
                        Assert.InRange(proposal.Proposals[0].Confidence, 0, 1);

                        var bbox = proposal.Proposals[0].BoundingBox;
                        List <ImageRegionCreateEntry> newRegions = new List <ImageRegionCreateEntry>();
                        newRegions.Add(new ImageRegionCreateEntry(existingImage.Id, testTag.Id, bbox.Left, bbox.Top, bbox.Width, bbox.Height));

                        var regions = await client.CreateImageRegionsAsync(project.ProjectId, new ImageRegionCreateBatch(newRegions));

                        Assert.Equal(1, regions.Created.Count);
                        Assert.Equal(0, regions.Duplicated.Count);
                        Assert.Equal(0, regions.Exceeded.Count);
                        Assert.Equal(bbox.Top, regions.Created[0].Top);
                        Assert.Equal(bbox.Left, regions.Created[0].Left);
                        Assert.Equal(bbox.Width, regions.Created[0].Width);
                        Assert.Equal(bbox.Height, regions.Created[0].Height);
                        Assert.Equal(existingImage.Id, regions.Created[0].ImageId);
                        Assert.Equal(testTag.Id, regions.Created[0].TagId);
                        Assert.NotEqual(Guid.Empty, regions.Created[0].RegionId);

                        var image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id }));

                        Assert.Equal(1, image.Count);
                        Assert.Equal(2, image[0].Regions.Count);

                        await client.DeleteImageRegionsAsync(project.ProjectId, new List <Guid>(new Guid[] { regions.Created[0].RegionId }));

                        image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id }));

                        Assert.Equal(1, image.Count);
                        Assert.Equal(1, image[0].Regions.Count);

                        await client.DeleteTagAsync(project.ProjectId, testTag.Id);
                    }
            }
        }
Exemplo n.º 11
0
        public void Dispose()
        {
#if RECORD_MODE
            ICustomVisionTrainingClient client = BaseTests.GetTrainingClient(false);

            foreach (var iter in client.GetIterations(this.ProjectId))
            {
                if (!string.IsNullOrEmpty(iter.PublishName))
                {
                    client.UnpublishIteration(this.ProjectId, iter.Id);
                }
            }
            client.DeleteProject(this.ProjectId);
#endif
        }
Exemplo n.º 12
0
        public async void GetUntaggedImages()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "GetUntaggedImages", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var images = await client.GetUntaggedImagesAsync(project.ProjectId);

                    Assert.Equal(0, images.Count);
                }
            }
        }
Exemplo n.º 13
0
        public async void TrainAndPublishProject()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "TrainAndPublishProject", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    // Remove the last trained iteration so we can retrain
                    var iterationToDelete = client.GetIteration(project.ProjectId, project.IterationId);

                    var originalPublishName = iterationToDelete.PublishName;
                    await client.UnpublishIterationAsync(project.ProjectId, iterationToDelete.Id);

                    await client.DeleteIterationAsync(project.ProjectId, iterationToDelete.Id);

                    // Need to ensure we wait 1 second between training calls from the previous project.Or
                    // We get 429s.
                    Thread.Sleep(1000);
                    var trainedIteration = await client.TrainProjectAsync(project.ProjectId);

                    Assert.NotEqual(iterationToDelete.Name, trainedIteration.Name);
                    Assert.NotEqual(iterationToDelete.Id, trainedIteration.Id);
                    Assert.NotEqual(Guid.Empty, trainedIteration.Id);
                    Assert.True("Staging" == trainedIteration.Status || "Training" == trainedIteration.Status);
                    Assert.False(trainedIteration.Exportable);
                    Assert.Null(trainedIteration.PublishName);

                    // Wait for training to complete.
                    while (trainedIteration.Status != "Completed")
                    {
                        Thread.Sleep(1000);
                        trainedIteration = client.GetIteration(project.ProjectId, trainedIteration.Id);
                    }

                    // Verify we can republish using same name
                    Assert.True(client.PublishIteration(project.ProjectId, trainedIteration.Id, originalPublishName, BaseTests.PredictionResourceId));
                    project.IterationId = trainedIteration.Id;
                }
            }
        }
Exemplo n.º 14
0
        public async void QuerySuggestedImages()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "QuerySuggestedImages", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                    {
                        // Add an untagged image we expect to be classified as tag1
                        var images = new ImageFileCreateEntry[] {
                            new ImageFileCreateEntry("suggest_ic.jpg", File.ReadAllBytes(Path.Combine("TestImages", "suggest_ic.jpg")))
                        };
                        var imageResult = await client.CreateImagesFromFilesAsync(project.ProjectId, new ImageFileCreateBatch(images));

                        Assert.True(imageResult.IsBatchSuccessful);
                        Assert.Equal(1, imageResult.Images.Count);

                        // Ask for suggestions
                        var suggestions = client.SuggestTagsAndRegions(project.ProjectId, project.IterationId, new Guid[] { imageResult.Images[0].Image.Id });

                        // Validate result
                        Assert.Equal(1, suggestions.Count);

                        // Get tags and build a query
                        var tags = await client.GetTagsAsync(project.ProjectId, project.IterationId);

                        var query = new SuggestedTagAndRegionQueryToken()
                        {
                            MaxCount  = 10,
                            TagIds    = tags.Select(t => t.Id).ToList(),
                            Threshold = 0
                        };

                        // This will return all suggested images (1 in this case)
                        var suggestedImages = await client.QuerySuggestedImagesAsync(project.ProjectId, project.IterationId, query);

                        Assert.Equal(1, suggestedImages.Results.Count);
                    }
            }
        }
Exemplo n.º 15
0
        public async void SuggestTagAndRegions()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "SuggestTagAndRegions", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                    using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                    {
                        // Add an untagged image we expect to be classified as tag1
                        var images = new ImageFileCreateEntry[] {
                            new ImageFileCreateEntry("suggest_ic.jpg", File.ReadAllBytes(Path.Combine("TestImages", "suggest_ic.jpg")))
                        };
                        var imageResult = await client.CreateImagesFromFilesAsync(project.ProjectId, new ImageFileCreateBatch(images));

                        Assert.True(imageResult.IsBatchSuccessful);
                        Assert.Equal(1, imageResult.Images.Count);

                        // Ask for suggestions
                        var suggestions = client.SuggestTagsAndRegions(project.ProjectId, project.IterationId, new Guid[] { imageResult.Images[0].Image.Id });

                        // Validate result
                        Assert.Equal(1, suggestions.Count);
                        Assert.Equal(project.ProjectId, suggestions[0].Project);
                        Assert.Equal(project.IterationId, suggestions[0].Iteration);
                        Assert.NotEqual(0, suggestions[0].Predictions.Count);

                        foreach (var prediction in suggestions[0].Predictions)
                        {
                            var tag = await client.GetTagAsync(project.ProjectId, prediction.TagId, project.IterationId);

                            Assert.Equal(tag.Name, prediction.TagName);
                            Assert.Equal(tag.Id, prediction.TagId);
                            Assert.InRange(prediction.Probability, 0, 1);
                        }

                        // We expect Tag1 to have the highest probability
                        Assert.Equal("Tag1", suggestions[0].Predictions.OrderByDescending(p => p.Probability).First().TagName);
                    }
            }
        }
Exemplo n.º 16
0
        public async void GetIterations()
        {
            var updatedName = "New Iteration Name";

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "GetIterations", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var iterations = await client.GetIterationsAsync(project.ProjectId);

                    Assert.Equal(1, iterations.Count);
                    Assert.NotEmpty(iterations[0].Name);
                    Assert.NotEqual(Guid.Empty, iterations[0].DomainId);
                    Assert.NotEqual(Guid.Empty, iterations[0].Id);
                    Assert.Equal(project.ProjectId, iterations[0].ProjectId);
                    Assert.Equal("Completed", iterations[0].Status);
                    Assert.False(iterations[0].Exportable);

                    var iteration = await client.GetIterationAsync(project.ProjectId, iterations[0].Id);

                    Assert.Equal(iteration.Name, iterations[0].Name);
                    Assert.Equal(iteration.Id, iterations[0].Id);
                    Assert.Equal(TrainingType.Regular, iteration.TrainingType);
                    Assert.Equal(0, iteration.ReservedBudgetInHours);
                    Assert.NotEmpty(iteration.PublishName);
                    Assert.Equal(1, iteration.TrainingTimeInMinutes);
                    Assert.Equal(BaseTests.PredictionResourceId, iteration.OriginalPublishResourceId);

                    var updatedIteration = await client.UpdateIterationAsync(project.ProjectId, iteration.Id, new Iteration()
                    {
                        Name = updatedName
                    });

                    Assert.Equal(updatedName, updatedIteration.Name);
                }
            }
        }
Exemplo n.º 17
0
        public async void CreateImagesFromPredictions()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "CreateImagesFromPredictions", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    string imageUrl         = "https://raw.githubusercontent.com/Microsoft/Cognitive-CustomVision-Windows/master/Samples/Images/Test/test_image.jpg";
                    var    predictionResult = await client.QuickTestImageUrlAsync(project.ProjectId, new ImageUrl(imageUrl), project.IterationId);

                    var i      = new ImageIdCreateEntry[] { new ImageIdCreateEntry(predictionResult.Id) };
                    var result = await client.CreateImagesFromPredictionsAsync(project.ProjectId, new ImageIdCreateBatch(i));

                    Assert.Equal(1, result.Images.Count);
                    Assert.NotEmpty(result.Images[0].SourceUrl);
                }
            }
        }
Exemplo n.º 18
0
        public async void DeletePrediction()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DeletePrediction", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var token = new PredictionQueryToken()
                    {
                        OrderBy = "Newest",
                    };
                    var result = client.QueryPredictionsAsync(project.ProjectId, token).Result;
                    Assert.NotEqual(0, result.Results.Count);

                    await client.DeletePredictionAsync(project.ProjectId, new Guid[] { result.Results[result.Results.Count - 1].Id });
                }
            }
        }
Exemplo n.º 19
0
        public async void DeleteImages()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DeleteImages", RecorderMode);

                using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient())
                {
                    var projectId = (await client.CreateProjectAsync(projName)).Id;

                    string imageUrl  = "https://raw.githubusercontent.com/Microsoft/Cognitive-CustomVision-Windows/master/Samples/Images/Test/test_image.jpg";
                    var    urlImages = new ImageUrlCreateEntry[] { new ImageUrlCreateEntry(imageUrl) };
                    var    result    = client.CreateImagesFromUrlsAsync(projectId, new ImageUrlCreateBatch(urlImages)).Result;
                    Assert.True(result.IsBatchSuccessful);
                    Assert.Equal(1, result.Images.Count);

                    await client.DeleteImagesAsync(projectId, new Guid[] { result.Images[0].Image.Id });

                    await client.DeleteProjectAsync(projectId);
                }
            }
        }
Exemplo n.º 20
0
        public async void DownloadRegions()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "DownloadRegions", RecorderMode);

                using (var project = CreateTrainedObjDetectionProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var images = await client.GetTaggedImagesAsync(project.ProjectId);

                    foreach (var img in images)
                    {
                        Assert.NotNull(img.Regions);
                        Assert.Equal(1, img.Regions.Count);
                        Assert.InRange(img.Regions[0].Left, 0, 1);
                        Assert.InRange(img.Regions[0].Top, 0, 1);
                        Assert.InRange(img.Regions[0].Width, 0, 1);
                        Assert.InRange(img.Regions[0].Height, 0, 1);
                    }
                }
            }
        }