What is the difference between Dataset.from_tensors and Dataset.from_tensor_slices?

前端 未结 4 900
轻奢々
轻奢々 2020-12-23 11:17

I have a dataset represented as a NumPy matrix of shape (num_features, num_examples) and I wish to convert it to TensorFlow type tf.Dataset.

<
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 12:03

    from_tensors combines the input and returns a dataset with a single element:

    t = tf.constant([[1, 2], [3, 4]])
    ds = tf.data.Dataset.from_tensors(t)   # [[1, 2], [3, 4]]
    

    from_tensor_slices creates a dataset with a separate element for each row of the input tensor:

    t = tf.constant([[1, 2], [3, 4]])
    ds = tf.data.Dataset.from_tensor_slices(t)   # [1, 2], [3, 4]
    

提交回复
热议问题