TensorFlow:dataset.train.next_batch 是如何定义的? [英] TensorFlow: how is dataset.train.next_batch defined?

查看:32
本文介绍了TensorFlow:dataset.train.next_batch 是如何定义的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 TensorFlow 并研究以下示例:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/autoencoder.ipynb

I am trying to learn TensorFlow and studying the example at: https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/autoencoder.ipynb

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

I then have some questions in the code below:

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 是如何定义的?

Since mnist is just a dataset, what exactly does mnist.train.next_batch mean? How was the dataset.train.next_batch defined?

谢谢!

推荐答案

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

The mnist object is returned from the read_data_sets() function defined in the tf.contrib.learn module. The mnist.train.next_batch(batch_size) method is implemented here, and it returns a tuple of two arrays, where the first represents a batch of batch_size MNIST images, and the second represents a batch of batch-size labels corresponding to those images.

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

The images are returned as a 2-D NumPy array of size [batch_size, 784] (since there are 784 pixels in an MNIST image), and the labels are returned as either a 1-D NumPy array of size [batch_size] (if read_data_sets() was called with one_hot=False) or a 2-D NumPy array of size [batch_size, 10] (if read_data_sets() was called with one_hot=True).

这篇关于TensorFlow:dataset.train.next_batch 是如何定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