Search in sources :

Example 11 with ModelName

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

the class ObjectDetectionDeployModelNodeCount method objectDetectionDeployModelNodeCount.

static void objectDetectionDeployModelNodeCount(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);
        // Set how many nodes the model is deployed on
        ImageObjectDetectionModelDeploymentMetadata deploymentMetadata = ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageObjectDetectionModelDeploymentMetadata(deploymentMetadata).build();
        // Deploy the model
        OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
        future.get();
        System.out.println("Model deployment on 2 nodes finished");
    }
}
Also used : DeployModelRequest(com.google.cloud.automl.v1beta1.DeployModelRequest) Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1beta1.ModelName) ImageObjectDetectionModelDeploymentMetadata(com.google.cloud.automl.v1beta1.ImageObjectDetectionModelDeploymentMetadata) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 12 with ModelName

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

the class DeployModel method deployModel.

// Deploy a model for prediction
static void deployModel(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);
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
        OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
        future.get();
        System.out.println("Model deployment finished");
    }
}
Also used : DeployModelRequest(com.google.cloud.automl.v1.DeployModelRequest) Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1.ModelName) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 13 with ModelName

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

the class TablesGetModel method getModel.

// Demonstrates using the AutoML client to get model details.
public static void getModel(String projectId, String computeRegion, 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, computeRegion, modelId);
        // Get complete detail of the model.
        Model model = client.getModel(modelFullId);
        // Display the model information.
        System.out.format("Model name: %s%n", model.getName());
        System.out.format("Model Id: %s\n", model.getName().split("/")[model.getName().split("/").length - 1]);
        System.out.format("Model display name: %s%n", model.getDisplayName());
        System.out.format("Dataset Id: %s%n", model.getDatasetId());
        System.out.println("Tables Model Metadata: ");
        System.out.format("\tTraining budget: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
        System.out.format("\tTraining cost: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        String createTime = dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
        System.out.format("Model create time: %s%n", createTime);
        System.out.format("Model deployment state: %s%n", model.getDeploymentState());
        // Get features of top importance
        for (TablesModelColumnInfo info : model.getTablesModelMetadata().getTablesModelColumnInfoList()) {
            System.out.format("Column: %s - Importance: %.2f%n", info.getColumnDisplayName(), info.getFeatureImportance());
        }
    }
}
Also used : TablesModelColumnInfo(com.google.cloud.automl.v1beta1.TablesModelColumnInfo) ModelName(com.google.cloud.automl.v1beta1.ModelName) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Model(com.google.cloud.automl.v1beta1.Model) SimpleDateFormat(java.text.SimpleDateFormat) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 14 with ModelName

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

the class PredictionApiIT method setUp.

@Before
public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Verify that the model is deployed for prediction
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", modelId);
        Model model = client.getModel(modelFullId);
        if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) {
            // Deploy the model if not deployed
            DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
            Future future = client.deployModelAsync(request);
            future.get(30, TimeUnit.MINUTES);
        }
    }
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    System.setOut(out);
}
Also used : DeployModelRequest(com.google.cloud.automl.v1beta1.DeployModelRequest) PrintStream(java.io.PrintStream) ModelName(com.google.cloud.automl.v1beta1.ModelName) Model(com.google.cloud.automl.v1beta1.Model) Future(java.util.concurrent.Future) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) Before(org.junit.Before)

Example 15 with ModelName

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

the class PredictionApiIT method setUp.

@Before
public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Verify that the model is deployed for prediction
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", modelId);
        Model model = client.getModel(modelFullId);
        if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) {
            // Deploy the model if not deployed
            DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
            Future future = client.deployModelAsync(request);
            future.get(30, TimeUnit.MINUTES);
        }
    }
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
}
Also used : DeployModelRequest(com.google.cloud.automl.v1.DeployModelRequest) PrintStream(java.io.PrintStream) ModelName(com.google.cloud.automl.v1.ModelName) Model(com.google.cloud.automl.v1.Model) Future(java.util.concurrent.Future) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Aggregations

ModelName (com.google.cloud.automl.v1.ModelName)24 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)16 ModelName (com.google.cloud.automl.v1beta1.ModelName)15 Empty (com.google.protobuf.Empty)13 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)11 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 Before (org.junit.Before)9 Model (com.google.cloud.automl.v1.Model)8 PredictionServiceClient (com.google.cloud.automl.v1.PredictionServiceClient)8 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)8 ExamplePayload (com.google.cloud.automl.v1.ExamplePayload)7 PredictResponse (com.google.cloud.automl.v1.PredictResponse)7 AnnotationPayload (com.google.cloud.automl.v1.AnnotationPayload)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6 PredictRequest (com.google.cloud.automl.v1.PredictRequest)6 DeployModelRequest (com.google.cloud.automl.v1beta1.DeployModelRequest)5 TextSnippet (com.google.cloud.automl.v1.TextSnippet)4 PredictionServiceClient (com.google.cloud.automl.v1beta1.PredictionServiceClient)4