Search in sources :

Example 1 with ModelEvaluation

use of com.google.cloud.automl.v1.ModelEvaluation in project java-automl by googleapis.

the class AutoMlClientTest method listModelEvaluationsTest2.

@Test
public void listModelEvaluationsTest2() throws Exception {
    ModelEvaluation responsesElement = ModelEvaluation.newBuilder().build();
    ListModelEvaluationsResponse expectedResponse = ListModelEvaluationsResponse.newBuilder().setNextPageToken("").addAllModelEvaluation(Arrays.asList(responsesElement)).build();
    mockAutoMl.addResponse(expectedResponse);
    String parent = "parent-995424086";
    String filter = "filter-1274492040";
    ListModelEvaluationsPagedResponse pagedListResponse = client.listModelEvaluations(parent, filter);
    List<ModelEvaluation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getModelEvaluationList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListModelEvaluationsRequest actualRequest = ((ListModelEvaluationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListModelEvaluationsPagedResponse(com.google.cloud.automl.v1.AutoMlClient.ListModelEvaluationsPagedResponse) Test(org.junit.Test)

Example 2 with ModelEvaluation

use of com.google.cloud.automl.v1.ModelEvaluation in project java-automl by googleapis.

the class ListModelEvaluations method listModelEvaluations.

// List model evaluations
static void listModelEvaluations(String projectId, String modelId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model.
        ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
        ListModelEvaluationsRequest modelEvaluationsrequest = ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
        // List all the model evaluations in the model by applying filter.
        System.out.println("List of model evaluations:");
        for (ModelEvaluation modelEvaluation : client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
            System.out.format("Model Evaluation Name: %s\n", modelEvaluation.getName());
            System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
            System.out.println("Create Time:");
            System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds());
            System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
            System.out.format("Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount());
            // [END automl_language_sentiment_analysis_list_model_evaluations]
            // [END automl_language_text_classification_list_model_evaluations]
            // [END automl_translate_list_model_evaluations]
            // [END automl_vision_classification_list_model_evaluations]
            // [END automl_vision_object_detection_list_model_evaluations]
            System.out.format("Entity Extraction Model Evaluation Metrics: %s\n", modelEvaluation.getTextExtractionEvaluationMetrics());
            // [END automl_language_entity_extraction_list_model_evaluations]
            // [START automl_language_sentiment_analysis_list_model_evaluations]
            System.out.format("Sentiment Analysis Model Evaluation Metrics: %s\n", modelEvaluation.getTextSentimentEvaluationMetrics());
            // [END automl_language_sentiment_analysis_list_model_evaluations]
            // [START automl_language_text_classification_list_model_evaluations]
            // [START automl_vision_classification_list_model_evaluations]
            System.out.format("Classification Model Evaluation Metrics: %s\n", modelEvaluation.getClassificationEvaluationMetrics());
            // [END automl_language_text_classification_list_model_evaluations]
            // [END automl_vision_classification_list_model_evaluations]
            // [START automl_translate_list_model_evaluations]
            System.out.format("Translate Model Evaluation Metrics: %s\n", modelEvaluation.getTranslationEvaluationMetrics());
            // [END automl_translate_list_model_evaluations]
            // [START automl_vision_object_detection_list_model_evaluations]
            System.out.format("Object Detection Model Evaluation Metrics: %s\n", modelEvaluation.getImageObjectDetectionEvaluationMetrics());
        // [START automl_language_entity_extraction_list_model_evaluations]
        // [START automl_language_sentiment_analysis_list_model_evaluations]
        // [START automl_language_text_classification_list_model_evaluations]
        // [START automl_translate_list_model_evaluations]
        // [START automl_vision_classification_list_model_evaluations]
        }
    }
}
Also used : ModelEvaluation(com.google.cloud.automl.v1.ModelEvaluation) ModelName(com.google.cloud.automl.v1.ModelName) ListModelEvaluationsRequest(com.google.cloud.automl.v1.ListModelEvaluationsRequest) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 3 with ModelEvaluation

use of com.google.cloud.automl.v1.ModelEvaluation in project java-automl by googleapis.

the class GetModelEvaluationTest method setUp.

@Before
public void setUp() throws IOException {
    // Get a model evaluation ID from the List request first to be used in the Get call
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
        ListModelEvaluationsRequest modelEvaluationsrequest = ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
        ModelEvaluation modelEvaluation = client.listModelEvaluations(modelEvaluationsrequest).getPage().getValues().iterator().next();
        modelEvaluationId = modelEvaluation.getName().split("/modelEvaluations/")[1];
    }
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
}
Also used : PrintStream(java.io.PrintStream) ModelEvaluation(com.google.cloud.automl.v1.ModelEvaluation) ModelName(com.google.cloud.automl.v1.ModelName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ListModelEvaluationsRequest(com.google.cloud.automl.v1.ListModelEvaluationsRequest) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 4 with ModelEvaluation

use of com.google.cloud.automl.v1.ModelEvaluation in project java-automl by googleapis.

the class GetModelEvaluation method getModelEvaluation.

// Get a model evaluation
static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model evaluation.
        ModelEvaluationName modelEvaluationFullId = ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId);
        // Get complete detail of the model evaluation.
        ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId);
        System.out.format("Model Evaluation Name: %s\n", modelEvaluation.getName());
        System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
        System.out.println("Create Time:");
        System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds());
        System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
        System.out.format("Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount());
        // [END automl_language_sentiment_analysis_get_model_evaluation]
        // [END automl_language_text_classification_get_model_evaluation]
        // [END automl_translate_get_model_evaluation]
        // [END automl_vision_classification_get_model_evaluation]
        // [END automl_vision_object_detection_get_model_evaluation]
        System.out.format("Entity Extraction Model Evaluation Metrics: %s\n", modelEvaluation.getTextExtractionEvaluationMetrics());
        // [END automl_language_entity_extraction_get_model_evaluation]
        // [START automl_language_sentiment_analysis_get_model_evaluation]
        System.out.format("Sentiment Analysis Model Evaluation Metrics: %s\n", modelEvaluation.getTextSentimentEvaluationMetrics());
        // [END automl_language_sentiment_analysis_get_model_evaluation]
        // [START automl_language_text_classification_get_model_evaluation]
        // [START automl_vision_classification_get_model_evaluation]
        System.out.format("Classification Model Evaluation Metrics: %s\n", modelEvaluation.getClassificationEvaluationMetrics());
        // [END automl_language_text_classification_get_model_evaluation]
        // [END automl_vision_classification_get_model_evaluation]
        // [START automl_translate_get_model_evaluation]
        System.out.format("Translate Model Evaluation Metrics: %s\n", modelEvaluation.getTranslationEvaluationMetrics());
        // [END automl_translate_get_model_evaluation]
        // [START automl_vision_object_detection_get_model_evaluation]
        System.out.format("Object Detection Model Evaluation Metrics: %s\n", modelEvaluation.getImageObjectDetectionEvaluationMetrics());
    // [START automl_language_entity_extraction_get_model_evaluation]
    // [START automl_language_sentiment_analysis_get_model_evaluation]
    // [START automl_language_text_classification_get_model_evaluation]
    // [START automl_translate_get_model_evaluation]
    // [START automl_vision_classification_get_model_evaluation]
    }
}
Also used : ModelEvaluationName(com.google.cloud.automl.v1.ModelEvaluationName) ModelEvaluation(com.google.cloud.automl.v1.ModelEvaluation) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 5 with ModelEvaluation

