You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/06/01 07:30:11 UTC

[GitHub] [beam] mwalenia commented on a change in pull request #11331: [BEAM-9646] Add Google Cloud vision integration transform

mwalenia commented on a change in pull request #11331:
URL: https://github.com/apache/beam/pull/11331#discussion_r433082826



##########
File path: sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateImages.java
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.AnnotateImageResponse;
+import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.ImageAnnotatorClient;
+import com.google.cloud.vision.v1.ImageContext;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Random;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.GroupIntoBatches;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.SerializableFunction;
+import org.apache.beam.sdk.transforms.WithKeys;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.apache.beam.sdk.values.TypeDescriptors;
+
+/**
+ * Parent class for transform utilizing Cloud Vision API. https://cloud.google.com/vision/docs/batch
+ * Max batch size limit is imposed by the API for synchronous requests.
+ *
+ * @param <T> Type of input PCollection.
+ */
+@Experimental
+abstract class AnnotateImages<T>
+    extends PTransform<PCollection<T>, PCollection<List<AnnotateImageResponse>>> {
+
+  private static final Long MIN_BATCH_SIZE = 1L;
+  private static final Long MAX_BATCH_SIZE = 16L;
+
+  protected final PCollectionView<Map<T, ImageContext>> contextSideInput;
+  protected final List<Feature> featureList;
+  private final long batchSize;
+  protected final int numKeys;
+
+  /**
+   * @param contextSideInput Side input optionally containting a map of elements to {@link
+   *     ImageContext} objects with metadata for the analysis.
+   * @param featureList list of features to be extracted from the image.
+   * @param batchSize desired size of request batches sent to Cloud Vision API. At least 1, at most
+   *     16.
+   * @param numKeys number of keys to map the requests into for batching.
+   */
+  public AnnotateImages(
+      @Nullable PCollectionView<Map<T, ImageContext>> contextSideInput,
+      List<Feature> featureList,
+      long batchSize,

Review comment:
       It cannot, there is no unit for this parameter - it's the number of images batched into one request for analysis.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org