python 数据集输入fn使用Tensorflow 1.4 API。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 数据集输入fn使用Tensorflow 1.4 API。相关的知识,希望对你有一定的参考价值。

def dataset_input_fn(is_training, data_dir, batch_size, num_epochs=1):
    """Input function which provides batches for train or eval.
    """
    dataset = tf.data.Dataset.from_tensor_slices(_filenames(is_training,
                                                            data_dir))

    if is_training:
        dataset = dataset.shuffle(buffer_size=_FILE_SHUFFLE_BUFFER)

    dataset = dataset.flat_map(tf.data.TFRecordDataset)
    dataset = dataset.map(lambda value: _record_parser(value, is_training),
                          num_parallel_calls=5)
    dataset = dataset.prefetch(batch_size)

    if is_training:
        # When choosing shuffle buffer sizes, larger size result in better
        # randomness, while smaller size have better performance.
        dataset = dataset.shuffle(buffer_size=_SHUFFLE_BUFFER)

    # We call repeat after shuffling, rather than before, to prevent separate
    # epochs from blending together.
    dataset = dataset.repeat(num_epochs)
    dataset = dataset.batch(batch_size)

    iterator = dataset.make_one_shot_iterator()
    images, labels = iterator.get_next()

    return images, labels

以上是关于python 数据集输入fn使用Tensorflow 1.4 API。的主要内容,如果未能解决你的问题,请参考以下文章

如何将“collat​​e_fn”与数据加载器一起使用?

T-SQL谜题:将表的每一行作为内联函数的输入传递,并使用UNION ALL开发新的堆栈数据集

Python中数据的“上采样数据”

计算大型数据集的python树高度

python数据拟合

python数据拟合