Class CloudVision.AnnotateImagesFromGcsUriWithContext

  • All Implemented Interfaces:
    java.io.Serializable, org.apache.beam.sdk.transforms.display.HasDisplayData
    Enclosing class:
    CloudVision

    public static class CloudVision.AnnotateImagesFromGcsUriWithContext
    extends org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<T>,​org.apache.beam.sdk.values.PCollection<java.util.List<com.google.cloud.vision.v1.AnnotateImageResponse>>>
    Accepts KVs of String (GCS URI to the image) and ImageContext. It's possible to add ImageContext to each image to be annotated.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.beam.sdk.values.PCollectionView<java.util.Map<T,​com.google.cloud.vision.v1.ImageContext>> contextSideInput  
      protected int desiredRequestParallelism  
      protected java.util.List<com.google.cloud.vision.v1.Feature> featureList  
      • Fields inherited from class org.apache.beam.sdk.transforms.PTransform

        annotations, displayData, name, resourceHints
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotateImagesFromGcsUriWithContext​(java.util.List<com.google.cloud.vision.v1.Feature> featureList, long batchSize, int desiredRequestParallelism)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.beam.sdk.values.PCollection<java.util.List<com.google.cloud.vision.v1.AnnotateImageResponse>> expand​(org.apache.beam.sdk.values.PCollection<T> input)
      Applies all necessary transforms to call the Vision API.
      com.google.cloud.vision.v1.AnnotateImageRequest mapToRequest​(org.apache.beam.sdk.values.KV<java.lang.String,​com.google.cloud.vision.v1.ImageContext> input, @Nullable com.google.cloud.vision.v1.ImageContext ctx)
      Maps KV of String (GCS URI to the image) and ImageContext to a valid AnnotateImageRequest.
      • Methods inherited from class org.apache.beam.sdk.transforms.PTransform

        addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • contextSideInput

        protected final org.apache.beam.sdk.values.PCollectionView<java.util.Map<T,​com.google.cloud.vision.v1.ImageContext>> contextSideInput
      • featureList

        protected final java.util.List<com.google.cloud.vision.v1.Feature> featureList
      • desiredRequestParallelism

        protected final int desiredRequestParallelism
    • Constructor Detail

      • AnnotateImagesFromGcsUriWithContext

        public AnnotateImagesFromGcsUriWithContext​(java.util.List<com.google.cloud.vision.v1.Feature> featureList,
                                                   long batchSize,
                                                   int desiredRequestParallelism)
    • Method Detail

      • mapToRequest

        public com.google.cloud.vision.v1.AnnotateImageRequest mapToRequest​(org.apache.beam.sdk.values.KV<java.lang.String,​com.google.cloud.vision.v1.ImageContext> input,
                                                                            @Nullable com.google.cloud.vision.v1.ImageContext ctx)
        Maps KV of String (GCS URI to the image) and ImageContext to a valid AnnotateImageRequest.
        Parameters:
        input - Input element.
        ctx - optional image context, ignored here since the input holds context.
        Returns:
        a valid request.
      • expand

        public org.apache.beam.sdk.values.PCollection<java.util.List<com.google.cloud.vision.v1.AnnotateImageResponse>> expand​(org.apache.beam.sdk.values.PCollection<T> input)
        Applies all necessary transforms to call the Vision API. In order to group requests into batches, we assign keys to the requests, as GroupIntoBatches works only on KVs.
        Specified by:
        expand in class org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<T>,​org.apache.beam.sdk.values.PCollection<java.util.List<com.google.cloud.vision.v1.AnnotateImageResponse>>>