python - 为什么我们在 tensorflow 的损失函数中需要 `int64` 作为 MNIST 标签?

标签 python tensorflow neural-network deep-learning mnist

代码摘自Tensorflow tutorial 。该函数在 MNIST 数据集(0-9 的手写图片数据集)上运行操作。为什么要将标签转换为 int64,我认为 int32 就足够了。

def loss(logits,labels):
    labels = tf.to_int64(labels)
    cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(
        logits,labels,name='xentropy')
    loss = tf.reduce_mean(cross_entropy,name='xentropy_mean')
    return loss

最佳答案

这个documentation说它可以是 int32int64。因此,您可以选择其中之一。在这里,他们更愿意选择 int64

引用文档:

labels: Tensor of shape [d_0, d_1, ..., d_{r-2}] and dtype int32 or int64. Each entry in labels must be an index in [0, num_classes). Other values will raise an exception when this op is run on CPU, and return NaN for corresponding corresponding loss and gradient rows on GPU.

关于python - 为什么我们在 tensorflow 的损失函数中需要 `int64` 作为 MNIST 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41174294/

相关文章:

machine-learning - 虚拟批量标准化和批量标准化有什么区别?

python - 许多 Controller ( subview )的一个 View (首页)

Python 多线程/处理模块,用于具有需要排序的依赖项的任务

python - 深度学习和神经网络

python - 使用 Tensorflow 初始化神经网络权重

python - 如何扩展CNN来识别更多物体?

python - Pandas 如何转置数据并添加列名

python - 如何在 python 中连接/断开连接/配置无线网络?

machine-learning - Tensorflow 默认情况下会对输入数据进行标准化吗?

machine-learning - 不变奖励如何帮助训练?