Skip to content

Commit

Permalink
week4
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchoi86 committed Aug 27, 2016
1 parent ac29f82 commit b061c60
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 47 deletions.
18 changes: 9 additions & 9 deletions notebooks/vis_cnn_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,21 @@
"output_type": "stream",
"text": [
"Start!\n",
"Epoch: 000/005 cost: 0.314222187\n",
"Epoch: 000/005 cost: 0.304427172\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.985\n",
"Epoch: 001/005 cost: 0.045797741\n",
" Training accuracy: 1.000\n",
" Test accuracy: 0.990\n",
"Epoch: 002/005 cost: 0.030807581\n",
" Test accuracy: 0.981\n",
"Epoch: 001/005 cost: 0.048057067\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.988\n",
"Epoch: 002/005 cost: 0.030249877\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.990\n",
"Epoch: 003/005 cost: 0.022313549\n",
"Epoch: 003/005 cost: 0.022841267\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.990\n",
"Epoch: 004/005 cost: 0.017620362\n",
"Epoch: 004/005 cost: 0.017701065\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.991\n",
" Test accuracy: 0.990\n",
"Optimization Finished.\n"
]
}
Expand Down
12 changes: 6 additions & 6 deletions notebooks/vis_linear_regression.ipynb

Large diffs are not rendered by default.

92 changes: 74 additions & 18 deletions notebooks/vis_logistic_regression_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Visualizing Logistic Regression"
"# Visualizing Logistic Regression"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -34,8 +34,17 @@
"trainimg = mnist.train.images\n",
"trainlabel = mnist.train.labels\n",
"testimg = mnist.test.images\n",
"testlabel = mnist.test.labels\n",
"\n",
"testlabel = mnist.test.labels"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Parameters of Logistic Regression\n",
"learning_rate = 0.01\n",
"training_epochs = 20\n",
Expand All @@ -58,9 +67,63 @@
"init = tf.initialize_all_variables()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Launch the graph"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sess = tf.Session()\n",
"sess.run(init)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Summary writer"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Summary writer ready\n"
]
}
],
"source": [
"summary_path = '/tmp/tf_logs/logistic_regression_mnist'\n",
"summary_writer = tf.train.SummaryWriter(summary_path, graph=sess.graph)\n",
"print (\"Summary writer ready\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand All @@ -69,22 +132,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch: 000/020 cost: 1.174349074 train_acc: 0.870\n",
"Epoch: 005/020 cost: 0.443016567 train_acc: 0.890\n",
"Epoch: 010/020 cost: 0.386667603 train_acc: 0.900\n",
"Epoch: 015/020 cost: 0.357187883 train_acc: 0.910\n",
"Epoch: 000/020 cost: 1.175680572 train_acc: 0.840\n",
"Epoch: 005/020 cost: 0.441145847 train_acc: 0.950\n",
"Epoch: 010/020 cost: 0.385325512 train_acc: 0.860\n",
"Epoch: 015/020 cost: 0.358649362 train_acc: 0.920\n",
"Optimization Finished!\n",
"Test Accuracy: 0.912\n"
"Test Accuracy: 0.911\n"
]
}
],
"source": [
"# Launch the graph\n",
"sess = tf.Session()\n",
"sess.run(init)\n",
"summary_writer = tf.train.SummaryWriter('/tmp/tf_logs/logistic_regression_mnist', graph=sess.graph)\n",
"\n",
"# Training cycle\n",
"for epoch in range(training_epochs):\n",
" avg_cost = 0.\n",
" num_batch = int(mnist.train.num_examples/batch_size)\n",
Expand All @@ -93,7 +150,6 @@
" randidx = np.random.randint(trainimg.shape[0], size=batch_size)\n",
" batch_xs = trainimg[randidx, :]\n",
" batch_ys = trainlabel[randidx, :] \n",
"\n",
" # Fit training using batch data\n",
" sess.run(optm, feed_dict={x: batch_xs, y: batch_ys})\n",
" # Compute average loss\n",
Expand All @@ -110,7 +166,7 @@
"# Test model\n",
"# Calculate accuracy\n",
"test_acc = sess.run(accr, feed_dict={x: testimg, y: testlabel})\n",
"print ((\"Test Accuracy: %.3f\") % (test_acc))\n"
"print ((\"Test Accuracy: %.3f\") % (test_acc))"
]
},
{
Expand Down
28 changes: 14 additions & 14 deletions notebooks/vis_mlp_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# MLP with TensorBoard"
"# Visualizing MNIST + Summary"
]
},
{
Expand Down Expand Up @@ -217,21 +217,21 @@
"output_type": "stream",
"text": [
"Start!\n",
"Epoch: 000/010 cost: 0.473336121\n",
"Epoch: 000/010 cost: 0.456668414\n",
" Training accuracy: 0.950\n",
" Test accuracy: 0.932\n",
"Epoch: 002/010 cost: 0.114191625\n",
" Training accuracy: 0.970\n",
" Test accuracy: 0.965\n",
"Epoch: 004/010 cost: 0.074626958\n",
" Training accuracy: 0.970\n",
" Test accuracy: 0.971\n",
"Epoch: 006/010 cost: 0.051695831\n",
" Training accuracy: 1.000\n",
" Test accuracy: 0.975\n",
"Epoch: 008/010 cost: 0.039800433\n",
" Test accuracy: 0.934\n",
"Epoch: 002/010 cost: 0.114907353\n",
" Training accuracy: 0.980\n",
" Test accuracy: 0.966\n",
"Epoch: 004/010 cost: 0.072722287\n",
" Training accuracy: 0.980\n",
" Test accuracy: 0.973\n",
"Epoch: 006/010 cost: 0.051551444\n",
" Training accuracy: 0.990\n",
" Test accuracy: 0.978\n",
" Test accuracy: 0.975\n",
"Epoch: 008/010 cost: 0.039778697\n",
" Training accuracy: 0.980\n",
" Test accuracy: 0.976\n",
"Optimization Finished!\n"
]
}
Expand Down

0 comments on commit b061c60

Please sign in to comment.