Skip to content

Commit

Permalink
Update Likelihood protobuf conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 13, 2017
1 parent 69f64e7 commit 28bc79e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
1 change: 1 addition & 0 deletions vision/google/cloud/vision/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _process_image_annotations(image):
:returns: Dictionary populated with entities from response.
"""
return {
'faces': _make_faces_from_pb(image.face_annotations),
'labels': _make_entity_from_pb(image.label_annotations),
'landmarks': _make_entity_from_pb(image.landmark_annotations),
'logos': _make_entity_from_pb(image.logo_annotations),
Expand Down
17 changes: 4 additions & 13 deletions vision/google/cloud/vision/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@

from enum import Enum

from google.cloud.grpc.vision.v1 import image_annotator_pb2

from google.cloud.vision.geometry import BoundsBase
from google.cloud.vision.likelihood import Likelihood
from google.cloud.vision.geometry import Position


LIKELIHOOD_PB = {
0: 'UNKNOWN',
1: 'VERY_UNLIKELY',
2: 'UNLIKELY',
3: 'POSSIBLE',
4: 'LIKELY',
5: 'VERY_LIKELY',
}


def _get_pb_likelihood(likelihood):
"""Convert gRPC Likelihood integer value to Likelihood instance.
Expand All @@ -41,7 +33,7 @@ def _get_pb_likelihood(likelihood):
:rtype: :class:`~google.cloud.vision.likelihood.Likelihood`
:returns: Instance of ``Likelihood`` converted from gRPC value.
"""
likelihood_pb = LIKELIHOOD_PB.get(likelihood)
likelihood_pb = image_annotator_pb2.Likelihood.Name(likelihood)
return Likelihood[likelihood_pb]


Expand Down Expand Up @@ -256,8 +248,7 @@ def from_pb(cls, response):
detection_confidence = response.detection_confidence
emotions = Emotions.from_pb(response)
fd_bounds = FDBounds.from_pb(response.fd_bounding_poly)
headwear_likelihood = Likelihood[
LIKELIHOOD_PB[response.headwear_likelihood]]
headwear_likelihood = _get_pb_likelihood(response.headwear_likelihood)
image_properties = FaceImageProperties.from_pb(response)
landmarks = Landmarks.from_pb(response.landmarks)
landmarking_confidence = response.landmarking_confidence
Expand Down

0 comments on commit 28bc79e

Please sign in to comment.