■ Variable 클래스를 사용해 변수를 만드는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import tensorflow as tf valueVariable = tf.Variable(0, name = "value") oneConstantTensor = tf.constant(1) addValueTensor = tf.add(valueVariable, oneConstantTensor) assignValueTensor = tf.assign(valueVariable, addValueTensor) globalVariableInitializerOperation = tf.global_variables_initializer() with tf.Session() as session: session.run(globalVariableInitializerOperation) print(session.run(valueVariable)) for _ in range(10): session.run(assignValueTensor) print(session.run(valueVariable)) [결과] 0 1 2 3 4 5 6 7 8 9 10 |