How to feed .h5 files in tf.data pipeline in tensorflow model

前端 未结 1 1399
夕颜
夕颜 2021-01-26 11:03

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

相关标签:
1条回答
  • 2021-01-26 11:29

    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)
    
    0 讨论(0)
提交回复
热议问题