Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jwlee-ml authored Mar 23, 2019
1 parent 9a18c1a commit 525d24a
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 393 deletions.
126 changes: 56 additions & 70 deletions lab-11-1-mnist-cnn-keras-sequential-eager.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random Seed"
"## Hyper Parameters"
]
},
{
Expand All @@ -73,6 +73,10 @@
"metadata": {},
"outputs": [],
"source": [
"learning_rate = 0.001\n",
"training_epochs = 15\n",
"batch_size = 100\n",
"\n",
"tf.set_random_seed(777)"
]
},
Expand Down Expand Up @@ -127,14 +131,42 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Function"
"## Datasets"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"(train_images, train_labels), (test_images, test_labels) = mnist.load_data() \n",
" \n",
"train_images = train_images.astype(np.float32) / 255.\n",
"test_images = test_images.astype(np.float32) / 255.\n",
"train_images = np.expand_dims(train_images, axis=-1)\n",
"test_images = np.expand_dims(test_images, axis=-1)\n",
" \n",
"train_labels = to_categorical(train_labels, 10)\n",
"test_labels = to_categorical(test_labels, 10) \n",
" \n",
"train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels)).shuffle(\n",
" buffer_size=100000).batch(batch_size)\n",
"test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels)).batch(batch_size)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Function"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def create_model():\n",
" model = keras.Sequential()\n",
Expand All @@ -154,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -196,52 +228,6 @@
"model.summary()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hyper Parameters"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"learning_rate = 0.001\n",
"training_epochs = 15\n",
"batch_size = 100"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Datasets"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"(train_images, train_labels), (test_images, test_labels) = mnist.load_data() \n",
" \n",
"train_images = train_images.astype(np.float32) / 255.\n",
"test_images = test_images.astype(np.float32) / 255.\n",
"train_images = np.expand_dims(train_images, axis=-1)\n",
"test_images = np.expand_dims(test_images, axis=-1)\n",
" \n",
"train_labels = to_categorical(train_labels, 10)\n",
"test_labels = to_categorical(test_labels, 10) \n",
" \n",
"train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels)).shuffle(\n",
" buffer_size=100000).batch(batch_size)\n",
"test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels)).batch(batch_size)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -251,7 +237,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -271,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -290,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -310,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -326,7 +312,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -342,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {
"scrolled": false
},
Expand All @@ -352,21 +338,21 @@
"output_type": "stream",
"text": [
"Learning started. It takes sometime.\n",
"Epoch: 1 loss = 0.18155795 train accuracy = 0.9561 test accuracy = 0.9864\n",
"Epoch: 2 loss = 0.04595109 train accuracy = 0.9901 test accuracy = 0.9893\n",
"Epoch: 3 loss = 0.03227887 train accuracy = 0.9933 test accuracy = 0.9913\n",
"Epoch: 4 loss = 0.02327809 train accuracy = 0.9955 test accuracy = 0.9908\n",
"Epoch: 5 loss = 0.01696701 train accuracy = 0.9970 test accuracy = 0.9931\n",
"Epoch: 6 loss = 0.01443311 train accuracy = 0.9977 test accuracy = 0.9928\n",
"Epoch: 7 loss = 0.01259885 train accuracy = 0.9981 test accuracy = 0.9923\n",
"Epoch: 8 loss = 0.01018594 train accuracy = 0.9985 test accuracy = 0.9919\n",
"Epoch: 9 loss = 0.00939758 train accuracy = 0.9987 test accuracy = 0.9927\n",
"Epoch: 10 loss = 0.00814385 train accuracy = 0.9990 test accuracy = 0.9928\n",
"Epoch: 11 loss = 0.00715813 train accuracy = 0.9991 test accuracy = 0.9925\n",
"Epoch: 12 loss = 0.00585301 train accuracy = 0.9995 test accuracy = 0.9935\n",
"Epoch: 13 loss = 0.00585623 train accuracy = 0.9994 test accuracy = 0.9915\n",
"Epoch: 14 loss = 0.00530782 train accuracy = 0.9993 test accuracy = 0.9920\n",
"Epoch: 15 loss = 0.00454885 train accuracy = 0.9993 test accuracy = 0.9940\n",
"Epoch: 1 loss = 0.17322077 train accuracy = 0.9588 test accuracy = 0.9843\n",
"Epoch: 2 loss = 0.04714254 train accuracy = 0.9894 test accuracy = 0.9889\n",
"Epoch: 3 loss = 0.03016450 train accuracy = 0.9940 test accuracy = 0.9904\n",
"Epoch: 4 loss = 0.02271373 train accuracy = 0.9957 test accuracy = 0.9927\n",
"Epoch: 5 loss = 0.01871874 train accuracy = 0.9966 test accuracy = 0.9935\n",
"Epoch: 6 loss = 0.01522499 train accuracy = 0.9976 test accuracy = 0.9942\n",
"Epoch: 7 loss = 0.01154464 train accuracy = 0.9982 test accuracy = 0.9912\n",
"Epoch: 8 loss = 0.01073314 train accuracy = 0.9983 test accuracy = 0.9922\n",
"Epoch: 9 loss = 0.00970077 train accuracy = 0.9985 test accuracy = 0.9931\n",
"Epoch: 10 loss = 0.00773255 train accuracy = 0.9990 test accuracy = 0.9926\n",
"Epoch: 11 loss = 0.00702506 train accuracy = 0.9994 test accuracy = 0.9919\n",
"Epoch: 12 loss = 0.00577464 train accuracy = 0.9993 test accuracy = 0.9929\n",
"Epoch: 13 loss = 0.00647555 train accuracy = 0.9992 test accuracy = 0.9916\n",
"Epoch: 14 loss = 0.00516995 train accuracy = 0.9995 test accuracy = 0.9920\n",
"Epoch: 15 loss = 0.00516423 train accuracy = 0.9994 test accuracy = 0.9931\n",
"Learning Finished!\n"
]
}
Expand Down
Loading

0 comments on commit 525d24a

Please sign in to comment.