Search in sources :

Example 36 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient 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 37 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient 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 38 with JobServiceClient

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

Example 39 with JobServiceClient

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

the class CreateBatchPredictionJobVideoActionRecognitionSample method createBatchPredictionJobVideoActionRecognitionSample.

static void createBatchPredictionJobVideoActionRecognitionSample(String project, String displayName, String model, String gcsSourceUri, 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)) {
        Value modelParameters = ValueConverter.EMPTY_VALUE;
        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();
        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) 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) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 40 with JobServiceClient

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

the class CreateDataLabelingJobSpecialistPoolSample method createDataLabelingJobSpecialistPoolSample.

static void createDataLabelingJobSpecialistPoolSample(String project, String displayName, String dataset, String specialistPool, String instructionUri, String inputsSchemaUri, String annotationSpec) 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)) {
        JsonArray jsonAnnotationSpecs = new JsonArray();
        jsonAnnotationSpecs.add(annotationSpec);
        JsonObject jsonInputs = new JsonObject();
        jsonInputs.add("annotation_specs", jsonAnnotationSpecs);
        Value.Builder inputsBuilder = Value.newBuilder();
        JsonFormat.parser().merge(jsonInputs.toString(), inputsBuilder);
        Value inputs = inputsBuilder.build();
        String datasetName = DatasetName.of(project, location, dataset).toString();
        String specialistPoolName = SpecialistPoolName.of(project, location, specialistPool).toString();
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).addDatasets(datasetName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).setInputs(inputs).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "data_labeling_job_specialist_pool").addSpecialistPools(specialistPoolName).build();
        LocationName parent = LocationName.of(project, location);
        DataLabelingJob response = client.createDataLabelingJob(parent, dataLabelingJob);
        System.out.format("response: %s\n", response);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) JsonObject(com.google.gson.JsonObject) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Aggregations

JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)21 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)21 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)19 Job (com.google.cloud.talent.v4beta1.Job)16 LocationName (com.google.cloud.aiplatform.v1.LocationName)15 Value (com.google.protobuf.Value)10 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)9 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)8 JobServiceClient (com.google.cloud.talent.v4.JobServiceClient)8 Job (com.google.cloud.talent.v4.Job)7 TenantOrProjectName (com.google.cloud.talent.v4beta1.TenantOrProjectName)7 TenantName (com.google.cloud.talent.v4.TenantName)6 RequestMetadata (com.google.cloud.talent.v4beta1.RequestMetadata)6 SearchJobsRequest (com.google.cloud.talent.v4beta1.SearchJobsRequest)6 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)5 MachineSpec (com.google.cloud.aiplatform.v1.MachineSpec)5 BigQueryDestination (com.google.cloud.aiplatform.v1.BigQueryDestination)4 BigQuerySource (com.google.cloud.aiplatform.v1.BigQuerySource)4 CreateJobRequest (com.google.cloud.talent.v4beta1.CreateJobRequest)4