Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Example code has been modified to support Tensorflow 1.0 or higher API by BGPark
* If you are using an IDE such as PyCharm, it is strongly recommended that you create a project for each chapter. If not, pay attention to the directory relative path of the dataset.

# _TensorFlow for Machine Intelligence_

![TensorFlow for Machine Intelligence book cover](img/book_cover.jpg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {
"collapsed": true
},
Expand All @@ -14,7 +14,7 @@
"# Build our graph nodes, starting from the inputs\n",
"a = tf.constant(5, name=\"input_a\")\n",
"b = tf.constant(3, name=\"input_b\")\n",
"c = tf.mul(a,b, name=\"mul_c\")\n",
"c = tf.multiply(a,b, name=\"mul_c\")\n",
"d = tf.add(a,b, name=\"add_d\")\n",
"e = tf.add(c,d, name=\"add_e\")\n",
"\n",
Expand All @@ -25,7 +25,7 @@
"output = sess.run(e)\n",
"\n",
"# Open a TensorFlow SummaryWriter to write our graph to disk\n",
"writer = tf.train.SummaryWriter('./my_graph', sess.graph)\n",
"writer = tf.summary.FileWriter('./my_graph', sess.graph)\n",
"\n",
"# Close our SummaryWriter and Session objects\n",
"writer.close()\n",
Expand All @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {
"collapsed": true
},
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {
"collapsed": true
},
Expand All @@ -58,14 +58,14 @@
"# Build our graph nodes, starting from the inputs\n",
"a = tf.constant(5, name=\"input_a\")\n",
"b = tf.constant(3, name=\"input_b\")\n",
"c = tf.mul(a,b, name=\"mul_c\")\n",
"c = tf.multiply(a,b, name=\"mul_c\")\n",
"d = tf.add(a,b, name=\"add_d\")\n",
"e = tf.add(c,d, name=\"add_e\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"metadata": {
"collapsed": true
},
Expand All @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand All @@ -89,19 +89,19 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Open a TensorFlow SummaryWriter to write our graph to disk\n",
"writer = tf.train.SummaryWriter('./my_graph', sess.graph)"
"writer = tf.summary.FileWriter('./my_graph', sess.graph)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 12,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -130,7 +130,9 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
Expand All @@ -142,7 +144,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 2.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -154,4 +156,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"\n",
"with tf.name_scope(\"Scope_A\"):\n",
" a = tf.add(1, 2, name=\"A_add\")\n",
" b = tf.mul(a, 3, name=\"A_mul\")\n",
" b = tf.multiply(a, 3, name=\"A_mul\")\n",
"\n",
"with tf.name_scope(\"Scope_B\"):\n",
" c = tf.add(4, 5, name=\"B_add\")\n",
" d = tf.mul(c, 6, name=\"B_mul\")\n",
" d = tf.multiply(c, 6, name=\"B_mul\")\n",
"\n",
"e = tf.add(b, d, name=\"output\")"
]
Expand All @@ -29,7 +29,7 @@
},
"outputs": [],
"source": [
"writer = tf.train.SummaryWriter('./name_scope_1', graph=tf.get_default_graph())"
"writer = tf.summary.FileWriter('./name_scope_1', graph=tf.get_default_graph())"
]
},
{
Expand All @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -61,12 +61,12 @@
" with tf.name_scope(\"Transformation\"):\n",
"\n",
" with tf.name_scope(\"A\"):\n",
" A_mul = tf.mul(in_1, const)\n",
" A_out = tf.sub(A_mul, in_1)\n",
" A_mul = tf.multiply(in_1, const)\n",
" A_out = tf.subtract(A_mul, in_1)\n",
"\n",
" with tf.name_scope(\"B\"):\n",
" B_mul = tf.mul(in_2, const)\n",
" B_out = tf.sub(B_mul, in_2)\n",
" B_mul = tf.multiply(in_2, const)\n",
" B_out = tf.subtract(B_mul, in_2)\n",
"\n",
" with tf.name_scope(\"C\"):\n",
" C_div = tf.div(A_out, B_out)\n",
Expand All @@ -78,7 +78,7 @@
"\n",
" out = tf.maximum(C_out, D_out) \n",
"\n",
"writer = tf.train.SummaryWriter('./name_scope_2', graph=graph)\n",
"writer = tf.summary.FileWriter('./name_scope_2', graph=graph)\n",
"writer.close()"
]
},
Expand Down Expand Up @@ -108,7 +108,9 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
Expand All @@ -120,7 +122,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 3.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -132,4 +134,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 8,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -61,30 +61,30 @@
" avg = tf.div(update_total, tf.cast(increment_step, tf.float32), name=\"average\")\n",
" \n",
" # Creates summaries for output node\n",
" tf.scalar_summary(b'Output', output, name=\"output_summary\")\n",
" tf.scalar_summary(b'Sum of outputs over time', update_total, name=\"total_summary\")\n",
" tf.scalar_summary(b'Average of outputs over time', avg, name=\"average_summary\")\n",
" tf.summary.scalar('Output', output)\n",
" tf.summary.scalar('Sum_of_outputs_over_time', update_total)\n",
" tf.summary.scalar('Average_of_outputs_over_time', avg)\n",
" \n",
" # Global Variables and Operations\n",
" with tf.name_scope(\"global_ops\"):\n",
" # Initialization Op\n",
" init = tf.initialize_all_variables() \n",
" init = tf.global_variables_initializer()\n",
" # Merge all summaries into one Operation\n",
" merged_summaries = tf.merge_all_summaries()\n",
" merged_summaries = tf.summary.merge_all()\n",
"\n",
"# Start a Session, using the explicitly created Graph\n",
"sess = tf.Session(graph=graph)\n",
"\n",
"# Open a SummaryWriter to save summaries\n",
"writer = tf.train.SummaryWriter('./improved_graph', graph)\n",
"writer = tf.summary.FileWriter('./improved_graph', graph)\n",
"\n",
"# Initialize Variables\n",
"sess.run(init)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand All @@ -101,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 10,
"metadata": {
"collapsed": false,
"scrolled": true
Expand All @@ -123,7 +123,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 11,
"metadata": {
"collapsed": true
},
Expand All @@ -135,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 12,
"metadata": {
"collapsed": true
},
Expand All @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 13,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -177,7 +177,9 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
""
]
}
],
"metadata": {
Expand All @@ -189,7 +191,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 3.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -201,4 +203,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
4 changes: 2 additions & 2 deletions chapters/03_tensorflow_fundamentals/basic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Build our graph nodes, starting from the inputs
a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_b")
c = tf.mul(a,b, name="mul_c")
c = tf.multiply(a,b, name="mul_c")
d = tf.add(a,b, name="add_d")
e = tf.add(c,d, name="add_e")

Expand All @@ -15,7 +15,7 @@
sess.run(e)

# Open a TensorFlow SummaryWriter to write our graph to disk
writer = tf.train.SummaryWriter('./my_graph', sess.graph)
writer = tf.summary.FileWriter('./my_graph', sess.graph)

# Close our SummaryWriter and Session objects
writer.close()
Expand Down
16 changes: 8 additions & 8 deletions chapters/03_tensorflow_fundamentals/name_scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Example 1
with tf.name_scope("Scope_A"):
a = tf.add(1, 2, name="A_add")
b = tf.mul(a, 3, name="A_mul")
b = tf.multiply(a, 3, name="A_mul")

with tf.name_scope("Scope_B"):
c = tf.add(4, 5, name="B_add")
d = tf.mul(c, 6, name="B_mul")
d = tf.multiply(c, 6, name="B_mul")

e = tf.add(b, d, name="output")

writer = tf.train.SummaryWriter('./name_scope_1', graph=tf.get_default_graph())
writer = tf.summary.FileWriter('./name_scope_1', graph=tf.get_default_graph())
writer.close()


Expand All @@ -26,12 +26,12 @@
with tf.name_scope("Transformation"):

with tf.name_scope("A"):
A_mul = tf.mul(in_1, const)
A_out = tf.sub(A_mul, in_1)
A_mul = tf.multiply(in_1, const)
A_out = tf.subtract(A_mul, in_1)

with tf.name_scope("B"):
B_mul = tf.mul(in_2, const)
B_out = tf.sub(B_mul, in_2)
B_mul = tf.multiply(in_2, const)
B_out = tf.subtract(B_mul, in_2)

with tf.name_scope("C"):
C_div = tf.div(A_out, B_out)
Expand All @@ -43,7 +43,7 @@

out = tf.maximum(C_out, D_out)

writer = tf.train.SummaryWriter('./name_scope_2', graph=graph)
writer = tf.summary.FileWriter('./name_scope_2', graph=graph)
writer.close()

# To start TensorBoard after running this file, execute the following command:
Expand Down
Loading