forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BEAM-9147] Make VideoIntelligence use PTransform on user-facing API (a…
…pache#11464) [BEAM-9147] Make VideoIntelligence use PTransform on user-facing API
- Loading branch information
Showing
9 changed files
with
294 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...s/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoBytesWithContextFn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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:https://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.videointelligence.v1.Feature; | ||
import com.google.cloud.videointelligence.v1.VideoAnnotationResults; | ||
import com.google.cloud.videointelligence.v1.VideoContext; | ||
import com.google.protobuf.ByteString; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import org.apache.beam.sdk.annotations.Experimental; | ||
import org.apache.beam.sdk.values.KV; | ||
|
||
/** | ||
* Implementation of AnnotateVideoFn accepting KVs as contents of input PCollection. Keys are the | ||
* ByteString encoded video contents, values - VideoContext objects. | ||
*/ | ||
@Experimental | ||
class AnnotateVideoBytesWithContextFn extends AnnotateVideoFn<KV<ByteString, VideoContext>> { | ||
|
||
public AnnotateVideoBytesWithContextFn(List<Feature> featureList) { | ||
super(featureList); | ||
} | ||
|
||
/** ProcessElement implementation. */ | ||
@Override | ||
public void processElement(ProcessContext context) | ||
throws ExecutionException, InterruptedException { | ||
ByteString element = context.element().getKey(); | ||
VideoContext videoContext = context.element().getValue(); | ||
List<VideoAnnotationResults> videoAnnotationResults = | ||
getVideoAnnotationResults(null, element, videoContext); | ||
context.output(videoAnnotationResults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...tensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoFromBytesFn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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:https://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.videointelligence.v1.Feature; | ||
import com.google.cloud.videointelligence.v1.VideoAnnotationResults; | ||
import com.google.cloud.videointelligence.v1.VideoContext; | ||
import com.google.protobuf.ByteString; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import org.apache.beam.sdk.annotations.Experimental; | ||
import org.apache.beam.sdk.values.PCollectionView; | ||
|
||
/** | ||
* Implementation of AnnotateVideoFn accepting ByteStrings as contents of input PCollection. Videos | ||
* decoded from the ByteStrings are annotated. | ||
*/ | ||
@Experimental | ||
class AnnotateVideoFromBytesFn extends AnnotateVideoFn<ByteString> { | ||
|
||
public AnnotateVideoFromBytesFn( | ||
PCollectionView<Map<ByteString, VideoContext>> contextSideInput, List<Feature> featureList) { | ||
super(contextSideInput, featureList); | ||
} | ||
|
||
/** Implementation of ProcessElement. */ | ||
@Override | ||
public void processElement(ProcessContext context) | ||
throws ExecutionException, InterruptedException { | ||
ByteString element = context.element(); | ||
VideoContext videoContext = null; | ||
if (contextSideInput != null) { | ||
videoContext = context.sideInput(contextSideInput).get(element); | ||
} | ||
List<VideoAnnotationResults> videoAnnotationResults = | ||
getVideoAnnotationResults(null, element, videoContext); | ||
context.output(videoAnnotationResults); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoFromURIFn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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:https://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.videointelligence.v1.Feature; | ||
import com.google.cloud.videointelligence.v1.VideoAnnotationResults; | ||
import com.google.cloud.videointelligence.v1.VideoContext; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import org.apache.beam.sdk.annotations.Experimental; | ||
import org.apache.beam.sdk.values.PCollectionView; | ||
|
||
/** | ||
* Implementation of AnnotateVideoFn accepting Strings as contents of input PCollection. Annotates | ||
* videos found on GCS based on URIs from input PCollection. | ||
*/ | ||
@Experimental | ||
class AnnotateVideoFromURIFn extends AnnotateVideoFn<String> { | ||
|
||
public AnnotateVideoFromURIFn( | ||
PCollectionView<Map<String, VideoContext>> contextSideInput, List<Feature> featureList) { | ||
super(contextSideInput, featureList); | ||
} | ||
|
||
/** ProcessElement implementation. */ | ||
@Override | ||
public void processElement(ProcessContext context) | ||
throws ExecutionException, InterruptedException { | ||
String elementURI = context.element(); | ||
VideoContext videoContext = null; | ||
if (contextSideInput != null) { | ||
videoContext = context.sideInput(contextSideInput).get(elementURI); | ||
} | ||
List<VideoAnnotationResults> annotationResultsList = | ||
getVideoAnnotationResults(elementURI, null, videoContext); | ||
context.output(annotationResultsList); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ons/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoURIWithContextFn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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:https://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.videointelligence.v1.Feature; | ||
import com.google.cloud.videointelligence.v1.VideoAnnotationResults; | ||
import com.google.cloud.videointelligence.v1.VideoContext; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import org.apache.beam.sdk.annotations.Experimental; | ||
import org.apache.beam.sdk.values.KV; | ||
|
||
/** | ||
* Implementation of AnnotateVideoFn accepting KVs as contents of input PCollection. Keys are the | ||
* GCS URIs, values - VideoContext objects. | ||
*/ | ||
@Experimental | ||
class AnnotateVideoURIWithContextFn extends AnnotateVideoFn<KV<String, VideoContext>> { | ||
|
||
public AnnotateVideoURIWithContextFn(List<Feature> featureList) { | ||
super(featureList); | ||
} | ||
|
||
/** ProcessElement implementation. */ | ||
@Override | ||
public void processElement(ProcessContext context) | ||
throws ExecutionException, InterruptedException { | ||
String elementURI = context.element().getKey(); | ||
VideoContext videoContext = context.element().getValue(); | ||
List<VideoAnnotationResults> videoAnnotationResults = | ||
getVideoAnnotationResults(elementURI, null, videoContext); | ||
context.output(videoAnnotationResults); | ||
} | ||
} |
Oops, something went wrong.