Search in sources :

Example 1 with UploadModelOperationMetadata

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

Aggregations

LocationName (com.google.cloud.aiplatform.v1.LocationName)1 Model (com.google.cloud.aiplatform.v1.Model)1 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)1 ModelServiceClient (com.google.cloud.aiplatform.v1.ModelServiceClient)1 ModelServiceSettings (com.google.cloud.aiplatform.v1.ModelServiceSettings)1 UploadModelOperationMetadata (com.google.cloud.aiplatform.v1.UploadModelOperationMetadata)1 UploadModelResponse (com.google.cloud.aiplatform.v1.UploadModelResponse)1