Search in sources :

Example 61 with AutoMlClient

use of com.google.cloud.automl.v1.AutoMlClient 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 62 with AutoMlClient

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

the class DeleteDataset method deleteDataset.

// Delete a dataset
static void deleteDataset(String projectId, String datasetId) throws IOException, ExecutionException, InterruptedException {
    // 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 dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        Empty response = client.deleteDatasetAsync(datasetFullId).get();
        System.out.format("Dataset deleted. %s%n", response);
    }
}
Also used : Empty(com.google.protobuf.Empty) DatasetName(com.google.cloud.automl.v1beta1.DatasetName) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 63 with AutoMlClient

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

the class GetModel method getModel.

// Get a model
static void getModel(String projectId, String modelId) throws IOException, StatusRuntimeException {
    // 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);
        Model model = client.getModel(modelFullId);
        // Display the model information.
        System.out.format("Model name: %s%n", model.getName());
        // To get the model id, you have to parse it out of the `name` field. As models Ids are
        // required for other methods.
        // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}`
        String[] names = model.getName().split("/");
        String retrievedModelId = names[names.length - 1];
        System.out.format("Model id: %s%n", retrievedModelId);
        System.out.format("Model display name: %s%n", model.getDisplayName());
        System.out.println("Model create time:");
        System.out.format("\tseconds: %s%n", model.getCreateTime().getSeconds());
        System.out.format("\tnanos: %s%n", model.getCreateTime().getNanos());
        System.out.format("Model deployment state: %s%n", model.getDeploymentState());
    }
}
Also used : ModelName(com.google.cloud.automl.v1beta1.ModelName) Model(com.google.cloud.automl.v1beta1.Model) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 64 with AutoMlClient

use of com.google.cloud.automl.v1.AutoMlClient 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_video_object_tracking_get_model_evaluation_beta]
        System.out.format("Classification Model Evaluation Metrics: %s%n", modelEvaluation.getClassificationEvaluationMetrics());
        // [END automl_video_classification_get_model_evaluation_beta]
        // [START automl_video_object_tracking_get_model_evaluation_beta]
        System.out.format("Video Object Tracking Evaluation Metrics: %s%n", modelEvaluation.getVideoObjectTrackingEvaluationMetrics());
    // [START automl_video_classification_get_model_evaluation_beta]
    }
}
Also used : ModelEvaluationName(com.google.cloud.automl.v1beta1.ModelEvaluationName) ModelEvaluation(com.google.cloud.automl.v1beta1.ModelEvaluation) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 65 with AutoMlClient

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

the class GetOperationStatus method getOperationStatus.

// Get the status of an operation
static void getOperationStatus(String operationFullId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the latest state of a long-running operation.
        Operation operation = client.getOperationsClient().getOperation(operationFullId);
        // Display operation details.
        System.out.println("Operation details:");
        System.out.format("\tName: %s%n", operation.getName());
        System.out.format("\tMetadata Type Url: %s%n", operation.getMetadata().getTypeUrl());
        System.out.format("\tDone: %s%n", operation.getDone());
        if (operation.hasResponse()) {
            System.out.format("\tResponse Type Url: %s%n", operation.getResponse().getTypeUrl());
        }
        if (operation.hasError()) {
            System.out.println("\tResponse:");
            System.out.format("\t\tError code: %s%n", operation.getError().getCode());
            System.out.format("\t\tError message: %s%n", operation.getError().getMessage());
        }
    }
}
Also used : Operation(com.google.longrunning.Operation) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Aggregations

AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)41 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)31 Empty (com.google.protobuf.Empty)20 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)18 LocationName (com.google.cloud.automl.v1.LocationName)17 Model (com.google.cloud.automl.v1.Model)16 ModelName (com.google.cloud.automl.v1.ModelName)16 LocationName (com.google.cloud.automl.v1beta1.LocationName)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 PrintStream (java.io.PrintStream)12 Before (org.junit.Before)12 ModelName (com.google.cloud.automl.v1beta1.ModelName)11 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)11 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 Dataset (com.google.cloud.automl.v1.Dataset)8 Model (com.google.cloud.automl.v1beta1.Model)8 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 Operation (com.google.longrunning.Operation)6 DatasetName (com.google.cloud.automl.v1.DatasetName)5 DatasetName (com.google.cloud.automl.v1beta1.DatasetName)5