Search in sources :

Example 51 with ModelName

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

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

Example 53 with ModelName

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

the class CreateBatchPredictionJobBigquerySample method createBatchPredictionJobBigquerySample.

static void createBatchPredictionJobBigquerySample(String project, String displayName, String model, String instancesFormat, String bigquerySourceInputUri, String predictionsFormat, String bigqueryDestinationOutputUri) throws IOException {
    JobServiceSettings settings = JobServiceSettings.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 (JobServiceClient client = JobServiceClient.create(settings)) {
        JsonObject jsonModelParameters = new JsonObject();
        Value.Builder modelParametersBuilder = Value.newBuilder();
        JsonFormat.parser().merge(jsonModelParameters.toString(), modelParametersBuilder);
        Value modelParameters = modelParametersBuilder.build();
        BigQuerySource bigquerySource = BigQuerySource.newBuilder().setInputUri(bigquerySourceInputUri).build();
        BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat(instancesFormat).setBigquerySource(bigquerySource).build();
        BigQueryDestination bigqueryDestination = BigQueryDestination.newBuilder().setOutputUri(bigqueryDestinationOutputUri).build();
        BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat(predictionsFormat).setBigqueryDestination(bigqueryDestination).build();
        String modelName = ModelName.of(project, location, model).toString();
        BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
        LocationName parent = LocationName.of(project, location);
        BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
        System.out.format("response: %s\n", response);
        System.out.format("\tName: %s\n", response.getName());
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) JsonObject(com.google.gson.JsonObject) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 54 with ModelName

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

the class CreateBatchPredictionJobSample method createBatchPredictionJobSample.

static void createBatchPredictionJobSample(String project, String displayName, String model, String instancesFormat, String gcsSourceUri, String predictionsFormat, String gcsDestinationOutputUriPrefix) throws IOException {
    JobServiceSettings settings = JobServiceSettings.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 (JobServiceClient client = JobServiceClient.create(settings)) {
        // Passing in an empty Value object for model parameters
        Value modelParameters = ValueConverter.EMPTY_VALUE;
        GcsSource gcsSource = GcsSource.newBuilder().addUris(gcsSourceUri).build();
        BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat(instancesFormat).setGcsSource(gcsSource).build();
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
        BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat(predictionsFormat).setGcsDestination(gcsDestination).build();
        MachineSpec machineSpec = MachineSpec.newBuilder().setMachineType("n1-standard-2").setAcceleratorType(AcceleratorType.NVIDIA_TESLA_K80).setAcceleratorCount(1).build();
        BatchDedicatedResources dedicatedResources = BatchDedicatedResources.newBuilder().setMachineSpec(machineSpec).setStartingReplicaCount(1).setMaxReplicaCount(1).build();
        String modelName = ModelName.of(project, location, model).toString();
        BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setModelParameters(modelParameters).setInputConfig(inputConfig).setOutputConfig(outputConfig).setDedicatedResources(dedicatedResources).build();
        LocationName parent = LocationName.of(project, location);
        BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
        System.out.format("response: %s\n", response);
        System.out.format("\tName: %s\n", response.getName());
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) BatchDedicatedResources(com.google.cloud.aiplatform.v1.BatchDedicatedResources) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 55 with ModelName

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

the class CreateBatchPredictionJobTextEntityExtractionSample method createBatchPredictionJobTextEntityExtractionSample.

static void createBatchPredictionJobTextEntityExtractionSample(String project, String location, String displayName, String modelId, String gcsSourceUri, String gcsDestinationOutputUriPrefix) throws IOException {
    // The AI Platform services require regional API endpoints.
    JobServiceSettings settings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient client = JobServiceClient.create(settings)) {
        try {
            String modelName = ModelName.of(project, location, modelId).toString();
            GcsSource gcsSource = GcsSource.newBuilder().addUris(gcsSourceUri).build();
            BatchPredictionJob.InputConfig inputConfig = BatchPredictionJob.InputConfig.newBuilder().setInstancesFormat("jsonl").setGcsSource(gcsSource).build();
            GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(gcsDestinationOutputUriPrefix).build();
            BatchPredictionJob.OutputConfig outputConfig = BatchPredictionJob.OutputConfig.newBuilder().setPredictionsFormat("jsonl").setGcsDestination(gcsDestination).build();
            BatchPredictionJob batchPredictionJob = BatchPredictionJob.newBuilder().setDisplayName(displayName).setModel(modelName).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
            LocationName parent = LocationName.of(project, location);
            BatchPredictionJob response = client.createBatchPredictionJob(parent, batchPredictionJob);
            System.out.format("response: %s\n", response);
            System.out.format("\tname:%s\n", response.getName());
        } catch (ApiException ex) {
            System.out.format("Exception: %s\n", ex.getLocalizedMessage());
        }
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName) ApiException(com.google.api.gax.rpc.ApiException)

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)11 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)10 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 ModelName (com.google.cloud.aiplatform.v1.ModelName)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 Before (org.junit.Before)9 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)8 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)8 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)8 LocationName (com.google.cloud.aiplatform.v1.LocationName)8 Model (com.google.cloud.automl.v1.Model)8 PredictionServiceClient (com.google.cloud.automl.v1.PredictionServiceClient)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)7 ExamplePayload (com.google.cloud.automl.v1.ExamplePayload)7 PredictResponse (com.google.cloud.automl.v1.PredictResponse)7