Search in sources :

Example 1 with AnnotatedDataset

use of com.google.cloud.datalabeling.v1beta1.AnnotatedDataset in project java-datalabeling by googleapis.

the class LabelText method labelText.

// Start a Text Labeling Task
static void labelText(String formattedInstructionName, String formattedAnnotationSpecSetName, String formattedDatasetName) throws IOException {
    // String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
    // "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
    // String formattedAnnotationSpecSetName =
    // DataLabelingServiceClient.formatAnnotationSpecSetName(
    // "YOUR_PROJECT_ID", "YOUR_ANNOTATION_SPEC_SET_UUID");
    // String formattedDatasetName = DataLabelingServiceClient.formatDatasetName(
    // "YOUR_PROJECT_ID", "YOUR_DATASET_UUID");
    // [END datalabeling_label_text_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_label_text_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder().setAnnotatedDatasetDisplayName("annotated_displayname").setAnnotatedDatasetDescription("annotated_description").setLanguageCode("en-us").setInstruction(formattedInstructionName).build();
        SentimentConfig sentimentConfig = SentimentConfig.newBuilder().setEnableLabelSentimentSelection(false).build();
        TextClassificationConfig textClassificationConfig = TextClassificationConfig.newBuilder().setAnnotationSpecSet(formattedAnnotationSpecSetName).setSentimentConfig(sentimentConfig).build();
        LabelTextRequest labelTextRequest = LabelTextRequest.newBuilder().setParent(formattedDatasetName).setBasicConfig(humanAnnotationConfig).setTextClassificationConfig(textClassificationConfig).setFeature(Feature.TEXT_CLASSIFICATION).build();
        OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation = dataLabelingServiceClient.labelTextAsync(labelTextRequest);
        // You'll want to save this for later to retrieve your completed operation.
        // System.out.format("Operation Name: %s\n", operation.getName());
        // Cancel the operation to avoid charges when testing.
        dataLabelingServiceClient.getOperationsClient().cancelOperation(operation.getName());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) LabelOperationMetadata(com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata) SentimentConfig(com.google.cloud.datalabeling.v1beta1.SentimentConfig) IOException(java.io.IOException) LabelTextRequest(com.google.cloud.datalabeling.v1beta1.LabelTextRequest) AnnotatedDataset(com.google.cloud.datalabeling.v1beta1.AnnotatedDataset) HumanAnnotationConfig(com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig) TextClassificationConfig(com.google.cloud.datalabeling.v1beta1.TextClassificationConfig) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with AnnotatedDataset

use of com.google.cloud.datalabeling.v1beta1.AnnotatedDataset in project java-datalabeling by googleapis.

the class DataLabelingServiceClientTest method listAnnotatedDatasetsTest2.

@Test
public void listAnnotatedDatasetsTest2() throws Exception {
    AnnotatedDataset responsesElement = AnnotatedDataset.newBuilder().build();
    ListAnnotatedDatasetsResponse expectedResponse = ListAnnotatedDatasetsResponse.newBuilder().setNextPageToken("").addAllAnnotatedDatasets(Arrays.asList(responsesElement)).build();
    mockDataLabelingService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    String filter = "filter-1274492040";
    ListAnnotatedDatasetsPagedResponse pagedListResponse = client.listAnnotatedDatasets(parent, filter);
    List<AnnotatedDataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAnnotatedDatasetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAnnotatedDatasetsRequest actualRequest = ((ListAnnotatedDatasetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListAnnotatedDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotatedDatasetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with AnnotatedDataset

use of com.google.cloud.datalabeling.v1beta1.AnnotatedDataset in project java-datalabeling by googleapis.

the class DataLabelingServiceClientTest method listAnnotatedDatasetsTest.

@Test
public void listAnnotatedDatasetsTest() throws Exception {
    AnnotatedDataset responsesElement = AnnotatedDataset.newBuilder().build();
    ListAnnotatedDatasetsResponse expectedResponse = ListAnnotatedDatasetsResponse.newBuilder().setNextPageToken("").addAllAnnotatedDatasets(Arrays.asList(responsesElement)).build();
    mockDataLabelingService.addResponse(expectedResponse);
    DatasetName parent = DatasetName.of("[PROJECT]", "[DATASET]");
    String filter = "filter-1274492040";
    ListAnnotatedDatasetsPagedResponse pagedListResponse = client.listAnnotatedDatasets(parent, filter);
    List<AnnotatedDataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAnnotatedDatasetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAnnotatedDatasetsRequest actualRequest = ((ListAnnotatedDatasetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListAnnotatedDatasetsPagedResponse(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotatedDatasetsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 4 with AnnotatedDataset

use of com.google.cloud.datalabeling.v1beta1.AnnotatedDataset in project java-datalabeling by googleapis.

the class LabelImage method labelImage.

// Start an Image Labeling Task
static void labelImage(String formattedInstructionName, String formattedAnnotationSpecSetName, String formattedDatasetName) throws IOException {
    // String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
    // "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
    // String formattedAnnotationSpecSetName =
    // DataLabelingServiceClient.formatAnnotationSpecSetName(
    // "YOUR_PROJECT_ID", "YOUR_ANNOTATION_SPEC_SET_UUID");
    // String formattedDatasetName = DataLabelingServiceClient.formatDatasetName(
    // "YOUR_PROJECT_ID", "YOUR_DATASET_UUID");
    // [END datalabeling_label_image_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_label_image_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder().setAnnotatedDatasetDisplayName("annotated_displayname").setAnnotatedDatasetDescription("annotated_description").setInstruction(formattedInstructionName).build();
        ImageClassificationConfig imageClassificationConfig = ImageClassificationConfig.newBuilder().setAllowMultiLabel(true).setAnswerAggregationType(StringAggregationType.MAJORITY_VOTE).setAnnotationSpecSet(formattedAnnotationSpecSetName).build();
        LabelImageRequest labelImageRequest = LabelImageRequest.newBuilder().setParent(formattedDatasetName).setBasicConfig(humanAnnotationConfig).setImageClassificationConfig(imageClassificationConfig).setFeature(Feature.CLASSIFICATION).build();
        OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation = dataLabelingServiceClient.labelImageAsync(labelImageRequest);
        // You'll want to save this for later to retrieve your completed operation.
        System.out.format("Operation Name: %s\n", operation.getName());
        // Cancel the operation to avoid charges when testing.
        dataLabelingServiceClient.getOperationsClient().cancelOperation(operation.getName());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) LabelOperationMetadata(com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata) IOException(java.io.IOException) AnnotatedDataset(com.google.cloud.datalabeling.v1beta1.AnnotatedDataset) HumanAnnotationConfig(com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig) LabelImageRequest(com.google.cloud.datalabeling.v1beta1.LabelImageRequest) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException) ImageClassificationConfig(com.google.cloud.datalabeling.v1beta1.ImageClassificationConfig)

Example 5 with AnnotatedDataset

use of com.google.cloud.datalabeling.v1beta1.AnnotatedDataset in project java-datalabeling by googleapis.

the class LabelVideo method labelVideo.

// Start a Video Labeling Task
static void labelVideo(String formattedInstructionName, String formattedAnnotationSpecSetName, String formattedDatasetName) throws IOException {
    // String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
    // "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
    // String formattedAnnotationSpecSetName =
    // DataLabelingServiceClient.formatAnnotationSpecSetName(
    // "YOUR_PROJECT_ID", "YOUR_ANNOTATION_SPEC_SET_UUID");
    // String formattedDatasetName = DataLabelingServiceClient.formatDatasetName(
    // "YOUR_PROJECT_ID", "YOUR_DATASET_UUID");
    // [END datalabeling_label_video_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_label_video_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder().setAnnotatedDatasetDisplayName("annotated_displayname").setAnnotatedDatasetDescription("annotated_description").setInstruction(formattedInstructionName).build();
        AnnotationSpecSetConfig annotationSpecSetConfig = AnnotationSpecSetConfig.newBuilder().setAnnotationSpecSet(formattedAnnotationSpecSetName).setAllowMultiLabel(true).build();
        VideoClassificationConfig videoClassificationConfig = VideoClassificationConfig.newBuilder().setApplyShotDetection(true).addAnnotationSpecSetConfigs(annotationSpecSetConfig).build();
        LabelVideoRequest labelVideoRequest = LabelVideoRequest.newBuilder().setParent(formattedDatasetName).setBasicConfig(humanAnnotationConfig).setVideoClassificationConfig(videoClassificationConfig).setFeature(Feature.CLASSIFICATION).build();
        OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation = dataLabelingServiceClient.labelVideoAsync(labelVideoRequest);
        // You'll want to save this for later to retrieve your completed operation.
        System.out.format("Operation Name: %s\n", operation.getName());
        // Cancel the operation to avoid charges when testing.
        dataLabelingServiceClient.getOperationsClient().cancelOperation(operation.getName());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) LabelVideoRequest(com.google.cloud.datalabeling.v1beta1.LabelVideoRequest) AnnotationSpecSetConfig(com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig.AnnotationSpecSetConfig) LabelOperationMetadata(com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata) IOException(java.io.IOException) VideoClassificationConfig(com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig) AnnotatedDataset(com.google.cloud.datalabeling.v1beta1.AnnotatedDataset) HumanAnnotationConfig(com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

AnnotatedDataset (com.google.cloud.datalabeling.v1beta1.AnnotatedDataset)3 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)3 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)3 HumanAnnotationConfig (com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig)3 LabelOperationMetadata (com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ListAnnotatedDatasetsPagedResponse (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient.ListAnnotatedDatasetsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ImageClassificationConfig (com.google.cloud.datalabeling.v1beta1.ImageClassificationConfig)1 LabelImageRequest (com.google.cloud.datalabeling.v1beta1.LabelImageRequest)1 LabelTextRequest (com.google.cloud.datalabeling.v1beta1.LabelTextRequest)1 LabelVideoRequest (com.google.cloud.datalabeling.v1beta1.LabelVideoRequest)1 SentimentConfig (com.google.cloud.datalabeling.v1beta1.SentimentConfig)1 TextClassificationConfig (com.google.cloud.datalabeling.v1beta1.TextClassificationConfig)1 VideoClassificationConfig (com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig)1 AnnotationSpecSetConfig (com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig.AnnotationSpecSetConfig)1