public async Task TrainingOps(bool labeled, bool useTokenCredential) { var client = CreateFormTrainingClient(useTokenCredential); var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl); TrainingOperation operation = await client.StartTrainingAsync(trainingFilesUri, labeled); await operation.WaitForCompletionAsync(PollingInterval); Assert.IsTrue(operation.HasValue); CustomFormModel trainedModel = operation.Value; CustomFormModel resultModel = await client.GetCustomModelAsync(trainedModel.ModelId); Assert.AreEqual(trainedModel.ModelId, resultModel.ModelId); Assert.AreEqual(trainedModel.Properties.IsComposedModel, resultModel.Properties.IsComposedModel); Assert.AreEqual(trainedModel.TrainingStartedOn, resultModel.TrainingStartedOn); Assert.AreEqual(trainedModel.TrainingCompletedOn, resultModel.TrainingCompletedOn); Assert.AreEqual(CustomFormModelStatus.Ready, resultModel.Status); Assert.AreEqual(trainedModel.Status, resultModel.Status); Assert.AreEqual(trainedModel.Errors.Count, resultModel.Errors.Count); for (int i = 0; i < resultModel.TrainingDocuments.Count; i++) { var tm = trainedModel.TrainingDocuments[i]; var rm = resultModel.TrainingDocuments[i]; Assert.AreEqual(tm.Name, rm.Name); Assert.AreEqual(tm.ModelId, rm.ModelId); Assert.AreEqual(tm.PageCount, rm.PageCount); Assert.AreEqual(TrainingStatus.Succeeded, rm.Status); Assert.AreEqual(tm.Status, rm.Status); Assert.AreEqual(tm.Errors.Count, rm.Errors.Count); } for (int i = 0; i < resultModel.Submodels.Count; i++) { Assert.AreEqual(trainedModel.Submodels[i].FormType, resultModel.Submodels[i].FormType); Assert.AreEqual(trainedModel.Submodels[i].ModelId, resultModel.Submodels[i].ModelId); foreach (var fields in resultModel.Submodels[i].Fields) { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Name, fields.Value.Name); if (labeled) { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Accuracy, fields.Value.Accuracy); } else { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Label, fields.Value.Label); } } } CustomFormModelInfo modelInfo = client.GetCustomModelsAsync().ToEnumerableAsync().Result.FirstOrDefault(); Assert.IsNotNull(modelInfo.ModelId); Assert.IsNotNull(modelInfo.TrainingStartedOn); Assert.IsNotNull(modelInfo.TrainingCompletedOn); Assert.IsNotNull(modelInfo.Status); Assert.IsNotNull(modelInfo.Properties); AccountProperties accountP = await client.GetAccountPropertiesAsync(); Assert.IsNotNull(accountP.CustomModelCount); Assert.IsNotNull(accountP.CustomModelLimit); await client.DeleteModelAsync(trainedModel.ModelId); RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(() => client.GetCustomModelAsync(trainedModel.ModelId)); Assert.AreEqual("1022", ex.ErrorCode); }
public async Task TrainingOps(bool labeled) { var client = CreateInstrumentedFormTrainingClient(); var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl); TrainingOperation operation; // TODO: sanitize body and enable body recording here. using (Recording.DisableRequestBodyRecording()) { operation = await client.StartTrainingAsync(trainingFilesUri, labeled); } await operation.WaitForCompletionAsync(); Assert.IsTrue(operation.HasValue); CustomFormModel trainedModel = operation.Value; CustomFormModel resultModel = await client.GetCustomModelAsync(trainedModel.ModelId); Assert.AreEqual(trainedModel.ModelId, resultModel.ModelId); Assert.AreEqual(trainedModel.RequestedOn, resultModel.RequestedOn); Assert.AreEqual(trainedModel.CompletedOn, resultModel.CompletedOn); Assert.AreEqual(CustomFormModelStatus.Ready, resultModel.Status); Assert.AreEqual(trainedModel.Status, resultModel.Status); Assert.AreEqual(trainedModel.Errors.Count, resultModel.Errors.Count); for (int i = 0; i < resultModel.TrainingDocuments.Count; i++) { var tm = trainedModel.TrainingDocuments[i]; var rm = resultModel.TrainingDocuments[i]; Assert.AreEqual(tm.DocumentName, rm.DocumentName); Assert.AreEqual(tm.PageCount, rm.PageCount); Assert.AreEqual(TrainingStatus.Succeeded, rm.Status); Assert.AreEqual(tm.Status, rm.Status); Assert.AreEqual(tm.Errors.Count, rm.Errors.Count); } for (int i = 0; i < resultModel.Submodels.Count; i++) { Assert.AreEqual(trainedModel.Submodels[i].FormType, resultModel.Submodels[i].FormType); foreach (var fields in resultModel.Submodels[i].Fields) { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Name, fields.Value.Name); if (labeled) { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Accuracy, fields.Value.Accuracy); } else { Assert.AreEqual(trainedModel.Submodels[i].Fields[fields.Key].Label, fields.Value.Label); } } } CustomFormModelInfo modelInfo = client.GetCustomModelsAsync().ToEnumerableAsync().Result.FirstOrDefault(); Assert.IsNotNull(modelInfo.ModelId); Assert.IsNotNull(modelInfo.RequestedOn); Assert.IsNotNull(modelInfo.CompletedOn); Assert.IsNotNull(modelInfo.Status); AccountProperties accountP = await client.GetAccountPropertiesAsync(); Assert.IsNotNull(accountP.CustomModelCount); Assert.IsNotNull(accountP.CustomModelLimit); await client.DeleteModelAsync(trainedModel.ModelId); Assert.ThrowsAsync <RequestFailedException>(() => client.GetCustomModelAsync(trainedModel.ModelId)); }
public async Task TrainingOps(bool labeled) { var client = CreateInstrumentedClient(); TrainingOperation operation = await client.StartTrainingAsync(_containerUri, labeled); await operation.WaitForCompletionAsync(); Assert.IsTrue(operation.HasValue); CustomFormModel trainedModel = operation.Value; CustomFormModel resultModel = await client.GetCustomModelAsync(trainedModel.ModelId); Assert.AreEqual(trainedModel.ModelId, resultModel.ModelId); Assert.AreEqual(trainedModel.CreatedOn, resultModel.CreatedOn); Assert.AreEqual(trainedModel.LastModified, resultModel.LastModified); Assert.AreEqual(CustomFormModelStatus.Ready, resultModel.Status); Assert.AreEqual(trainedModel.Status, resultModel.Status); Assert.AreEqual(trainedModel.Errors.Count, resultModel.Errors.Count); for (int i = 0; i < resultModel.TrainingDocuments.Count; i++) { var tm = trainedModel.TrainingDocuments[i]; var rm = resultModel.TrainingDocuments[i]; Assert.AreEqual(tm.DocumentName, rm.DocumentName); Assert.AreEqual(tm.PageCount, rm.PageCount); Assert.AreEqual(TrainingStatus.Succeeded, rm.Status); Assert.AreEqual(tm.Status, rm.Status); Assert.AreEqual(tm.Errors.Count, rm.Errors.Count); } for (int i = 0; i < resultModel.Models.Count; i++) { Assert.AreEqual(trainedModel.Models[i].FormType, resultModel.Models[i].FormType); foreach (var fields in resultModel.Models[i].Fields) { Assert.AreEqual(trainedModel.Models[i].Fields[fields.Key].Name, fields.Value.Name); if (labeled) { Assert.AreEqual(trainedModel.Models[i].Fields[fields.Key].Accuracy, fields.Value.Accuracy); } else { Assert.AreEqual(trainedModel.Models[i].Fields[fields.Key].Label, fields.Value.Label); } } } CustomFormModelInfo modelInfo = client.GetModelInfosAsync().ToEnumerableAsync().Result.FirstOrDefault(); Assert.IsNotNull(modelInfo.ModelId); Assert.IsNotNull(modelInfo.CreatedOn); Assert.IsNotNull(modelInfo.LastModified); Assert.IsNotNull(modelInfo.Status); AccountProperties accountP = await client.GetAccountPropertiesAsync(); Assert.IsNotNull(accountP.CustomModelCount); Assert.IsNotNull(accountP.CustomModelLimit); await client.DeleteModelAsync(trainedModel.ModelId); Assert.ThrowsAsync <RequestFailedException>(() => client.GetCustomModelAsync(trainedModel.ModelId)); }
public async Task CopyModel() { #region Snippet:FormRecognizerSampleCreateCopySourceClientV3 #if SNIPPET string sourceEndpoint = "<source_endpoint>"; string sourceApiKey = "<source_apiKey>"; #else string sourceEndpoint = TestEnvironment.Endpoint; string sourceApiKey = TestEnvironment.ApiKey; #endif var sourcecredential = new AzureKeyCredential(sourceApiKey); var sourceClient = new FormTrainingClient(new Uri(sourceEndpoint), sourcecredential); #endregion // For the purpose of this sample, we are going to create a trained model to copy. Please note that // if you already have a model, this is not necessary. #if SNIPPET Uri trainingFileUri = new Uri("<trainingFileUri>"); #else Uri trainingFileUri = new Uri(TestEnvironment.BlobContainerSasUrlV2); #endif TrainingOperation operation = await sourceClient.StartTrainingAsync(trainingFileUri, useTrainingLabels : false); Response <CustomFormModel> operationResponse = await operation.WaitForCompletionAsync(); CustomFormModel model = operationResponse.Value; #region Snippet:FormRecognizerSampleCreateCopyTargetClientV3 #if SNIPPET string targetEndpoint = "<target_endpoint>"; string targetApiKey = "<target_apiKey>"; #else string targetEndpoint = TestEnvironment.Endpoint; string targetApiKey = TestEnvironment.ApiKey; #endif var targetCredential = new AzureKeyCredential(targetApiKey); var targetClient = new FormTrainingClient(new Uri(targetEndpoint), targetCredential); #endregion #region Snippet:FormRecognizerSampleGetCopyAuthorizationV3 #if SNIPPET string resourceId = "<resourceId>"; string resourceRegion = "<region>"; #else string resourceId = TestEnvironment.TargetResourceId; string resourceRegion = TestEnvironment.TargetResourceRegion; #endif CopyAuthorization targetAuth = await targetClient.GetCopyAuthorizationAsync(resourceId, resourceRegion); #endregion #region Snippet:FormRecognizerSampleToJson string jsonTargetAuth = targetAuth.ToJson(); #endregion #region Snippet:FormRecognizerSampleFromJson CopyAuthorization targetCopyAuth = CopyAuthorization.FromJson(jsonTargetAuth); #endregion #region Snippet:FormRecognizerSampleCopyModel #if SNIPPET string modelId = "<source_modelId>"; #else string modelId = model.ModelId; #endif CustomFormModelInfo newModel = await sourceClient.StartCopyModelAsync(modelId, targetCopyAuth).WaitForCompletionAsync(); Console.WriteLine($"Original model ID => {modelId}"); Console.WriteLine($"Copied model ID => {newModel.ModelId}"); #endregion }
internal Model(CustomFormModelInfo modelInfo, KeysResult keys, TrainResult trainResult) { ModelInfo = modelInfo; Keys = keys; TrainResult = trainResult; }