170719 Keras重复运行结果不一致问题

Github-2743
Github-2479
不同版本的keras,对同样的代码,得到不同结果的原因总结
用深度学习每次得到的结果都不一样,怎么办?
单独设置seed的方法适合于CPU,GPU不适用
指定随机数+Shuffle=False方法(认为模型结果的不确定性与采样训练时的随机种子有关)

import numpy as np
np.random.seed(1337)
这里写图片描述

同时设置numpy与tensorflow随机种子的方法

《用深度学习每次得到的结果都不一样,怎么办?》

from numpy.random import seed 
seed(1) 
from tensorflow import set_random_seed 
set_random_seed(2)

万能重启大法(找不到原因,重启试试)

Thanks for the suggestion. I have set the seed before importing the Keras libraries. Here, just to show that I have put the seed, I have edited in that way. After a lot of prolonged analysis I found that, to get the consistency in results, we need to shutdown the ipynb file, restart once again and run the code. If I just interrupt and rerun the code once again, it is giving me inconsistent results. (However, I expect that the results should be consistent even if I forcefully interrupt and rerun the code once again. Please let me know your comments).

后端配置大法
cuDNN’s backward pass is by default non-deterministic. See http://deeplearning.net/software/theano/library/sandbox/cuda/dnn.html

The documentation of CUDNN tells that, for the 2 following operations, the reproducibility is not guaranteed with the default implementation:
cudnnConvolutionBackwardFilter and cudnnConvolutionBackwardData. Those correspond to the gradient wrt the weights and the gradient wrt the input of the convolution. They are also used sometimes in the forward pass, when they give a speed up. The Theano flag dnn.conv.algo_bwd can be use to force the use of a slower but deterministic convolution implementation.

确实解决不了,心灵安慰法

The model weights are initialised randomly according to the initialization type. In general stochastic optimisation is not known to yield the exact same result each time. That’s why people like to use ensembles of models to give more accurate predictions.

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GuokLiu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值