apache_beam.ml.gcp.videointelligenceml module¶
A connector for sending API requests to the GCP Video Intelligence API.
-
class
apache_beam.ml.gcp.videointelligenceml.AnnotateVideo(features, location_id=None, metadata=None, timeout=120, context_side_input=None)[source]¶ Bases:
apache_beam.transforms.ptransform.PTransformA
PTransformfor annotating video using the GCP Video Intelligence API ref: https://cloud.google.com/video-intelligence/docsSends each element to the GCP Video Intelligence API. Element is a Union[text_type, binary_type] of either an URI (e.g. a GCS URI) or binary_type base64-encoded video data. Accepts an AsDict side input that maps each video to a video context.
Parameters: - features – (List[
videointelligence_v1.enums.Feature]) Required. The Video Intelligence API features to detect - location_id – (str) Optional. Cloud region where annotation should take place. If no region is specified, a region will be determined based on video file location.
- metadata – (Sequence[Tuple[str, str]]) Optional. Additional metadata that is provided to the method.
- timeout – (int) Optional. The time in seconds to wait for the response from the Video Intelligence API
- context_side_input –
(beam.pvalue.AsDict) Optional. An
AsDictof a PCollection to be passed to the _VideoAnnotateFn as the video context mapping containing additional video context and/or feature-specific parameters. Example usage:video_contexts = [('gs://cloud-samples-data/video/cat.mp4', Union[dict, ``videointelligence_v1.types.VideoContext``]), ('gs://some-other-video/sample.mp4', Union[dict, ``videointelligence_v1.types.VideoContext``]),] context_side_input = ( p | "Video contexts" >> beam.Create(video_contexts) ) videointelligenceml.AnnotateVideo(features, context_side_input=beam.pvalue.AsDict(context_side_input)))
-
annotations() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
default_label()¶
-
default_type_hints()¶
-
display_data()¶ Returns the display data associated to a pipeline component.
It should be reimplemented in pipeline components that wish to have static display data.
Returns: A dictionary containing key:valuepairs. The value might be an integer, float or string value; aDisplayDataItemfor values that have more data (e.g. short value, label, url); or aHasDisplayDatainstance that has more display data that should be picked up. For example:{ 'key1': 'string_value', 'key2': 1234, 'key3': 3.14159265, 'key4': DisplayDataItem('apache.org', url='http://apache.org'), 'key5': subComponent }
Return type: Dict[str, Any]
-
classmethod
from_runner_api(proto, context)¶
-
get_type_hints()¶ Gets and/or initializes type hints for this object.
If type hints have not been set, attempts to initialize type hints in this order: - Using self.default_type_hints(). - Using self.__class__ type hints.
-
get_windowing(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type(unused_input_type)¶
-
label¶
-
pipeline= None¶
-
classmethod
register_urn(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input()¶
-
side_inputs= ()¶
-
to_runner_api(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter(unused_context)¶
-
to_runner_api_pickled(unused_context)¶
-
type_check_inputs(pvalueish)¶
-
type_check_inputs_or_outputs(pvalueish, input_or_output)¶
-
type_check_outputs(pvalueish)¶
-
with_input_types(input_type_hint)¶ Annotates the input type of a
PTransformwith a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint.Raises: TypeError– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()for further details.Returns: A reference to the instance of this particular PTransformobject. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types(type_hint)¶ Annotates the output type of a
PTransformwith a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint.Raises: TypeError– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()for further details.Returns: A reference to the instance of this particular PTransformobject. This allows chaining type-hinting related methods.Return type: PTransform
- features – (List[
-
class
apache_beam.ml.gcp.videointelligenceml.AnnotateVideoWithContext(features, location_id=None, metadata=None, timeout=120)[source]¶ Bases:
apache_beam.ml.gcp.videointelligenceml.AnnotateVideoA
PTransformfor annotating video using the GCP Video Intelligence API ref: https://cloud.google.com/video-intelligence/docsSends each element to the GCP Video Intelligence API. Element is a tuple of
(Union[text_type, binary_type], Optional[videointelligence.types.VideoContext])where the former is either an URI (e.g. a GCS URI) or binary_type base64-encoded video data
Parameters: - features – (List[
videointelligence_v1.enums.Feature]) Required. the Video Intelligence API features to detect - location_id – (str) Optional. Cloud region where annotation should take place. If no region is specified, a region will be determined based on video file location.
- metadata – (Sequence[Tuple[str, str]]) Optional. Additional metadata that is provided to the method.
- timeout – (int) Optional. The time in seconds to wait for the response from the Video Intelligence API
-
annotations() → Dict[str, Union[bytes, str, google.protobuf.message.Message]]¶
-
default_label()¶
-
default_type_hints()¶
-
display_data()¶ Returns the display data associated to a pipeline component.
It should be reimplemented in pipeline components that wish to have static display data.
Returns: A dictionary containing key:valuepairs. The value might be an integer, float or string value; aDisplayDataItemfor values that have more data (e.g. short value, label, url); or aHasDisplayDatainstance that has more display data that should be picked up. For example:{ 'key1': 'string_value', 'key2': 1234, 'key3': 3.14159265, 'key4': DisplayDataItem('apache.org', url='http://apache.org'), 'key5': subComponent }
Return type: Dict[str, Any]
-
classmethod
from_runner_api(proto, context)¶
-
get_type_hints()¶ Gets and/or initializes type hints for this object.
If type hints have not been set, attempts to initialize type hints in this order: - Using self.default_type_hints(). - Using self.__class__ type hints.
-
get_windowing(inputs)¶ Returns the window function to be associated with transform’s output.
By default most transforms just return the windowing function associated with the input PCollection (or the first input if several).
-
infer_output_type(unused_input_type)¶
-
label¶
-
pipeline= None¶
-
classmethod
register_urn(urn, parameter_type, constructor=None)¶
-
runner_api_requires_keyed_input()¶
-
side_inputs= ()¶
-
to_runner_api(context, has_parts=False, **extra_kwargs)¶
-
to_runner_api_parameter(unused_context)¶
-
to_runner_api_pickled(unused_context)¶
-
type_check_inputs(pvalueish)¶
-
type_check_inputs_or_outputs(pvalueish, input_or_output)¶
-
type_check_outputs(pvalueish)¶
-
with_input_types(input_type_hint)¶ Annotates the input type of a
PTransformwith a type-hint.Parameters: input_type_hint (type) – An instance of an allowed built-in type, a custom class, or an instance of a TypeConstraint.Raises: TypeError– If input_type_hint is not a valid type-hint. Seeapache_beam.typehints.typehints.validate_composite_type_param()for further details.Returns: A reference to the instance of this particular PTransformobject. This allows chaining type-hinting related methods.Return type: PTransform
-
with_output_types(type_hint)¶ Annotates the output type of a
PTransformwith a type-hint.Parameters: type_hint (type) – An instance of an allowed built-in type, a custom class, or a TypeConstraint.Raises: TypeError– If type_hint is not a valid type-hint. Seevalidate_composite_type_param()for further details.Returns: A reference to the instance of this particular PTransformobject. This allows chaining type-hinting related methods.Return type: PTransform
- features – (List[