我正在努力学习TensorFlow,并在https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/autoencoder.ipynb时学习这个例子

然后我在下面的代码中有一些问题:

for epoch in range(training_epochs):
    # Loop over all batches
    for i in range(total_batch):
        batch_xs, batch_ys = mnist.train.next_batch(batch_size)
        # Run optimization op (backprop) and cost op (to get loss value)
        _, c = sess.run([optimizer, cost], feed_dict={X: batch_xs})
    # Display logs per epoch step
    if epoch % display_step == 0:
        print("Epoch:", '%04d' % (epoch+1),
              "cost=", "{:.9f}".format(c))

既然mnist只是一个数据集,那么mnist.train.next_batch到底意味着什么?dataset.train.next_batch是如何定义的?

谢谢

推荐答案

mnist对象从tf.contrib.learn模块中定义的read_data_sets() function返回.mnist.train.next_batch(batch_size)方法是here实现的,它返回两个数组的元组,其中第一个表示batch_size个MNIST图像的一批,第二个表示与这些图像对应的batch-size个标签的一批.

图像作为大小为[batch_size, 784]的二维NumPy数组返回(因为MNIST图像中有784个像素),标签作为大小为[batch_size]的一维NumPy数组(如果用one_hot=False调用read_data_sets())或大小为[batch_size, 10]的二维NumPy数组返回(如果用one_hot=True调用read_data_sets()).

Python-3.x相关问答推荐

使用pybind11时,在sys.exit(0)处成功完成测试后,Python单元测试冻结

如何转换Pandas中的数据,以使我 Select 的列名变为行值并增加行?

我正在try 从 10*3 矩阵中删除随机值并将其变为 10*2 矩阵

匹配语句NaN

如何将日期时间索引写入日期类型的表?

删除列表中的第二个出现

列出相同索引的Pandas

如何在数据['column']中的'string'等条件下应用pandas

过滤查询集和Q运算符的不同值

命名元组内命名元组的 Python 语法

ValueError:FixedLocator 位置的数量 (5),通常来自对 set_ticks 的调用,与刻度标签的数量 (12) 不匹配

multiprocessing.Queue 中的 ctx 参数

tensorflow 中 numpy.newaxis 的替代方案是什么?

如何用pymongo连接远程mongodb

如何通过命令行将数组传递给python

__cause__ 和 __context__ 有什么区别?

如何使用 asyncio 添加连接超时?

将 args、kwargs 传递给 run_in_executor

当默认 pip 为 pip2 时,升级 pip3 的正确格式是什么?

在 macbook pro M1 上安装 Tensorflow 时出现zsh:非法硬件指令 python