You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by tv...@apache.org on 2022/10/20 22:53:17 UTC
[beam] branch master updated: Update google cloud vision >= 2.0.0 (#23755)
This is an automated email from the ASF dual-hosted git repository.
tvalentyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new a138a4f86f6 Update google cloud vision >= 2.0.0 (#23755)
a138a4f86f6 is described below
commit a138a4f86f6d70dadb9eaefd16ca92d608ba5c5d
Author: Anand Inguva <34...@users.noreply.github.com>
AuthorDate: Thu Oct 20 18:53:10 2022 -0400
Update google cloud vision >= 2.0.0 (#23755)
Co-authored-by: Anand Inguva <an...@google.com>
---
sdks/python/apache_beam/ml/gcp/visionml.py | 51 ++++++++++++----------
sdks/python/apache_beam/ml/gcp/visionml_test.py | 9 ++--
sdks/python/apache_beam/ml/gcp/visionml_test_it.py | 7 ++-
.../container/py310/base_image_requirements.txt | 6 +--
.../container/py37/base_image_requirements.txt | 4 +-
.../container/py38/base_image_requirements.txt | 6 +--
.../container/py39/base_image_requirements.txt | 6 +--
sdks/python/setup.py | 2 +-
8 files changed, 51 insertions(+), 40 deletions(-)
diff --git a/sdks/python/apache_beam/ml/gcp/visionml.py b/sdks/python/apache_beam/ml/gcp/visionml.py
index 3e556b903c4..dd29dd37738 100644
--- a/sdks/python/apache_beam/ml/gcp/visionml.py
+++ b/sdks/python/apache_beam/ml/gcp/visionml.py
@@ -80,7 +80,7 @@ class AnnotateImage(PTransform):
metadata=None):
"""
Args:
- features: (List[``vision.types.Feature.enums.Feature``]) Required.
+ features: (List[``vision.Feature``]) Required.
The Vision API features to detect
retry: (google.api_core.retry.Retry) Optional.
A retry object used to retry requests.
@@ -107,9 +107,9 @@ class AnnotateImage(PTransform):
image_contexts =
[(''gs://cloud-samples-data/vision/ocr/sign.jpg'', Union[dict,
- ``vision.types.ImageContext()``]),
+ ``vision.ImageContext()``]),
(''gs://cloud-samples-data/vision/ocr/sign.jpg'', Union[dict,
- ``vision.types.ImageContext()``]),]
+ ``vision.ImageContext()``]),]
context_side_input =
(
@@ -152,9 +152,8 @@ class AnnotateImage(PTransform):
client_options=self.client_options,
metadata=self.metadata)))
- @typehints.with_input_types(
- Union[str, bytes], Optional[vision.types.ImageContext])
- @typehints.with_output_types(List[vision.types.AnnotateImageRequest])
+ @typehints.with_input_types(Union[str, bytes], Optional[vision.ImageContext])
+ @typehints.with_output_types(List[vision.AnnotateImageRequest])
def _create_image_annotation_pairs(self, element, context_side_input):
if context_side_input: # If we have a side input image context, use that
image_context = context_side_input.get(element)
@@ -162,13 +161,18 @@ class AnnotateImage(PTransform):
image_context = None
if isinstance(element, str):
- image = vision.types.Image(
- source=vision.types.ImageSource(image_uri=element))
+
+ image = vision.Image(
+ {'source': vision.ImageSource({'image_uri': element})})
+
else: # Typehint checks only allows str or bytes
- image = vision.types.Image(content=element)
+ image = vision.Image(content=element)
- request = vision.types.AnnotateImageRequest(
- image=image, features=self.features, image_context=image_context)
+ request = vision.AnnotateImageRequest({
+ 'image': image,
+ 'features': self.features,
+ 'image_context': image_context
+ })
yield request
@@ -181,7 +185,7 @@ class AnnotateImageWithContext(AnnotateImage):
Element is a tuple of::
(Union[str, bytes],
- Optional[``vision.types.ImageContext``])
+ Optional[``vision.ImageContext``])
where the former is either an URI (e.g. a GCS URI) or bytes
base64-encoded image data.
@@ -197,7 +201,7 @@ class AnnotateImageWithContext(AnnotateImage):
metadata=None):
"""
Args:
- features: (List[``vision.types.Feature.enums.Feature``]) Required.
+ features: (List[``vision.Feature``]) Required.
The Vision API features to detect
retry: (google.api_core.retry.Retry) Optional.
A retry object used to retry requests.
@@ -244,25 +248,28 @@ class AnnotateImageWithContext(AnnotateImage):
metadata=self.metadata)))
@typehints.with_input_types(
- Tuple[Union[str, bytes], Optional[vision.types.ImageContext]])
- @typehints.with_output_types(List[vision.types.AnnotateImageRequest])
+ Tuple[Union[str, bytes], Optional[vision.ImageContext]])
+ @typehints.with_output_types(List[vision.AnnotateImageRequest])
def _create_image_annotation_pairs(self, element, **kwargs):
element, image_context = element # Unpack (image, image_context) tuple
if isinstance(element, str):
- image = vision.types.Image(
- source=vision.types.ImageSource(image_uri=element))
+ image = vision.Image(
+ {'source': vision.ImageSource({'image_uri': element})})
else: # Typehint checks only allows str or bytes
- image = vision.types.Image(content=element)
+ image = vision.Image({"content": element})
- request = vision.types.AnnotateImageRequest(
- image=image, features=self.features, image_context=image_context)
+ request = vision.AnnotateImageRequest({
+ 'image': image,
+ 'features': self.features,
+ 'image_context': image_context
+ })
yield request
-@typehints.with_input_types(List[vision.types.AnnotateImageRequest])
+@typehints.with_input_types(List[vision.AnnotateImageRequest])
class _ImageAnnotateFn(DoFn):
"""A DoFn that sends each input element to the GCP Vision API.
- Returns ``google.cloud.vision.types.BatchAnnotateImagesResponse``.
+ Returns ``google.cloud.vision.BatchAnnotateImagesResponse``.
"""
def __init__(self, features, retry, timeout, client_options, metadata):
super().__init__()
diff --git a/sdks/python/apache_beam/ml/gcp/visionml_test.py b/sdks/python/apache_beam/ml/gcp/visionml_test.py
index f038442468f..479b3d80e4d 100644
--- a/sdks/python/apache_beam/ml/gcp/visionml_test.py
+++ b/sdks/python/apache_beam/ml/gcp/visionml_test.py
@@ -45,12 +45,13 @@ class VisionTest(unittest.TestCase):
self._mock_client = mock.Mock()
self._mock_client.batch_annotate_images.return_value = None
- feature_type = vision.enums.Feature.Type.TEXT_DETECTION
+ feature_type = vision.Feature.Type.TEXT_DETECTION
self.features = [
- vision.types.Feature(
- type=feature_type, max_results=3, model="builtin/stable")
+ vision.Feature({
+ 'type': feature_type, 'max_results': 3, 'model': "builtin/stable"
+ })
]
- self.img_ctx = vision.types.ImageContext()
+ self.img_ctx = vision.ImageContext()
self.min_batch_size = 1
self.max_batch_size = 1
diff --git a/sdks/python/apache_beam/ml/gcp/visionml_test_it.py b/sdks/python/apache_beam/ml/gcp/visionml_test_it.py
index 4413266dcc5..ea3fc9768ff 100644
--- a/sdks/python/apache_beam/ml/gcp/visionml_test_it.py
+++ b/sdks/python/apache_beam/ml/gcp/visionml_test_it.py
@@ -47,7 +47,8 @@ class VisionMlTestIT(unittest.TestCase):
IMAGES_TO_ANNOTATE = [
'gs://apache-beam-samples/advanced_analytics/vision/sign.jpg'
]
- IMAGE_CONTEXT = [vision.types.ImageContext(language_hints=['en'])]
+
+ IMAGE_CONTEXT = [vision.ImageContext({'language_hints': ['en']})]
with TestPipeline(is_integration_test=True) as p:
contexts = p | 'Create context' >> beam.Create(
@@ -57,7 +58,9 @@ class VisionMlTestIT(unittest.TestCase):
p
| beam.Create(IMAGES_TO_ANNOTATE)
| AnnotateImage(
- features=[vision.types.Feature(type='TEXT_DETECTION')],
+ features=[
+ vision.Feature({'type_': vision.Feature.Type.TEXT_DETECTION})
+ ],
context_side_input=beam.pvalue.AsDict(contexts))
| beam.ParDo(extract))
diff --git a/sdks/python/container/py310/base_image_requirements.txt b/sdks/python/container/py310/base_image_requirements.txt
index aeb8d0d990b..651a332f909 100644
--- a/sdks/python/container/py310/base_image_requirements.txt
+++ b/sdks/python/container/py310/base_image_requirements.txt
@@ -66,7 +66,7 @@ google-cloud-pubsublite==1.5.0
google-cloud-recommendations-ai==0.7.1
google-cloud-spanner==3.22.2
google-cloud-videointelligence==1.16.3
-google-cloud-vision==1.0.2
+google-cloud-vision==3.1.4
google-crc32c==1.5.0
google-pasta==0.2.0
google-resumable-media==2.4.0
@@ -102,7 +102,7 @@ overrides==6.5.0
packaging==21.3
pandas==1.4.4
parameterized==0.8.1
-pbr==5.10.0
+pbr==5.11.0
pluggy==1.0.0
proto-plus==1.22.1
protobuf==3.19.6
@@ -131,7 +131,7 @@ requests-mock==1.10.0
requests-oauthlib==1.3.1
rsa==4.9
scikit-learn==1.1.2
-scipy==1.9.2
+scipy==1.9.3
six==1.16.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
diff --git a/sdks/python/container/py37/base_image_requirements.txt b/sdks/python/container/py37/base_image_requirements.txt
index 53041ca821f..2dbf7d1827d 100644
--- a/sdks/python/container/py37/base_image_requirements.txt
+++ b/sdks/python/container/py37/base_image_requirements.txt
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
google-cloud-spanner==3.22.2
google-cloud-storage==2.5.0
google-cloud-videointelligence==1.16.3
-google-cloud-vision==1.0.2
+google-cloud-vision==3.1.4
google-crc32c==1.5.0
google-pasta==0.2.0
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
packaging==21.3
pandas==1.3.5
parameterized==0.8.1
-pbr==5.10.0
+pbr==5.11.0
pluggy==1.0.0
proto-plus==1.22.1
protobuf==3.19.6
diff --git a/sdks/python/container/py38/base_image_requirements.txt b/sdks/python/container/py38/base_image_requirements.txt
index e5f7fec5848..ca45ef30f85 100644
--- a/sdks/python/container/py38/base_image_requirements.txt
+++ b/sdks/python/container/py38/base_image_requirements.txt
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
google-cloud-spanner==3.22.2
google-cloud-storage==2.5.0
google-cloud-videointelligence==1.16.3
-google-cloud-vision==1.0.2
+google-cloud-vision==3.1.4
google-crc32c==1.5.0
google-pasta==0.2.0
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
packaging==21.3
pandas==1.4.4
parameterized==0.8.1
-pbr==5.10.0
+pbr==5.11.0
pluggy==1.0.0
proto-plus==1.22.1
protobuf==3.19.6
@@ -138,7 +138,7 @@ requests-mock==1.10.0
requests-oauthlib==1.3.1
rsa==4.9
scikit-learn==1.1.2
-scipy==1.9.2
+scipy==1.9.3
six==1.16.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
diff --git a/sdks/python/container/py39/base_image_requirements.txt b/sdks/python/container/py39/base_image_requirements.txt
index bc624e7df12..f4b9cdca16a 100644
--- a/sdks/python/container/py39/base_image_requirements.txt
+++ b/sdks/python/container/py39/base_image_requirements.txt
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
google-cloud-spanner==3.22.2
google-cloud-storage==2.5.0
google-cloud-videointelligence==1.16.3
-google-cloud-vision==1.0.2
+google-cloud-vision==3.1.4
google-crc32c==1.5.0
google-pasta==0.2.0
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
packaging==21.3
pandas==1.4.4
parameterized==0.8.1
-pbr==5.10.0
+pbr==5.11.0
pluggy==1.0.0
proto-plus==1.22.1
protobuf==3.19.6
@@ -138,7 +138,7 @@ requests-mock==1.10.0
requests-oauthlib==1.3.1
rsa==4.9
scikit-learn==1.1.2
-scipy==1.9.2
+scipy==1.9.3
six==1.16.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index c91fb2e71a8..aaa761b1476 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -314,7 +314,7 @@ if __name__ == '__main__':
'google-cloud-dlp>=3.0.0,<4',
'google-cloud-language>=1.3.0,<2',
'google-cloud-videointelligence>=1.8.0,<2',
- 'google-cloud-vision>=0.38.0,<2',
+ 'google-cloud-vision>=2,<4',
'google-cloud-recommendations-ai>=0.1.0,<0.8.0'
],
'interactive': [