简体   繁体   English

每次使用TensorFlow训练CNN(MNIST数据集)时,如何获得相同的损失值?

[英]How to get the same loss value, every time training a CNN (MNIST data set), with TensorFlow?

I want to train a convolutional neural network (with MNIST data set and TensorFlow) a few times new and get every time the same results of the accuracy. 我想训练卷积神经网络(带有MNIST数据集和TensorFlow)几次,每次获得相同的精度结果。 To get this i: 为了得到这个我:

  1. Save an untrained only initialized (global_variables_initializer) net 保存未经训练的仅初始化(global_variables_initializer)网络
  2. Load every time I start the training this untrained net 每次我开始训练时,请加载此未经训练的网络
  3. Set mnist.train.next_batch shuffle=False, so the image sequence is every time the same 设置mnist.train.next_batch shuffle = False,因此图像序列每次都相同

I have done this before with a feed forward net (3 hidden layer) and every time I run this python script I get the exact same values for loss and accuracy. 我之前使用前馈网络(3个隐藏层)进行了此操作,每次运行此python脚本时,我都会得到完全相同的损耗和准确性值。

But, the "same" script with changing the model from a feed forward net to a convolutional neural net make every time I run the script a little different loss/accuracy. 但是,将模型从前馈网络更改为卷积神经网络的“相同”脚本使每次运行脚本时的损失/准确性都有所不同。

So I reduce the batch size to one and look for each image the loss value and see that the first two images always have the same loss value, but the rest is every time I run the script a little different. 因此,我将批处理大小减小为一个,并为每个图像查找损失值,并看到前两个图像始终具有相同的损失值,但是其余的每次运行脚本时都有一点不同。

Any idea why? 知道为什么吗?

Thanks to @AlexandrePassos comment, I search for deterministic/ non-deterministic operations in TensorFlow. 感谢@AlexandrePassos评论,我在TensorFlow中搜索确定性/非确定性操作。

So at the moment all operations which using CUDA atomics and running on GPU, are non-deterministic. 因此,目前所有使用CUDA原子并在GPU上运行的操作都是不确定的。
See this link: https://github.com/tensorflow/tensorflow/issues/3103 看到这个链接: https : //github.com/tensorflow/tensorflow/issues/3103

If somebody knows a way to realize a CNN with TensorFlow on GPU and with deterministic operations, please: How to create a CNN with deterministic operations in TensorFlow on a GPU? 如果有人知道在GPU上使用TensorFlow并执行确定性操作的CNN的方法,请: 如何在GPU上的TensorFlow中使用确定性操作创建CNN?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM