Search in sources :

Example 1 with AnnotationSpecSetConfig

use of com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig.AnnotationSpecSetConfig 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)1 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)1 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)1 HumanAnnotationConfig (com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig)1 LabelOperationMetadata (com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata)1 LabelVideoRequest (com.google.cloud.datalabeling.v1beta1.LabelVideoRequest)1 VideoClassificationConfig (com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig)1 AnnotationSpecSetConfig (com.google.cloud.datalabeling.v1beta1.VideoClassificationConfig.AnnotationSpecSetConfig)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1