I\'m trying to optimize the input pipeline for .h5 data with tf.data. But I encountered a TypeError: expected str, bytes or os.PathLike object, not Tensor
. I did a
Here is an example of how you can wrap the function with the help of py_func. Do note that this is deprecated in TF V2. You can follow the documentation for further details.
def parse_function_wrapper(filename):
# Assuming your data and labels are float32
# Your input is parse_function, who arg is filename, and you get X and y as output
# whose datatypes are indicated by the tuple argument
features, labels = tf.py_func(
parse_function, [filename], (tf.float32, tf.float32))
return features, labels
# Create dataset of filenames.
dataset = tf.data.Dataset.from_tensor_slices(flist)
dataset = dataset.shuffle(len(flist))
dataset = dataset.map(parse_function_wrapper)