2525import numpy as np
2626import tensorflow as tf
2727from google .protobuf import json_format
28+ from six import binary_type , string_types , integer_types
2829from six import iteritems
29- from six import string_types , integer_types
3030from six .moves import zip # pylint: disable=redefined-builtin
3131
3232from tensorboard .plugins .interactive_inference .utils import common_utils
@@ -125,7 +125,8 @@ class OriginalFeatureList(object):
125125 def __init__ (self , feature_name , original_value , feature_type ):
126126 """Inits OriginalFeatureList."""
127127 self .feature_name = feature_name
128- self .original_value = original_value
128+ self .original_value = [
129+ ensure_not_binary (value ) for value in original_value ]
129130 self .feature_type = feature_type
130131
131132 # Derived attributes.
@@ -164,7 +165,8 @@ def __init__(self, original_feature, index, mutant_value):
164165 'index should be None or int, but had unexpected type: {}' .format (
165166 type (index )))
166167 self .index = index
167- self .mutant_value = mutant_value
168+ self .mutant_value = (mutant_value .encode ()
169+ if isinstance (mutant_value , string_types ) else mutant_value )
168170
169171
170172class ServingBundle (object ):
@@ -226,6 +228,11 @@ def __init__(self, inference_address, model_name, model_type, model_version,
226228 self .custom_predict_fn = custom_predict_fn
227229
228230
231+ def ensure_not_binary (value ):
232+ """Return non-binary version of value."""
233+ return value .decode () if isinstance (value , binary_type ) else value
234+
235+
229236def proto_value_for_feature (example , feature_name ):
230237 """Get the value of a feature from Example regardless of feature type."""
231238 feature = get_example_features (example )[feature_name ]
@@ -563,9 +570,10 @@ def make_json_formatted_for_single_chart(mutant_features,
563570 key += ' (index %d)' % index_to_mutate
564571 if not key in series :
565572 series [key ] = {}
566- if not mutant_feature .mutant_value in series [key ]:
567- series [key ][mutant_feature .mutant_value ] = []
568- series [key ][mutant_feature .mutant_value ].append (
573+ mutant_val = ensure_not_binary (mutant_feature .mutant_value )
574+ if not mutant_val in series [key ]:
575+ series [key ][mutant_val ] = []
576+ series [key ][mutant_val ].append (
569577 classification_class .score )
570578
571579 # Post-process points to have separate list for each class
@@ -589,9 +597,10 @@ def make_json_formatted_for_single_chart(mutant_features,
589597 # results. So, modding by len(mutant_features) allows us to correctly
590598 # lookup the mutant value for each inference.
591599 mutant_feature = mutant_features [idx % len (mutant_features )]
592- if not mutant_feature .mutant_value in points :
593- points [mutant_feature .mutant_value ] = []
594- points [mutant_feature .mutant_value ].append (regression .value )
600+ mutant_val = ensure_not_binary (mutant_feature .mutant_value )
601+ if not mutant_val in points :
602+ points [mutant_val ] = []
603+ points [mutant_val ].append (regression .value )
595604 key = 'value'
596605 if (index_to_mutate != 0 ):
597606 key += ' (index %d)' % index_to_mutate
0 commit comments