Search in sources :

Example 6 with DataLabelingServiceSettings

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

Example 7 with DataLabelingServiceSettings

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

the class CreateAnnotationSpecSet method createAnnotationSpecSet.

// Create an annotation spec set.
static void createAnnotationSpecSet(String projectId) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";
    Map<String, String> annotationLabels = new HashMap<>();
    annotationLabels.put("label_1", "label_1_description");
    annotationLabels.put("label_2", "label_2_description");
    // [END datalabeling_create_annotation_spec_set_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_create_annotation_spec_set_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        ProjectName projectName = ProjectName.of(projectId);
        List<AnnotationSpec> annotationSpecs = new ArrayList<>();
        for (Entry<String, String> entry : annotationLabels.entrySet()) {
            AnnotationSpec annotationSpec = AnnotationSpec.newBuilder().setDisplayName(entry.getKey()).setDescription(entry.getValue()).build();
            annotationSpecs.add(annotationSpec);
        }
        AnnotationSpecSet annotationSpecSet = AnnotationSpecSet.newBuilder().setDisplayName("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").addAllAnnotationSpecs(annotationSpecs).build();
        CreateAnnotationSpecSetRequest request = CreateAnnotationSpecSetRequest.newBuilder().setAnnotationSpecSet(annotationSpecSet).setParent(projectName.toString()).build();
        AnnotationSpecSet result = dataLabelingServiceClient.createAnnotationSpecSet(request);
        System.out.format("Name: %s\n", result.getName());
        System.out.format("DisplayName: %s\n", result.getDisplayName());
        System.out.format("Description: %s\n", result.getDescription());
        System.out.format("Annotation Count: %d\n", result.getAnnotationSpecsCount());
        for (AnnotationSpec annotationSpec : result.getAnnotationSpecsList()) {
            System.out.format("\tDisplayName: %s\n", annotationSpec.getDisplayName());
            System.out.format("\tDescription: %s\n\n", annotationSpec.getDescription());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) HashMap(java.util.HashMap) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) AnnotationSpecSet(com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationSpec(com.google.cloud.datalabeling.v1beta1.AnnotationSpec) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) CreateAnnotationSpecSetRequest(com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest)

Example 8 with DataLabelingServiceSettings

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

the class CreateInstruction method createInstruction.

// Create a instruction for a dataset.
static void createInstruction(String projectId, String pdfUri) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";
    // String pdfUri = "gs://YOUR_BUCKET_ID/path_to_pdf_or_csv";
    // [END datalabeling_create_instruction_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_create_instruction_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        ProjectName projectName = ProjectName.of(projectId);
        // There are two types of instructions: CSV (CsvInstruction) or PDF (PdfInstruction)
        PdfInstruction pdfInstruction = PdfInstruction.newBuilder().setGcsFileUri(pdfUri).build();
        Instruction instruction = Instruction.newBuilder().setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.IMAGE).setPdfInstruction(// .setCsvInstruction() or .setPdfInstruction()
        pdfInstruction).build();
        CreateInstructionRequest createInstructionRequest = CreateInstructionRequest.newBuilder().setInstruction(instruction).setParent(projectName.toString()).build();
        OperationFuture<Instruction, CreateInstructionMetadata> operation = dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);
        Instruction result = operation.get();
        System.out.format("Name: %s\n", result.getName());
        System.out.format("DisplayName: %s\n", result.getDisplayName());
        System.out.format("Description: %s\n", result.getDescription());
        System.out.format("GCS SOURCE URI: %s\n", result.getPdfInstruction().getGcsFileUri());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) CreateInstructionRequest(com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest) IOException(java.io.IOException) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) CreateInstructionMetadata(com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)8 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)8 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)6 AnnotatedDataset (com.google.cloud.datalabeling.v1beta1.AnnotatedDataset)3 HumanAnnotationConfig (com.google.cloud.datalabeling.v1beta1.HumanAnnotationConfig)3 LabelOperationMetadata (com.google.cloud.datalabeling.v1beta1.LabelOperationMetadata)3 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)3 AnnotationSpec (com.google.cloud.datalabeling.v1beta1.AnnotationSpec)1 AnnotationSpecSet (com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet)1 CreateAnnotationSpecSetRequest (com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest)1 CreateDatasetRequest (com.google.cloud.datalabeling.v1beta1.CreateDatasetRequest)1 CreateInstructionMetadata (com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata)1 CreateInstructionRequest (com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest)1 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)1 ExportDataOperationMetadata (com.google.cloud.datalabeling.v1beta1.ExportDataOperationMetadata)1 ExportDataOperationResponse (com.google.cloud.datalabeling.v1beta1.ExportDataOperationResponse)1 ExportDataRequest (com.google.cloud.datalabeling.v1beta1.ExportDataRequest)1 GcsDestination (com.google.cloud.datalabeling.v1beta1.GcsDestination)1 GcsSource (com.google.cloud.datalabeling.v1beta1.GcsSource)1