머신러닝과 기술적 분석

Tensorflow 에서 random seed 사용방법 본문

Tensorflow

Tensorflow 에서 random seed 사용방법

BetterToday 2017. 8. 16. 23:37
728x90

tensorflow에서 Variable 객제의 초기값은 보통 random 으로 지정한다. 디버깅을 하거나 reproducibility를 위해서 random seed를 자주 사용한다.

본 post에서는 tensorflow에서 random seed를 지정하는 방법을 알아본다.

1. random seed

random으로 생성한 결과가 항상 같은 value를 갖도록 하는 방법이다.

tensorflow 뿐만아니라 numpy scikit-learn등 random 함수를 제공하는 대부분의 library에서 제공한다.

2. 사용방법

variable 객제를 생성하기 전에 다음과 같은 code를 붙이면 된다.

tf.set_random_seed(42)
w1 = tf.Variable(tf.random_normal([28*28, 10], stddev=0.01), name="weights")
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init_op)
    weight_value = sess.run(w1)
    print(weight_value[0,0])               # 0.00802145
728x90
반응형
Comments