Skip to content

Instantly share code, notes, and snippets.

@watermouth
Created July 15, 2019 07:52
Show Gist options
  • Select an option

  • Save watermouth/143fe202ac8a7c78637c33521e7c1334 to your computer and use it in GitHub Desktop.

Select an option

Save watermouth/143fe202ac8a7c78637c33521e7c1334 to your computer and use it in GitHub Desktop.
Kerasでreproducible 再現可能 gpu

Keras (tensorflow backend) で 再現可能なNN (Neural Network) model.fitの実行

事前に以下実行でOKだった. 記事 https://qiita.com/okotaku/items/8d682a11d8f2370684c9 と違うのは、randomそのものの部分の設定.

import os
import numpy as np
import keras.backend as K
import tensorflow as tf

os.environ['PYTHONHASHSEED'] = '0'
np.random.seed(mp["random_state"])
tf.set_random_seed(mp["random_state"]) # different seed is ok
session_conf = tf.ConfigProto(
intra_op_parallelism_threads=1,
inter_op_parallelism_threads=1
)
sess = tf.Session(graph=tf.get_default_graph(), config=session_conf)
K.set_session(sess)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment