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

前端 未结 4 894
轻奢々
轻奢々 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 11:47

    I think @MatthewScarpino clearly explained the differences between these two methods.

    Here I try to describe the typical usage of these two methods:

    • from_tensors can be used to construct a larger dataset from several small datasets, i.e., the size (length) of the dataset becomes larger;

    • while from_tensor_slices can be used to combine different elements into one dataset, e.g., combine features and labels into one dataset (that's also why the 1st dimension of the tensors should be the same). That is, the dataset becomes "wider".

提交回复
热议问题