본문 바로가기
파이썬

AI 공부하면서 #1(Variable, random.uniform)

by 오징어땅콩2 2021. 7. 13.
반응형

본인도 공부하면 정리하는거라, 정답은 아니지만, 그냥 이해하는것을 적는 정도로 받아 주면 좋을듯

 

텐셔 플로우 1에서 Variable 할당만 하는것으로 값이 저장되지는 않고 세션 실행을 통해서 변수 값이 대입된다.

 

import numpy as np
#import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

# Input and output size based on the Env
input_size = 16
output_size = 4

R = tf.random_uniform([input_size, output_size], 0, 0.01)
W = tf.Variable(R) 

sess = tf.Session()
sess.run( tf.global_variables_initializer() )
x1= sess.run(W)
print(x1)

 

그러나 텐셔플로우2 에서는 세션이 없기 때문에 바로 바로 대입 된다.

 

import numpy as np
import tensorflow as tf
#import tensorflow.compat.v1 as tf
#tf.disable_v2_behavior()

# Input and output size based on the Env
input_size = 16
output_size = 4

R = tf.random.uniform([input_size, output_size], 0, 0.01)
W = tf.Variable(R) 

print(W)
print('------------------------------')
print(R)

댓글