Search in sources :

Example 11 with JobServiceSettings

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

the class CreateDataLabelingJobSample method createDataLabelingJob.

static void createDataLabelingJob(String project, String displayName, String datasetId, String instructionUri, String inputsSchemaUri, String annotationSpec) throws IOException {
    JobServiceSettings jobServiceSettings = 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 jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
        Value.Builder annotationSpecValue = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, annotationSpecValue);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
        DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
        System.out.println("Create Data Labeling Job Response");
        System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
        System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
        System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
        System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
        System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
        System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
        System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
        System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
        System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
        System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
        for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
            System.out.println("\tAnnotation Level");
            System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
            System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
        }
        Money money = dataLabelingJobResponse.getCurrentSpend();
        System.out.println("\tCurrent Spend");
        System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
        System.out.format("\t\tUnits: %s\n", money.getUnits());
        System.out.format("\t\tNanos: %s\n", money.getNanos());
    }
}
Also used : Money(com.google.type.Money) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) Map(java.util.Map) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 12 with JobServiceSettings

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

the class DeleteDataLabelingJobSample method deleteDataLabelingJob.

static void deleteDataLabelingJob(String project, String dataLabelingJobId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    JobServiceSettings jobServiceSettings = 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 jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        DataLabelingJobName dataLabelingJobName = DataLabelingJobName.of(project, location, dataLabelingJobId);
        OperationFuture<Empty, DeleteOperationMetadata> operationFuture = jobServiceClient.deleteDataLabelingJobAsync(dataLabelingJobName);
        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 Data Labeling Job.");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) Empty(com.google.protobuf.Empty) DeleteOperationMetadata(com.google.cloud.aiplatform.v1.DeleteOperationMetadata) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJobName(com.google.cloud.aiplatform.v1.DataLabelingJobName)

Example 13 with JobServiceSettings

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

the class CreateHyperparameterTuningJobPythonPackageSampleTest method tearDown.

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException, TimeoutException {
    JobServiceSettings settings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    try (JobServiceClient client = JobServiceClient.create(settings)) {
        // Cancel hyper parameter job
        String hyperparameterJobName = String.format("projects/%s/locations/us-central1/hyperparameterTuningJobs/%s", PROJECT, hyperparameterJobId);
        client.cancelHyperparameterTuningJob(hyperparameterJobName);
        TimeUnit.MINUTES.sleep(1);
        // Delete the created job
        client.deleteHyperparameterTuningJobAsync(hyperparameterJobName);
        System.out.flush();
        System.setOut(originalPrintStream);
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1beta1.JobServiceSettings) JobServiceClient(com.google.cloud.aiplatform.v1beta1.JobServiceClient) After(org.junit.After)

Example 14 with JobServiceSettings

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

the class DeleteBatchPredictionJobSample method deleteBatchPredictionJobSample.

static void deleteBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    JobServiceSettings jobServiceSettings = 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 jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        OperationFuture<Empty, DeleteOperationMetadata> operationFuture = jobServiceClient.deleteBatchPredictionJobAsync(batchPredictionJobName);
        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.println("Deleted Batch Prediction Job.");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) Empty(com.google.protobuf.Empty) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) DeleteOperationMetadata(com.google.cloud.aiplatform.v1.DeleteOperationMetadata) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient)

Example 15 with JobServiceSettings

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

the class CreateHyperparameterTuningJobPythonPackageSample method createHyperparameterTuningJobPythonPackageSample.

