Variables
Variables는 그래프가 실행되는 동안 state를 유지합니다.
Variables maintain state across executions of the graph.
다음 예제는 simple counter 역할을 하는 변수를 보여주고 있습니다.
The following example shows a variable serving as a simple counter.
보다 상세한 사항은 Variables를 참조 하세요.
See Variables for more details.
# 변수 만들기, 변수를 scalar 값 0으로 초기화
state = tf.Variable(0,
name="counter")
# `state`에 1을 더하는 op 만들기.
one = tf.constant(1)
new_value = tf.add(state, one)
update = tf.assign(state, new_value)
# 그래프를 가동시킨 후, `init` op를 가동시켜서 변수를 초기화해야 함, 먼저 `init` op를 그래프에 더해야 함
init_op = tf.initialize_all_variables()
# 그래프를 가동시키고 ops를 가동시키기, 'init' op를 가동시키고, 'state'의 초기값 프린트 하기
with tf.Session() as sess:
# 'init' op 가동시키기
sess.run(init_op)
# 'state'의 초기값 프린트 하기
print(sess.run(state))
# 'state'를 업데이트 하는 op를 가동시키고, 'state'를 프린트하기
for _ in range(3):
sess.run(update)
print(sess.run(state))
# 출력된 결과
0
1
1
2
2
3
3
위 코드의 assign() op은 add() op과 같은 expression
graph의 일부이기 때문에, 이것은 run()가 expression을 실행할 때까지 할당을 실제로 수행하지 않습니다.
The assign() operation in this code is a part of the expression graph
just like the add() operation, so it does not actually perform the
assignment until run() executes the expression.
일반적으로 statistical
model의 패러미터를 Variables(변수) 세트로 표현합니다.
You typically represent the parameters of a statistical model as a set of
Variables.
예를 들어, NN의 가중치를 변수 안의 텐서로 저장할 것입니다.
For example, you would store the weights for a neural network as a tensor in a
Variable.
훈련하는 중에, 훈련그래프를 반복적으로 가동시켜서 이 텐서를 업데이트 합니다.
During training you update this tensor by running a training graph repeatedly.
'TensorFlow' 카테고리의 다른 글
Feeds (13) (0) | 2016.03.31 |
---|---|
Fetch (12) (0) | 2016.03.31 |
Interactive 사용법 (10) (0) | 2016.03.31 |
기초 사용법 Basic Usage(9) (0) | 2016.03.31 |
TensorFlow Introduction (8) (0) | 2016.03.31 |
댓글