Search in sources :

Example 46 with ModelName

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

the class UndeployModelSample method undeployModelSample.

static void undeployModelSample(String project, String endpointId, String modelId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    EndpointServiceSettings endpointServiceSettings = EndpointServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (EndpointServiceClient endpointServiceClient = EndpointServiceClient.create(endpointServiceSettings)) {
        String location = "us-central1";
        EndpointName endpointName = EndpointName.of(project, location, endpointId);
        ModelName modelName = ModelName.of(project, location, modelId);
        // key '0' assigns traffic for the newly deployed model
        // Traffic percentage values must add up to 100
        // Leave dictionary empty if endpoint should not accept any traffic
        Map<String, Integer> trafficSplit = new HashMap<>();
        trafficSplit.put("0", 100);
        OperationFuture<UndeployModelResponse, UndeployModelOperationMetadata> operation = endpointServiceClient.undeployModelAsync(endpointName.toString(), modelName.toString(), trafficSplit);
        System.out.format("Operation name: %s\n", operation.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        UndeployModelResponse undeployModelResponse = operation.get(180, TimeUnit.SECONDS);
        System.out.format("Undeploy Model Response: %s\n", undeployModelResponse);
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) EndpointName(com.google.cloud.aiplatform.v1.EndpointName) HashMap(java.util.HashMap) EndpointServiceClient(com.google.cloud.aiplatform.v1.EndpointServiceClient) UndeployModelResponse(com.google.cloud.aiplatform.v1.UndeployModelResponse) EndpointServiceSettings(com.google.cloud.aiplatform.v1.EndpointServiceSettings) UndeployModelOperationMetadata(com.google.cloud.aiplatform.v1.UndeployModelOperationMetadata)

Example 47 with ModelName

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

the class DeployModelSample method deployModelSample.

static void deployModelSample(String project, String deployedModelDisplayName, String endpointId, String modelId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    EndpointServiceSettings endpointServiceSettings = EndpointServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (EndpointServiceClient endpointServiceClient = EndpointServiceClient.create(endpointServiceSettings)) {
        String location = "us-central1";
        EndpointName endpointName = EndpointName.of(project, location, endpointId);
        // key '0' assigns traffic for the newly deployed model
        // Traffic percentage values must add up to 100
        // Leave dictionary empty if endpoint should not accept any traffic
        Map<String, Integer> trafficSplit = new HashMap<>();
        trafficSplit.put("0", 100);
        ModelName modelName = ModelName.of(project, location, modelId);
        AutomaticResources automaticResourcesInput = AutomaticResources.newBuilder().setMinReplicaCount(1).setMaxReplicaCount(1).build();
        DeployedModel deployedModelInput = DeployedModel.newBuilder().setModel(modelName.toString()).setDisplayName(deployedModelDisplayName).setAutomaticResources(automaticResourcesInput).build();
        OperationFuture<DeployModelResponse, DeployModelOperationMetadata> deployModelResponseFuture = endpointServiceClient.deployModelAsync(endpointName, deployedModelInput, trafficSplit);
        System.out.format("Operation name: %s\n", deployModelResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        DeployModelResponse deployModelResponse = deployModelResponseFuture.get(20, TimeUnit.MINUTES);
        System.out.println("Deploy Model Response");
        DeployedModel deployedModel = deployModelResponse.getDeployedModel();
        System.out.println("\tDeployed Model");
        System.out.format("\t\tid: %s\n", deployedModel.getId());
        System.out.format("\t\tmodel: %s\n", deployedModel.getModel());
        System.out.format("\t\tDisplay Name: %s\n", deployedModel.getDisplayName());
        System.out.format("\t\tCreate Time: %s\n", deployedModel.getCreateTime());
        DedicatedResources dedicatedResources = deployedModel.getDedicatedResources();
        System.out.println("\t\tDedicated Resources");
        System.out.format("\t\t\tMin Replica Count: %s\n", dedicatedResources.getMinReplicaCount());
        MachineSpec machineSpec = dedicatedResources.getMachineSpec();
        System.out.println("\t\t\tMachine Spec");
        System.out.format("\t\t\t\tMachine Type: %s\n", machineSpec.getMachineType());
        System.out.format("\t\t\t\tAccelerator Type: %s\n", machineSpec.getAcceleratorType());
        System.out.format("\t\t\t\tAccelerator Count: %s\n", machineSpec.getAcceleratorCount());
        AutomaticResources automaticResources = deployedModel.getAutomaticResources();
        System.out.println("\t\tAutomatic Resources");
        System.out.format("\t\t\tMin Replica Count: %s\n", automaticResources.getMinReplicaCount());
        System.out.format("\t\t\tMax Replica Count: %s\n", automaticResources.getMaxReplicaCount());
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) HashMap(java.util.HashMap) DedicatedResources(com.google.cloud.aiplatform.v1.DedicatedResources) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) DeployedModel(com.google.cloud.aiplatform.v1.DeployedModel) DeployModelResponse(com.google.cloud.aiplatform.v1.DeployModelResponse) DeployModelOperationMetadata(com.google.cloud.aiplatform.v1.DeployModelOperationMetadata) EndpointName(com.google.cloud.aiplatform.v1.EndpointName) AutomaticResources(com.google.cloud.aiplatform.v1.AutomaticResources) EndpointServiceClient(com.google.cloud.aiplatform.v1.EndpointServiceClient) EndpointServiceSettings(com.google.cloud.aiplatform.v1.EndpointServiceSettings)

Example 48 with ModelName

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

the class ExportModelSample method exportModelSample.

static void exportModelSample(String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    ModelServiceSettings modelServiceSettings = ModelServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings)) {
        String location = "us-central1";
        GcsDestination.Builder gcsDestination = GcsDestination.newBuilder();
        gcsDestination.setOutputUriPrefix(gcsDestinationOutputUriPrefix);
        ModelName modelName = ModelName.of(project, location, modelId);
        ExportModelRequest.OutputConfig outputConfig = ExportModelRequest.OutputConfig.newBuilder().setExportFormatId(exportFormat).setArtifactDestination(gcsDestination).build();
        OperationFuture<ExportModelResponse, ExportModelOperationMetadata> exportModelResponseFuture = modelServiceClient.exportModelAsync(modelName, outputConfig);
        System.out.format("Operation name: %s\n", exportModelResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        ExportModelResponse exportModelResponse = exportModelResponseFuture.get(300, TimeUnit.SECONDS);
        System.out.format("Export Model Response: %s\n", exportModelResponse);
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) ExportModelResponse(com.google.cloud.aiplatform.v1.ExportModelResponse) ModelServiceSettings(com.google.cloud.aiplatform.v1.ModelServiceSettings) ExportModelOperationMetadata(com.google.cloud.aiplatform.v1.ExportModelOperationMetadata) ModelServiceClient(com.google.cloud.aiplatform.v1.ModelServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) ExportModelRequest(com.google.cloud.aiplatform.v1.ExportModelRequest)

Example 49 with ModelName

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

the class ExportModelTabularClassificationSample method exportModelTableClassification.

static void exportModelTableClassification(String gcsDestinationOutputUriPrefix, String project, String modelId) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    ModelServiceSettings modelServiceSettings = ModelServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings)) {
        String location = "us-central1";
        ModelName modelName = ModelName.of(project, location, modelId);
        GcsDestination.Builder gcsDestination = GcsDestination.newBuilder();
        gcsDestination.setOutputUriPrefix(gcsDestinationOutputUriPrefix);
        ExportModelRequest.OutputConfig outputConfig = ExportModelRequest.OutputConfig.newBuilder().setExportFormatId("tf-saved-model").setArtifactDestination(gcsDestination).build();
        OperationFuture<ExportModelResponse, ExportModelOperationMetadata> exportModelResponseFuture = modelServiceClient.exportModelAsync(modelName, outputConfig);
        System.out.format("Operation name: %s\n", exportModelResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        ExportModelResponse exportModelResponse = exportModelResponseFuture.get(300, TimeUnit.SECONDS);
        System.out.format("Export Model Tabular Classification Response: %s", exportModelResponse.toString());
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) ExportModelResponse(com.google.cloud.aiplatform.v1.ExportModelResponse) ModelServiceSettings(com.google.cloud.aiplatform.v1.ModelServiceSettings) ExportModelOperationMetadata(com.google.cloud.aiplatform.v1.ExportModelOperationMetadata) ModelServiceClient(com.google.cloud.aiplatform.v1.ModelServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) ExportModelRequest(com.google.cloud.aiplatform.v1.ExportModelRequest)

Example 50 with ModelName

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

the class ExportModelVideoActionRecognitionSample method exportModelVideoActionRecognitionSample.

static void exportModelVideoActionRecognitionSample(String project, String modelId, String gcsDestinationOutputUriPrefix, String exportFormat) throws IOException, ExecutionException, InterruptedException {
    ModelServiceSettings settings = ModelServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    String location = "us-central1";
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ModelServiceClient client = ModelServiceClient.create(settings)) {
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
        ExportModelRequest.OutputConfig outputConfig = ExportModelRequest.OutputConfig.newBuilder().setArtifactDestination(gcsDestination).setExportFormatId(exportFormat).build();
        ModelName name = ModelName.of(project, location, modelId);
        OperationFuture<ExportModelResponse, ExportModelOperationMetadata> response = client.exportModelAsync(name, outputConfig);
        // You can use OperationFuture.getInitialFuture to get a future representing the initial
        // response to the request, which contains information while the operation is in progress.
        System.out.format("Operation name: %s\n", response.getInitialFuture().get().getName());
        // OperationFuture.get() will block until the operation is finished.
        ExportModelResponse exportModelResponse = response.get();
        System.out.format("exportModelResponse: %s\n", exportModelResponse);
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) ExportModelResponse(com.google.cloud.aiplatform.v1.ExportModelResponse) ModelServiceSettings(com.google.cloud.aiplatform.v1.ModelServiceSettings) ExportModelOperationMetadata(com.google.cloud.aiplatform.v1.ExportModelOperationMetadata) ModelServiceClient(com.google.cloud.aiplatform.v1.ModelServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) ExportModelRequest(com.google.cloud.aiplatform.v1.ExportModelRequest)

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)14 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)12 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 ModelName (com.google.cloud.aiplatform.v1.ModelName)9 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)9 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 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 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)5 ModelServiceClient (com.google.cloud.aiplatform.v1.ModelServiceClient)5