Search in sources :

Example 1 with DataLabelingJob

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

the class JobServiceClientTest method listDataLabelingJobsTest.

@Test
public void listDataLabelingJobsTest() throws Exception {
    DataLabelingJob responsesElement = DataLabelingJob.newBuilder().build();
    ListDataLabelingJobsResponse expectedResponse = ListDataLabelingJobsResponse.newBuilder().setNextPageToken("").addAllDataLabelingJobs(Arrays.asList(responsesElement)).build();
    mockJobService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListDataLabelingJobsPagedResponse pagedListResponse = client.listDataLabelingJobs(parent);
    List<DataLabelingJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDataLabelingJobsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockJobService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDataLabelingJobsRequest actualRequest = ((ListDataLabelingJobsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDataLabelingJobsPagedResponse(com.google.cloud.aiplatform.v1.JobServiceClient.ListDataLabelingJobsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with DataLabelingJob

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

the class JobServiceClientTest method listDataLabelingJobsTest2.

@Test
public void listDataLabelingJobsTest2() throws Exception {
    DataLabelingJob responsesElement = DataLabelingJob.newBuilder().build();
    ListDataLabelingJobsResponse expectedResponse = ListDataLabelingJobsResponse.newBuilder().setNextPageToken("").addAllDataLabelingJobs(Arrays.asList(responsesElement)).build();
    mockJobService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDataLabelingJobsPagedResponse pagedListResponse = client.listDataLabelingJobs(parent);
    List<DataLabelingJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDataLabelingJobsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockJobService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDataLabelingJobsRequest actualRequest = ((ListDataLabelingJobsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDataLabelingJobsPagedResponse(com.google.cloud.aiplatform.v1.JobServiceClient.ListDataLabelingJobsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with DataLabelingJob

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

the class CreateDataLabelingJobActiveLearningSample method createDataLabelingJobActiveLearningSample.

static void createDataLabelingJobActiveLearningSample(String project, String displayName, String dataset, 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();
        ActiveLearningConfig activeLearningConfig = ActiveLearningConfig.newBuilder().setMaxDataItemCount(1).build();
        String datasetName = DatasetName.of(project, location, dataset).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_active_learning").setActiveLearningConfig(activeLearningConfig).build();
        LocationName parent = LocationName.of(project, location);
        DataLabelingJob response = client.createDataLabelingJob(parent, dataLabelingJob);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ActiveLearningConfig(com.google.cloud.aiplatform.v1.ActiveLearningConfig) 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)

Example 4 with DataLabelingJob

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

the class CreateDataLabelingJobImageSample method createDataLabelingJobImage.

static void createDataLabelingJobImage(String project, String displayName, String datasetId, String instructionUri, 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("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "image_classification.yaml").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 Image 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 5 with DataLabelingJob

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

Aggregations

DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)5 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)5 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)5 LocationName (com.google.cloud.aiplatform.v1.LocationName)5 Value (com.google.protobuf.Value)5 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)3 Money (com.google.type.Money)3 Map (java.util.Map)3 ListDataLabelingJobsPagedResponse (com.google.cloud.aiplatform.v1.JobServiceClient.ListDataLabelingJobsPagedResponse)2 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ActiveLearningConfig (com.google.cloud.aiplatform.v1.ActiveLearningConfig)1