static void createHyperparameterTuningJobPythonPackageSample(String project, String displayName, String executorImageUri, String packageUri, String pythonModule) 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)) {
        // study spec
        MetricSpec metric = MetricSpec.newBuilder().setMetricId("val_rmse").setGoal(GoalType.MINIMIZE).build();
        // decay
        DoubleValueSpec doubleValueSpec = DoubleValueSpec.newBuilder().setMinValue(1e-07).setMaxValue(1).build();
        ParameterSpec parameterDecaySpec = ParameterSpec.newBuilder().setParameterId("decay").setDoubleValueSpec(doubleValueSpec).setScaleType(ScaleType.UNIT_LINEAR_SCALE).build();
        Double[] decayValues = { 32.0, 64.0 };
        DiscreteValueCondition discreteValueDecay = DiscreteValueCondition.newBuilder().addAllValues(Arrays.asList(decayValues)).build();
        ConditionalParameterSpec conditionalParameterDecay = ConditionalParameterSpec.newBuilder().setParameterSpec(parameterDecaySpec).setParentDiscreteValues(discreteValueDecay).build();
        // learning rate
        ParameterSpec parameterLearningSpec = ParameterSpec.newBuilder().setParameterId("learning_rate").setDoubleValueSpec(// Use the same min/max as for decay
        doubleValueSpec).setScaleType(ScaleType.UNIT_LINEAR_SCALE).build();
        Double[] learningRateValues = { 4.0, 8.0, 16.0 };
        DiscreteValueCondition discreteValueLearning = DiscreteValueCondition.newBuilder().addAllValues(Arrays.asList(learningRateValues)).build();
        ConditionalParameterSpec conditionalParameterLearning = ConditionalParameterSpec.newBuilder().setParameterSpec(parameterLearningSpec).setParentDiscreteValues(discreteValueLearning).build();
        // batch size
        Double[] batchSizeValues = { 4.0, 8.0, 16.0, 32.0, 64.0, 128.0 };
        DiscreteValueSpec discreteValueSpec = DiscreteValueSpec.newBuilder().addAllValues(Arrays.asList(batchSizeValues)).build();
        ParameterSpec parameter = ParameterSpec.newBuilder().setParameterId("batch_size").setDiscreteValueSpec(discreteValueSpec).setScaleType(ScaleType.UNIT_LINEAR_SCALE).addConditionalParameterSpecs(conditionalParameterDecay).addConditionalParameterSpecs(conditionalParameterLearning).build();
        // trial_job_spec
        MachineSpec machineSpec = MachineSpec.newBuilder().setMachineType("n1-standard-4").setAcceleratorType(AcceleratorType.NVIDIA_TESLA_K80).setAcceleratorCount(1).build();
        PythonPackageSpec pythonPackageSpec = PythonPackageSpec.newBuilder().setExecutorImageUri(executorImageUri).addPackageUris(packageUri).setPythonModule(pythonModule).build();
        WorkerPoolSpec workerPoolSpec = WorkerPoolSpec.newBuilder().setMachineSpec(machineSpec).setReplicaCount(1).setPythonPackageSpec(pythonPackageSpec).build();
        StudySpec studySpec = StudySpec.newBuilder().addMetrics(metric).addParameters(parameter).setAlgorithm(StudySpec.Algorithm.RANDOM_SEARCH).build();
        CustomJobSpec trialJobSpec = CustomJobSpec.newBuilder().addWorkerPoolSpecs(workerPoolSpec).build();
        // hyperparameter_tuning_job
        HyperparameterTuningJob hyperparameterTuningJob = HyperparameterTuningJob.newBuilder().setDisplayName(displayName).setMaxTrialCount(4).setParallelTrialCount(2).setStudySpec(studySpec).setTrialJobSpec(trialJobSpec).build();
        LocationName parent = LocationName.of(project, location);
        HyperparameterTuningJob response = client.createHyperparameterTuningJob(parent, hyperparameterTuningJob);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) StudySpec(com.google.cloud.aiplatform.v1.StudySpec) DoubleValueSpec(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec.DoubleValueSpec) ParameterSpec(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec) ConditionalParameterSpec(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec.ConditionalParameterSpec) MetricSpec(com.google.cloud.aiplatform.v1.StudySpec.MetricSpec) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) CustomJobSpec(com.google.cloud.aiplatform.v1.CustomJobSpec) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) ConditionalParameterSpec(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec.ConditionalParameterSpec) PythonPackageSpec(com.google.cloud.aiplatform.v1.PythonPackageSpec) LocationName(com.google.cloud.aiplatform.v1.LocationName) DiscreteValueCondition(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition) HyperparameterTuningJob(com.google.cloud.aiplatform.v1.HyperparameterTuningJob) DiscreteValueSpec(com.google.cloud.aiplatform.v1.StudySpec.ParameterSpec.DiscreteValueSpec) WorkerPoolSpec(com.google.cloud.aiplatform.v1.WorkerPoolSpec)

Aggregations

JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)21 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)21 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 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 ApiException (com.google.api.gax.rpc.ApiException)3 BatchDedicatedResources (com.google.cloud.aiplatform.v1.BatchDedicatedResources)3 InputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig)3 OutputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig)3 OutputInfo (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo)3 BatchPredictionJobName (com.google.cloud.aiplatform.v1.BatchPredictionJobName)3 CompletionStats (com.google.cloud.aiplatform.v1.CompletionStats)3 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)3 HyperparameterTuningJob (com.google.cloud.aiplatform.v1.HyperparameterTuningJob)3