我在运行“适合机器学习初学者的MNIST”示例(https://www.tensorflow.org/get_started/mnist/beginners)。官方代码在这里:https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/mnist/mnist_softmax.py
然后我发现如果多次运行,得到的结果会有所不同。问题是,如果代码中没有随机化,为什么会发生这种情况呢?
回答:
通过查看源代码:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py#181,可以发现每次训练示例实际上都在变化。
供您参考:
numpy.random.shuffle(perm0)