public async Task ModelEvaluationRequestShouldBeSuccessful() { /* * Create a model. */ string modelID = GenerateRandomID(); ClarifaiResponse <ConceptModel> createModelResponse = await Client.CreateModel( modelID, concepts : new List <Concept> { new Concept("celeb"), new Concept("cat"), }) .ExecuteAsync(); AssertResponseSuccess(createModelResponse); /* * Add inputs associated with concepts. */ ClarifaiResponse <List <IClarifaiInput> > addInputsResponse = await Client.AddInputs( new ClarifaiURLImage(CELEB1, positiveConcepts : new List <Concept> { new Concept("celeb") }, allowDuplicateUrl : true), new ClarifaiURLImage(CAT1, positiveConcepts : new List <Concept> { new Concept("cat") }, allowDuplicateUrl : true) ).ExecuteAsync(); AssertResponseSuccess(addInputsResponse); await WaitForSpecificInputsUpload(addInputsResponse.Get().Select(i => i.ID).ToArray()); /* * Train the model. */ await Client.TrainModel <Concept>(modelID).ExecuteAsync(); /* * Wait until the model has finished training. */ int count = 0; string modelVersionID = null; while (true) { count++; if (count == 20) { Assert.Fail("Model training has not finished in the allotted time."); } ClarifaiResponse <IModel <Concept> > response = await Client.GetModel <Concept>(modelID).ExecuteAsync(); modelVersionID = response.Get().ModelVersion.ID; ModelTrainingStatus status = response.Get().ModelVersion.Status; if (status.IsTerminalEvent()) { if (status.StatusCode == ModelTrainingStatus.Trained.StatusCode) { break; } Assert.Fail("The model was not trained successfully: " + status.StatusCode); } Thread.Sleep(1000); } /* * Start model evaluation. */ ClarifaiResponse <ModelVersion> evalResponse = await Client.ModelEvaluation( modelID, modelVersionID) .ExecuteAsync(); AssertResponseSuccess(evalResponse); Assert.NotNull(evalResponse.Get().ModelMetricsStatus); }
public async Task ShorthandTrainingModelShouldBeSuccessful() { /* * Create a model. */ string modelID = GenerateRandomID(); var createModelResponse = await Client.CreateModel( modelID, concepts : new List <Concept> { new Concept("celeb"), new Concept("cat"), }) .ExecuteAsync(); ConceptModel model = createModelResponse.Get(); /* * Add inputs associated with concepts. */ ClarifaiResponse <List <IClarifaiInput> > addInputsResponse = await Client.AddInputs( new ClarifaiURLImage(CELEB1, positiveConcepts : new List <Concept> { new Concept("celeb") }, allowDuplicateUrl : true), new ClarifaiURLImage(CAT1, positiveConcepts : new List <Concept> { new Concept("cat") }, allowDuplicateUrl : true) ).ExecuteAsync(); if (addInputsResponse.Status.Type != ClarifaiStatus.StatusType.Successful) { Assert.Fail("Adding inputs not successful: " + addInputsResponse.Status.Type); } /* * Train the model. */ await model.TrainModel().ExecuteAsync(); /* * Wait until the model has finished training. */ int count = 0; while (true) { count++; if (count == 20) { Assert.Fail("Model training has not finished in the allotted time."); } ClarifaiResponse <IModel <Concept> > response = await Client.GetModel <Concept>(modelID).ExecuteAsync(); ModelTrainingStatus status = response.Get().ModelVersion.Status; if (status.IsTerminalEvent()) { if (status.StatusCode == ModelTrainingStatus.Trained.StatusCode) { return; } Assert.Fail("The model was not trained successfully: " + status.StatusCode); } Thread.Sleep(1000); } }