Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
feature_map = {
"byte": lambda f: example_pb2.Feature(
bytes_list=example_pb2.BytesList(value=f)),
"float": lambda f: example_pb2.Feature(
float_list=example_pb2.FloatList(value=f)),
"int": lambda f: example_pb2.Feature(
int64_list=example_pb2.Int64List(value=f))
}
def serialize(value, dtype):
if not isinstance(value, (list, tuple, np.ndarray)):
value = [value]
return feature_map[dtype](value)
features = {key: serialize(value, dtype) for key, (value, dtype) in datum.items()}
example_proto = example_pb2.Example(features=example_pb2.Features(feature=features))
return example_proto.SerializeToString()