keras可重现的结果 [英] Reproducible results with keras

查看:67
本文介绍了keras可重现的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得可乐的可复制结果?我遵循了这些步骤,但是每次运行Jupyter笔记本时,我仍然会得到不同的结果.我还尝试在调用model.fit()时设置shuffle=False.

How can I get reproducible results with keras? I followed these steps but I am still getting different results every time I run the Jupyter notebook. I also tried setting shuffle=False when calling model.fit().

我的配置: 康达4.3.25

My configuration: conda 4.3.25

带有tensorflow后端的keras 2.0.6

keras 2.0.6 with tensorflow backend

tensorflow-gpu 1.2.1

tensorflow-gpu 1.2.1

python 3.5

python 3.5

windows 10

windows 10

推荐答案

请参阅我在另一个问题上发布的答案.主要思想是:首先,禁用GPU.然后,将诸如"numpy,random等"之类的库作为种子.综上所述,在代码的开头添加以下代码可能会帮助您解决问题.

See the answer I posted at another question. The main idea is to: first, disable the GPU. And then, seed the libraries like "numpy, random, etc". To sum up, including the code below at the beginning of your code may help solve your problem.

import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""

import numpy as np
import tensorflow as tf
import random as rn
from keras import backend as K

sd = 1
np.random.seed(sd)
rn.seed(sd)
os.environ['PYTHONHASHSEED']=str(sd)

config = tf.ConfigProto(intra_op_parallelism_threads=1,inter_op_parallelism_threads=1)
tf.set_random_seed(sd)
sess = tf.Session(graph=tf.get_default_graph(), config=config)
K.set_session(sess)

这篇关于keras可重现的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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