-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import tensorflow as tf | ||
|
||
# Create a Constant op that produces a 1x2 matrix. The op is | ||
# added as a node to the default graph. | ||
# | ||
# The value returned by the constructor represents the output | ||
# of the Constant op. | ||
matrix1 = tf.constant([[3., 3.]]) | ||
|
||
# Create another Constant that produces a 2x1 matrix. | ||
matrix2 = tf.constant([[2.],[2.]]) | ||
|
||
# Create a Matmul op that takes 'matrix1' and 'matrix2' as inputs. | ||
# The returned value, 'product', represents the result of the matrix | ||
# multiplication. | ||
product = tf.matmul(matrix1, matrix2) | ||
|
||
# Launch the default graph. | ||
sess = tf.Session() | ||
|
||
with tf.Session() as sess: | ||
result = sess.run([product]) | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import tensorflow as tf | ||
|
||
|
||
input1 = tf.placeholder(tf.float32) | ||
input2 = tf.placeholder(tf.float32) | ||
output = tf.mul(input1, input2) | ||
|
||
with tf.Session() as sess: | ||
print(sess.run([output], feed_dict={input1:[7.], input2:[2.]})) | ||
|
||
# output: | ||
# [array([ 14.], dtype=float32)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import tensorflow as tf | ||
|
||
# Create a Variable, that will be initialized to the scalar value 0. | ||
state = tf.Variable(0, name="counter") | ||
|
||
# Create an Op to add one to `state`. | ||
|
||
one = tf.constant(1) | ||
new_value = tf.add(state, one) | ||
update = tf.assign(state, new_value) | ||
|
||
# Variables must be initialized by running an `init` Op after having | ||
# launched the graph. We first have to add the `init` Op to the graph. | ||
init_op = tf.initialize_all_variables() | ||
|
||
# Launch the graph and run the ops. | ||
with tf.Session() as sess: | ||
# Run the 'init' op | ||
sess.run(init_op) | ||
# Print the initial value of 'state' | ||
print(sess.run(state)) | ||
# Run the op that updates 'state' and print 'state'. | ||
for _ in range(3): | ||
sess.run(update) | ||
print(sess.run(state)) | ||
|
||
# output: | ||
|
||
# 0 | ||
# 1 | ||
# 2 | ||
# 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# TensorFlow 기본 개념 " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 36, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"WARNING:tensorflow:From <ipython-input-36-265b04346152>:17 in <module>.: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.\nInstructions for updating:\nUse `tf.global_variables_initializer` instead.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"epoch 0, output: 0.800000011920929\nepoch 10, output: 0.47898948192596436\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"epoch 20, output: 0.2867887020111084\nepoch 30, output: 0.17171096801757812\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"epoch 40, output: 0.10280969738960266\nepoch 50, output: 0.06155595928430557\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"epoch 60, output: 0.036855824291706085\nepoch 70, output: 0.022066941484808922\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"epoch 80, output: 0.01321229338645935\nepoch 90, output: 0.007910688407719135\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import tensorflow as tf\n", | ||
"x = tf.constant(1.0, name='input')\n", | ||
"w = tf.Variable(0.8, name='weight')\n", | ||
"y = tf.mul(w, x, name='output')\n", | ||
"y_ = tf.constant(0.0, name='correct_value')\n", | ||
"loss = tf.pow(y - y_, 2, name='loss')\n", | ||
"train_step = tf.train.GradientDescentOptimizer(0.025).minimize(loss)\n", | ||
"\n", | ||
"for value in [x, w, y, y_, loss]:\n", | ||
" tf.scalar_summary(value.op.name, value)\n", | ||
"\n", | ||
"summaries = tf.merge_all_summaries()\n", | ||
"\n", | ||
"sess = tf.Session()\n", | ||
"summary_writer = tf.train.SummaryWriter('log_simple_stats', sess.graph)\n", | ||
"\n", | ||
"sess.run(tf.initialize_all_variables())\n", | ||
"for i in range(100):\n", | ||
" if i % 10 ==0:\n", | ||
" print(\"epoch {}, output: {}\".format(i, sess.run(y)))\n", | ||
" summary_writer.add_summary(sess.run(summaries), i)\n", | ||
" sess.run(train_step)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2.0 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' | ||
Created on Nov 17, 2015 | ||
@author: root | ||
''' | ||
|
||
import tensorflow as tf | ||
|
||
a = tf.placeholder(tf.int16) | ||
b = tf.placeholder(tf.int16) | ||
|
||
# Define some operations | ||
add = tf.add(a, b) | ||
mul = tf.mul(a, b) | ||
|
||
with tf.Session() as sess: | ||
print ("Addition with variables: %i" % sess.run(add, feed_dict={a:2, b:3})) | ||
print ("Multiplication with variables: %d" % sess.run(mul, feed_dict={a:2, b:3})) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
''' | ||
Created on Nov 17, 2015 | ||
@author: root | ||
''' | ||
import tensorflow as tf | ||
hello = tf.constant('Hello, TensorFlow!') | ||
sess = tf.Session() | ||
print (sess.run(hello)) | ||
|
||
a = tf.constant(10) | ||
b = tf.constant(32) | ||
print (sess.run(a+b)) |