Example #1
0
 def do_decode(self, value, decode_fn):
     return tensor_spec.TensorSpec(
         shape=decode_fn(
             struct_pb2.StructuredValue(
                 tensor_shape_value=value.tensor_spec_value.shape)),
         dtype=decode_fn(
             struct_pb2.StructuredValue(
                 tensor_dtype_value=value.tensor_spec_value.dtype)),
         name=value.tensor_spec_value.name)
Example #2
0
 def do_encode(self, tensor_spec_value, encode_fn):
     encoded_tensor_spec = struct_pb2.StructuredValue()
     encoded_tensor_spec.tensor_spec_value.CopyFrom(
         struct_pb2.TensorSpecProto(
             shape=encode_fn(tensor_spec_value.shape).tensor_shape_value,
             dtype=encode_fn(tensor_spec_value.dtype).tensor_dtype_value,
             name=tensor_spec_value.name))
     return encoded_tensor_spec
Example #3
0
 def do_encode(self, named_tuple_value, encode_fn):
   encoded_named_tuple = struct_pb2.StructuredValue()
   encoded_named_tuple.named_tuple_value.CopyFrom(struct_pb2.NamedTupleValue())
   encoded_named_tuple.named_tuple_value.name = \
     named_tuple_value.__class__.__name__
   for key in named_tuple_value._fields:
     pair = encoded_named_tuple.named_tuple_value.values.add()
     pair.key = key
     pair.value.CopyFrom(encode_fn(named_tuple_value._asdict()[key]))
   return encoded_named_tuple
Example #4
0
 def do_encode(self, tensor_dtype_value, encode_fn):
     del encode_fn
     encoded_tensor_type = struct_pb2.StructuredValue()
     encoded_tensor_type.tensor_dtype_value = tensor_dtype_value.as_datatype_enum
     return encoded_tensor_type
Example #5
0
 def do_encode(self, tensor_shape_value, encode_fn):
     del encode_fn
     encoded_tensor_shape = struct_pb2.StructuredValue()
     encoded_tensor_shape.tensor_shape_value.CopyFrom(
         tensor_shape_value.as_proto())
     return encoded_tensor_shape
Example #6
0
 def do_encode(self, bool_value, encode_fn):
     del encode_fn
     value = struct_pb2.StructuredValue()
     value.bool_value = bool_value
     return value
Example #7
0
 def do_encode(self, none_value, encode_fn):
     del encode_fn, none_value
     value = struct_pb2.StructuredValue()
     value.none_value.CopyFrom(struct_pb2.NoneValue())
     return value
Example #8
0
 def do_encode(self, string_value, encode_fn):
     del encode_fn
     value = struct_pb2.StructuredValue()
     value.string_value = string_value
     return value
Example #9
0
 def do_encode(self, int_value, encode_fn):
     del encode_fn
     value = struct_pb2.StructuredValue()
     value.int64_value = int_value
     return value
Example #10
0
 def do_encode(self, float64_value, encode_fn):
     del encode_fn
     value = struct_pb2.StructuredValue()
     value.float64_value = float64_value
     return value
Example #11
0
 def do_encode(self, dict_value, encode_fn):
     encoded_dict = struct_pb2.StructuredValue()
     encoded_dict.dict_value.CopyFrom(struct_pb2.DictValue())
     for key, value in dict_value.items():
         encoded_dict.dict_value.fields[key].CopyFrom(encode_fn(value))
     return encoded_dict
Example #12
0
 def do_encode(self, tuple_value, encode_fn):
     encoded_tuple = struct_pb2.StructuredValue()
     encoded_tuple.tuple_value.CopyFrom(struct_pb2.TupleValue())
     for element in tuple_value:
         encoded_tuple.tuple_value.values.add().CopyFrom(encode_fn(element))
     return encoded_tuple
Example #13
0
 def do_encode(self, list_value, encode_fn):
     encoded_list = struct_pb2.StructuredValue()
     encoded_list.list_value.CopyFrom(struct_pb2.ListValue())
     for element in list_value:
         encoded_list.list_value.values.add().CopyFrom(encode_fn(element))
     return encoded_list