问题描述
我正在尝试TensorFlow教程,但不知道此行中的next_batch来自何处?
I am trying out the TensorFlow tutorial and don't understand where does next_batch in this line come from?
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.
And didn't see next_batch there either.
现在,当在我自己的代码中尝试next_batch时,我会得到
Now when trying out next_batch in my own code, I am getting
AttributeError: 'numpy.ndarray' object has no attribute 'next_batch'
所以我想了解next_batch来自何处?
So I would like to understand where does next_batch come from?
推荐答案
next_batch
是DataSet
类的方法(请参见了解有关课程内容的更多信息.
next_batch
is a method of the DataSet
class (see https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py for more information on what's in the class).
当您加载mnist数据并将其分配给变量mnist
时,使用以下命令:
When you load the mnist data and assign it to the variable mnist
with:
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
查看mnist.train
的类.您可以输入以下内容来查看它:
look at the class of mnist.train
. You can see it by typing:
print mnist.train.__class__
您将看到以下内容:
<class 'tensorflow.contrib.learn.python.learn.datasets.mnist.Dataset'>
因为mnist.train
是类DataSet
的实例,所以可以使用该类的函数next_batch
.有关类的更多信息,请查看文档.
Because mnist.train
is an instance of class DataSet
, you can use the class's function next_batch
. For more information on classes, check out the documentation.
这篇关于TensorFlow教程batch_xs,batch_ys = mnist.train.next_batch(100)的next_batch来自何处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!