Search in sources :

Example 96 with Model

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

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

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

the class ListModels method listModels.

// List the models available in the specified location
static void listModels(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Create list models request.
        ListModelsRequest listModelsRequest = ListModelsRequest.newBuilder().setParent(projectLocation.toString()).setFilter("").build();
        // List all the models available in the region by applying filter.
        System.out.println("List of models:");
        for (Model model : client.listModels(listModelsRequest).iterateAll()) {
            // 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 : Model(com.google.cloud.automl.v1.Model) ListModelsRequest(com.google.cloud.automl.v1.ListModelsRequest) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 99 with Model

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

the class TranslatePredict method predict.

static void predict(String projectId, String modelId, String filePath) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, "us-central1", modelId);
        String content = new String(Files.readAllBytes(Paths.get(filePath)));
        TextSnippet textSnippet = TextSnippet.newBuilder().setContent(content).build();
        ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build();
        PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build();
        PredictResponse response = client.predict(predictRequest);
        TextSnippet translatedContent = response.getPayload(0).getTranslation().getTranslatedContent();
        System.out.format("Translated Content: %s\n", translatedContent.getContent());
    }
}
Also used : ModelName(com.google.cloud.automl.v1.ModelName) TextSnippet(com.google.cloud.automl.v1.TextSnippet) PredictResponse(com.google.cloud.automl.v1.PredictResponse) ExamplePayload(com.google.cloud.automl.v1.ExamplePayload) PredictRequest(com.google.cloud.automl.v1.PredictRequest) PredictionServiceClient(com.google.cloud.automl.v1.PredictionServiceClient)

Example 100 with Model

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

the class UndeployModel method undeployModel.

// Undeploy a model from prediction
static void undeployModel(String projectId, String modelId) 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 model.
        ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
        UndeployModelRequest request = UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
        OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(request);
        future.get();
        System.out.println("Model undeployment finished");
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1.ModelName) UndeployModelRequest(com.google.cloud.automl.v1.UndeployModelRequest) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Aggregations

Test (org.junit.Test)51 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)25 ModelName (com.google.cloud.automl.v1.ModelName)24 Model (com.google.cloud.aiplatform.v1.Model)16 Model (com.google.cloud.automl.v1.Model)16 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 LocationName (com.google.cloud.aiplatform.v1.LocationName)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)14 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)14 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)14 InputDataConfig (com.google.cloud.aiplatform.v1.InputDataConfig)13 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)13 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)12 FilterSplit (com.google.cloud.aiplatform.v1.FilterSplit)11 FractionSplit (com.google.cloud.aiplatform.v1.FractionSplit)11 PredefinedSplit (com.google.cloud.aiplatform.v1.PredefinedSplit)11 TimestampSplit (com.google.cloud.aiplatform.v1.TimestampSplit)11 Status (com.google.rpc.Status)11 Model (com.microsoft.z3.Model)11