use of com.google.cloud.automl.v1.ModelEvaluation in project java-automl by googleapis.

the class ListModelEvaluations method listModelEvaluations.

// List model evaluations
static void listModelEvaluations(String projectId, String modelId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the model.
        ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
        ListModelEvaluationsRequest modelEvaluationsrequest = ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
        // List all the model evaluations in the model by applying filter.
        System.out.println("List of model evaluations:");
        for (ModelEvaluation modelEvaluation : client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
            System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
            System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
            System.out.println("Create Time:");
            System.out.format("\tseconds: %s%n", modelEvaluation.getCreateTime().getSeconds());
            System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
            System.out.format("Evalution Example Count: %d%n", modelEvaluation.getEvaluatedExampleCount());
            System.out.format("Tables Model Evaluation Metrics: %s%n", modelEvaluation.getClassificationEvaluationMetrics());
        }
    }
}
Also used : ModelEvaluation(com.google.cloud.automl.v1beta1.ModelEvaluation) ModelName(com.google.cloud.automl.v1beta1.ModelName) ListModelEvaluationsRequest(com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Aggregations

AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)3 ModelEvaluation (com.google.cloud.automl.v1.ModelEvaluation)3 ListModelEvaluationsPagedResponse (com.google.cloud.automl.v1.AutoMlClient.ListModelEvaluationsPagedResponse)2 ListModelEvaluationsRequest (com.google.cloud.automl.v1.ListModelEvaluationsRequest)2 ModelName (com.google.cloud.automl.v1.ModelName)2 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)2 ModelEvaluation (com.google.cloud.automl.v1beta1.ModelEvaluation)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ModelEvaluationName (com.google.cloud.automl.v1.ModelEvaluationName)1 ListModelEvaluationsRequest (com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest)1 ModelEvaluationName (com.google.cloud.automl.v1beta1.ModelEvaluationName)1 ModelName (com.google.cloud.automl.v1beta1.ModelName)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Before (org.junit.Before)1