How to use the tfrecord.example_pb2 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
            "byte": lambda f: example_pb2.Feature(
            "float": lambda f: example_pb2.Feature(
github vahidk / tfrecord / tfrecord / View on Github external
    features: dict of {str, np.ndarray}
        Decoded bytes of the features into its respective data type (for
        an individual record).

    typename_mapping = {
        "byte": "bytes_list",
        "float": "float_list",
        "int": "int64_list"

    record_iterator = tfrecord_iterator(data_path, index_path, shard)

    for record in record_iterator:
        example = example_pb2.Example()

        all_keys = list(example.features.feature.keys())
        if description is None:
            description = dict.fromkeys(all_keys, None)
        elif isinstance(description, list):
            description = dict.fromkeys(description, None)

        features = {}
        for key, typename in description.items():
            if key not in all_keys:
                raise KeyError(f"Key {key} doesn't exist (select from {all_keys})!")
            # NOTE: We assume that each key in the example has only one field
            # (either "bytes_list", "float_list", or "int64_list")!
            field = example.features.feature[key].ListFields()[0]
            inferred_typename, value = field[0].name, field[1].value