How to use the tfrecord.example_pb2.Features function in tfrecord

To help you get started, we’ve selected a few tfrecord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vahidk / tfrecord / tfrecord / View on Github external
feature_map = {
            "byte": lambda f: example_pb2.Feature(
            "float": lambda f: example_pb2.Feature(
            "int": lambda f: example_pb2.Feature(

        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()