def generate_sprite(self, example_strings): # Generate a sprite image for the examples if the examples contain the # standard encoded image feature. feature_list = (self.examples[0].features.feature if self.example_class == tf.train.Example else self.examples[0].context.feature) self.sprite = (inference_utils.create_sprite_image(example_strings) if (len(self.examples) and self.image_feature_name in feature_list) else None)
def create_sprite(self): """Returns an encoded image of thumbnails for image examples.""" # Generate a sprite image for the examples if the examples contain the # standard encoded image feature. if not self.examples: return None example_to_check = self.json_to_proto(self.examples[0]) feature_list = (example_to_check.context.feature if self.config.get('are_sequence_examples') else example_to_check.features.feature) if 'image/encoded' in feature_list: example_strings = [ self.json_to_proto(ex).SerializeToString() for ex in self.examples] encoded = ensure_str(base64.b64encode( inference_utils.create_sprite_image(example_strings))) return 'data:image/png;base64,{}'.format(encoded) else: return None