gpt4 book ai didi

python - TensorFlow教程中的next_batch batch_xs, batch_ys = mnist.train.next_batch(100) 从哪里来?

转载 作者:太空狗 更新时间:2023-10-29 17:13:59 29 4
gpt4 key购买 nike

我正在试用 TensorFlow 教程,但不明白这行中的 next_batch 从何而来?

 batch_xs, batch_ys = mnist.train.next_batch(100)

我看了

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

也没有在那里看到 next_batch。

现在在我自己的代码中尝试 next_batch 时,我得到了

AttributeError: 'numpy.ndarray' object has no attribute 'next_batch'

所以我想了解一下 next_batch 是从哪里来的?

最佳答案

next_batchDataSet 类的一个方法(有关类中内容的更多信息,请参阅 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py)。

当您加载 mnist 数据并将其分配给变量 mnist 时:

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

查看mnist.train 类。您可以通过键入以下内容来查看它:

print mnist.train.__class__

您会看到以下内容:

<class 'tensorflow.contrib.learn.python.learn.datasets.mnist.Dataset'>

因为mnist.train 是类DataSet 的一个实例,您可以使用该类的函数next_batch。有关类(class)的更多信息,请查看 documentation .

关于python - TensorFlow教程中的next_batch batch_xs, batch_ys = mnist.train.next_batch(100) 从哪里来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40368697/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com