Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"byte": lambda f: example_pb2.Feature(
bytes_list=example_pb2.BytesList(value=f)),
"float": lambda f: example_pb2.Feature(
-------
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()
example.ParseFromString(record)
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