Skip to content

Commit 28bc79e

Browse files
committed
Update Likelihood protobuf conversion.
1 parent 69f64e7 commit 28bc79e

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

vision/google/cloud/vision/annotations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def _process_image_annotations(image):
119119
:returns: Dictionary populated with entities from response.
120120
"""
121121
return {
122+
'faces': _make_faces_from_pb(image.face_annotations),
122123
'labels': _make_entity_from_pb(image.label_annotations),
123124
'landmarks': _make_entity_from_pb(image.landmark_annotations),
124125
'logos': _make_entity_from_pb(image.logo_annotations),

vision/google/cloud/vision/face.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,13 @@
1717

1818
from enum import Enum
1919

20+
from google.cloud.grpc.vision.v1 import image_annotator_pb2
21+
2022
from google.cloud.vision.geometry import BoundsBase
2123
from google.cloud.vision.likelihood import Likelihood
2224
from google.cloud.vision.geometry import Position
2325

2426

25-
LIKELIHOOD_PB = {
26-
0: 'UNKNOWN',
27-
1: 'VERY_UNLIKELY',
28-
2: 'UNLIKELY',
29-
3: 'POSSIBLE',
30-
4: 'LIKELY',
31-
5: 'VERY_LIKELY',
32-
}
33-
34-
3527
def _get_pb_likelihood(likelihood):
3628
"""Convert gRPC Likelihood integer value to Likelihood instance.
3729
@@ -41,7 +33,7 @@ def _get_pb_likelihood(likelihood):
4133
:rtype: :class:`~google.cloud.vision.likelihood.Likelihood`
4234
:returns: Instance of ``Likelihood`` converted from gRPC value.
4335
"""
44-
likelihood_pb = LIKELIHOOD_PB.get(likelihood)
36+
likelihood_pb = image_annotator_pb2.Likelihood.Name(likelihood)
4537
return Likelihood[likelihood_pb]
4638

4739

@@ -256,8 +248,7 @@ def from_pb(cls, response):
256248
detection_confidence = response.detection_confidence
257249
emotions = Emotions.from_pb(response)
258250
fd_bounds = FDBounds.from_pb(response.fd_bounding_poly)
259-
headwear_likelihood = Likelihood[
260-
LIKELIHOOD_PB[response.headwear_likelihood]]
251+
headwear_likelihood = _get_pb_likelihood(response.headwear_likelihood)
261252
image_properties = FaceImageProperties.from_pb(response)
262253
landmarks = Landmarks.from_pb(response.landmarks)
263254
landmarking_confidence = response.landmarking_confidence

0 commit comments

Comments
 (0)