Exemplo n.º 1
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.º 2
0
        public static async Task <TrainingModels::Export> ExportIteration(
            this ICustomVisionTrainingClient trainingApi, Guid projectId, Guid iterationId, string flavor = "onnx12", int timeoutInSecond = 30)
        {
            TimeSpan timeout = TimeSpan.FromSeconds(timeoutInSecond);

            TrainingModels::Export exportIteration = null;

            try
            {
                exportIteration = exportIteration = string.IsNullOrEmpty(flavor)
                    ? await trainingApi.ExportIterationAsync(projectId, iterationId, platform)
                    : await trainingApi.ExportIterationAsync(projectId, iterationId, platform, flavor);
            }
            catch (HttpOperationException ex)
            {
                string exceptionContent = ex?.Response?.Content ?? string.Empty;
                if (!exceptionContent.Contains("BadRequestExportAlreadyInProgress"))
                {
                    throw ex;
                }
            }

            DateTime startTime = DateTime.Now;

            while (true)
            {
                IList <TrainingModels::Export> exports = await trainingApi.GetExportsAsync(projectId, iterationId);

                exportIteration = string.IsNullOrEmpty(flavor)
                    ? exports?.FirstOrDefault(x => string.Equals(x.Platform, platform, StringComparison.OrdinalIgnoreCase))
                    : exports?.FirstOrDefault(x => string.Equals(x.Platform, platform, StringComparison.OrdinalIgnoreCase) &&
                                              string.Equals(x.Flavor, flavor, StringComparison.OrdinalIgnoreCase));

                if (exportIteration?.Status == "Exporting")
                {
                    await Task.Delay(1000);
                }
                else
                {
                    break;
                }

                if (DateTime.Now - startTime > timeout)
                {
                    throw new TimeoutException("The operation couldn't be completed due to a timeout.");
                }
            }

            return(exportIteration);
        }
Exemplo n.º 3
0
        public static async Task <TrainingModels::Export> ExportIteration(this ICustomVisionTrainingClient trainingApi, Guid projectId, Guid iterationId, int timeoutInSecond = 30)
        {
            TimeSpan timeout = TimeSpan.FromSeconds(timeoutInSecond);

            TrainingModels::Export exportIteration = null;

            try
            {
                exportIteration = await trainingApi.ExportIterationAsync(projectId, iterationId, platform);
            }
            catch (TrainingModels::CustomVisionErrorException ex)
            {
                if (ex.Body.Code != TrainingModels::CustomVisionErrorCodes.BadRequestExportAlreadyInProgress)
                {
                    throw ex;
                }
            }

            DateTime startTime = DateTime.Now;

            while (true)
            {
                IList <TrainingModels::Export> exports = await trainingApi.GetExportsAsync(projectId, iterationId);

                exportIteration = exports?.FirstOrDefault(x => string.Equals(x.Platform, platform, StringComparison.OrdinalIgnoreCase));

                if (exportIteration?.Status == "Exporting")
                {
                    await Task.Delay(1000);
                }
                else
                {
                    break;
                }

                if (DateTime.Now - startTime > timeout)
                {
                    throw new TimeoutException("The operation couldn't be completed due to a timeout.");
                }
            }

            return(exportIteration);
        }