■ 단일 입력 뉴런을 만드는 방법을 보여준다.
▶ 예제 코드 (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 |
import tensorflow as tf weightVariable = tf.Variable(1.0, name = "weight") inputValueTensor = tf.constant(0.5, name = "inputValue") expectedOuptutValueTensor = tf.constant(0.0, name = "expectedOutputValue") actualOutputValueTensor = tf.multiply(inputValueTensor, weightVariable, "actualOutputValue") lossFunctionTensor = tf.pow(expectedOuptutValueTensor - actualOutputValueTensor, 2, name = "lossFunction") optimizerOperation = tf.train.GradientDescentOptimizer(0.025).minimize(lossFunctionTensor) for value in [inputValueTensor, weightVariable, expectedOuptutValueTensor, actualOutputValueTensor, lossFunctionTensor]: tf.summary.scalar(value.op.name, value) symmaryTensor = tf.summary.merge_all() with tf.Session() as session: summaryFileWriter = tf.summary.FileWriter("c:/SummaryLog", session.graph) session.run(tf.global_variables_initializer()) for i in range(100): summaryFileWriter.add_summary(session.run(symmaryTensor), i) session.run(optimizerOperation) |