How to use the Tensorflow Dataset Pipeline for Variable Length Inputs?

后端 未结 1 1446
名媛妹妹
名媛妹妹 2021-02-09 23:21

I am training a Recurrent Neural Network in Tensorflow over a dataset of sequence of numbers of varying lengths and have been trying to use the tf.data API to creat

1条回答
  •  北海茫月
    2021-02-09 23:36

    As you have noticed, tf.data.Dataset.from_tensor_slices() only works on objects that can be converted to a (dense) tf.Tensor or a tf.SparseTensor. The easiest way to get variable-length NumPy data into a Dataset is to use tf.data.Dataset.from_generator(), as follows:

    dataset = tf.data.Dataset.from_generator(lambda: dataset_list, 
                                             tf.as_dtype(dataset_list[0].dtype),
                                             tf.TensorShape([None, 32, 2]))
    

    0 讨论(0)
提交回复
热议问题