Search in sources :

Example 11 with ModelServiceSettings

use of com.google.cloud.aiplatform.v1.ModelServiceSettings in project java-aiplatform by googleapis.

the class DeleteModelSample method deleteModel.

static void deleteModel(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);
        OperationFuture<Empty, DeleteOperationMetadata> operationFuture = modelServiceClient.deleteModelAsync(modelName);
        System.out.format("Operation name: %s\n", operationFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        operationFuture.get(300, TimeUnit.SECONDS);
        System.out.format("Deleted Model.");
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.aiplatform.v1.ModelName) DeleteOperationMetadata(com.google.cloud.aiplatform.v1.DeleteOperationMetadata) ModelServiceSettings(com.google.cloud.aiplatform.v1.ModelServiceSettings) ModelServiceClient(com.google.cloud.aiplatform.v1.ModelServiceClient)

Example 12 with ModelServiceSettings

use of com.google.cloud.aiplatform.v1.ModelServiceSettings in project java-aiplatform by googleapis.

the class UploadModelSample method uploadModel.

static void uploadModel(String project, String modelDisplayName, String metadataSchemaUri, String imageUri, String artifactUri) 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";
        LocationName locationName = LocationName.of(project, location);
        ModelContainerSpec modelContainerSpec = ModelContainerSpec.newBuilder().setImageUri(imageUri).build();
        Model model = Model.newBuilder().setDisplayName(modelDisplayName).setMetadataSchemaUri(metadataSchemaUri).setArtifactUri(artifactUri).setContainerSpec(modelContainerSpec).build();
        OperationFuture<UploadModelResponse, UploadModelOperationMetadata> uploadModelResponseFuture = modelServiceClient.uploadModelAsync(locationName, model);
        System.out.format("Operation name: %s\n", uploadModelResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        UploadModelResponse uploadModelResponse = uploadModelResponseFuture.get(5, TimeUnit.MINUTES);
        System.out.println("Upload Model Response");
        System.out.format("Model: %s\n", uploadModelResponse.getModel());
    }
}
Also used : ModelContainerSpec(com.google.cloud.aiplatform.v1.ModelContainerSpec) UploadModelOperationMetadata(com.google.cloud.aiplatform.v1.UploadModelOperationMetadata) ModelServiceSettings(com.google.cloud.aiplatform.v1.ModelServiceSettings) Model(com.google.cloud.aiplatform.v1.Model) UploadModelResponse(com.google.cloud.aiplatform.v1.UploadModelResponse) ModelServiceClient(com.google.cloud.aiplatform.v1.ModelServiceClient) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 13 with ModelServiceSettings

use of com.google.cloud.aiplatform.v1.ModelServiceSettings 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 14 with ModelServiceSettings

use of com.google.cloud.aiplatform.v1.ModelServiceSettings 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 15 with ModelServiceSettings

use of com.google.cloud.aiplatform.v1.ModelServiceSettings 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

ModelServiceClient (com.google.cloud.aiplatform.v1.ModelServiceClient)19 ModelServiceSettings (com.google.cloud.aiplatform.v1.ModelServiceSettings)19 ModelEvaluationName (com.google.cloud.aiplatform.v1.ModelEvaluationName)12 ModelEvaluation (com.google.cloud.aiplatform.v1.ModelEvaluation)11 ModelName (com.google.cloud.aiplatform.v1.ModelName)5 ExportModelOperationMetadata (com.google.cloud.aiplatform.v1.ExportModelOperationMetadata)3 ExportModelRequest (com.google.cloud.aiplatform.v1.ExportModelRequest)3 ExportModelResponse (com.google.cloud.aiplatform.v1.ExportModelResponse)3 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)3 Model (com.google.cloud.aiplatform.v1.Model)2 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)2 ModelEvaluationSlice (com.google.cloud.aiplatform.v1.ModelEvaluationSlice)2 Slice (com.google.cloud.aiplatform.v1.ModelEvaluationSlice.Slice)2 DeleteOperationMetadata (com.google.cloud.aiplatform.v1.DeleteOperationMetadata)1 DeployedModelRef (com.google.cloud.aiplatform.v1.DeployedModelRef)1 EnvVar (com.google.cloud.aiplatform.v1.EnvVar)1 LocationName (com.google.cloud.aiplatform.v1.LocationName)1 ExportFormat (com.google.cloud.aiplatform.v1.Model.ExportFormat)1 ModelEvaluationSliceName (com.google.cloud.aiplatform.v1.ModelEvaluationSliceName)1 Port (com.google.cloud.aiplatform.v1.Port)1