Search in sources :

Example 6 with DeployModelRequest

use of com.google.cloud.automl.v1beta1.DeployModelRequest in project java-automl by googleapis.

the class VisionObjectDetectionPredictTest method setUp.

@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
    // Verify that the model is deployed for prediction
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
        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();
            client.deployModelAsync(request).get();
        }
    }
    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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 7 with DeployModelRequest

use of com.google.cloud.automl.v1beta1.DeployModelRequest in project java-automl by googleapis.

the class LanguageSentimentAnalysisPredictTest method setUp.

@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
    // Verify that the model is deployed for prediction
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
        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();
            client.deployModelAsync(request).get();
        }
    }
    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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 8 with DeployModelRequest

use of com.google.cloud.automl.v1beta1.DeployModelRequest in project java-automl by googleapis.

the class TablesPredictTest method setUp.

@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
    // Verify that the model is deployed for prediction
    try (AutoMlClient client = AutoMlClient.create()) {
        ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
        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();
            client.deployModelAsync(request).get();
        }
    }
    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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 9 with DeployModelRequest

use of com.google.cloud.automl.v1beta1.DeployModelRequest in project java-automl by googleapis.

the class ClassificationDeployModelNodeCount method classificationDeployModelNodeCount.

// Deploy a model with a specified node count
static void classificationDeployModelNodeCount(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
        ImageClassificationModelDeploymentMetadata deploymentMetadata = ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageClassificationModelDeploymentMetadata(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) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) ImageClassificationModelDeploymentMetadata(com.google.cloud.automl.v1beta1.ImageClassificationModelDeploymentMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 10 with DeployModelRequest

use of com.google.cloud.automl.v1beta1.DeployModelRequest in project java-automl by googleapis.

the class VisionObjectDetectionDeployModelNodeCount method visionObjectDetectionDeployModelNodeCount.

// Deploy a model for prediction with a specified node count (can be used to redeploy a model)
static void visionObjectDetectionDeployModelNodeCount(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);
        ImageObjectDetectionModelDeploymentMetadata metadata = ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
        DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageObjectDetectionModelDeploymentMetadata(metadata).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) ImageObjectDetectionModelDeploymentMetadata(com.google.cloud.automl.v1.ImageObjectDetectionModelDeploymentMetadata) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Aggregations

AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)10 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 ModelName (com.google.cloud.automl.v1.ModelName)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 PrintStream (java.io.PrintStream)8 Before (org.junit.Before)8 Model (com.google.cloud.automl.v1.Model)7 Empty (com.google.protobuf.Empty)7 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)5 DeployModelRequest (com.google.cloud.automl.v1beta1.DeployModelRequest)5 ModelName (com.google.cloud.automl.v1beta1.ModelName)5 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)4 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)3 Future (java.util.concurrent.Future)2 ImageClassificationModelDeploymentMetadata (com.google.cloud.automl.v1.ImageClassificationModelDeploymentMetadata)1 ImageObjectDetectionModelDeploymentMetadata (com.google.cloud.automl.v1.ImageObjectDetectionModelDeploymentMetadata)1 ImageClassificationModelDeploymentMetadata (com.google.cloud.automl.v1beta1.ImageClassificationModelDeploymentMetadata)1 ImageObjectDetectionModelDeploymentMetadata (com.google.cloud.automl.v1beta1.ImageObjectDetectionModelDeploymentMetadata)1 Model (com.google.cloud.automl.v1beta1.Model)1