------------恢复内容开始------------
The tf.data.Dataset API supports writing descriptive and efficient input pipelines. Dataset usage follows a common pattern:
- Create a source dataset from your input data.
- Apply dataset transformations to preprocess the data.
- Iterate over the dataset and process the elements.
------------恢复内容结束------------
Methods:
1. batch
1 batch( 2 batch_size, drop_remainder=False 3 )
Combines consecutive elements of this dataset into batches.
把当前的dataset分割成连续的batches
drop_remainder = true时把最后一组那些剩下的,除不尽的元素舍弃
1 dataset = tf.data.Dataset.range(8) 2 dataset = dataset.batch(3) 3 list(dataset.as_numpy_iterator())
输出:Array[[0, 1, 2], [3, 4, 5], [6, 7]]
1 dataset = tf.data.Dataset.range(8) 2 dataset = dataset.batch(3, drop_remainder=True) 3 list(dataset.as_numpy_iterator())
输出:Array[[0, 1, 2], [3, 4, 5]]