Skip to content

Commit

Permalink
update solution week 3 course 1
Browse files Browse the repository at this point in the history
  • Loading branch information
honghanhh committed Dec 2, 2020
1 parent c319979 commit af20fae
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Course 1: Introduction to Tensorflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<img src="./img/w1_quizz1b.png" width="80%" height="50%" title="Week 1 Quiz" >
</p>


<p align="center">
<img src="./img/w1_quizz1c.png" width="80%" height="50%" title="Week 1 Quiz" >
</p>
Expand All @@ -32,22 +31,32 @@

- Quiz:
<p align="center">
<img src="./img/w1_quizz2a.png" width="80%" height="50%" title="Week 2 Quiz" >
<img src="./img/w2_quizz1a.png" width="80%" height="50%" title="Week 2 Quiz" >
</p>

<p align="center">
<img src="./img/w1_quizz2b.png" width="80%" height="50%" title="Week 2 Quiz" >
<img src="./img/w2_quizz1b.png" width="80%" height="50%" title="Week 2 Quiz" >
</p>


<p align="center">
<img src="./img/w1_quizz2c.png" width="80%" height="50%" title="Week 2 Quiz" >
<img src="./img/w2_quizz1c.png" width="80%" height="50%" title="Week 2 Quiz" >
</p>

- [Programming assignment]().

### Week 3

- Quiz:
<p align="center">
<img src="./img/w3_quizz1a.png" width="80%" height="50%" title="Week 3 Quiz" >
</p>

<p align="center">
<img src="./img/w3_quizz1b.png" width="80%" height="50%" title="Week 3 Quiz" >
</p>

- [Programming assignment]().

### Week 4

## Contributors:
Expand Down
166 changes: 166 additions & 0 deletions Course 1: Introduction to Tensorflow/Week 3/Excercise-3-Question.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "iQjHqsmTAVLU"
},
"source": [
"## Exercise 3\n",
"In the videos you looked at how you would improve Fashion MNIST using Convolutions. For your exercise see if you can improve MNIST to 99.8% accuracy or more using only a single convolutional layer and a single MaxPooling 2D. You should stop training once the accuracy goes above this amount. It should happen in less than 20 epochs, so it's ok to hard code the number of epochs for training, but your training must end once it hits the above metric. If it doesn't, then you'll need to redesign your layers.\n",
"\n",
"I've started the code for you -- you need to finish it!\n",
"\n",
"When 99.8% accuracy has been hit, you should print out the string \"Reached 99.8% accuracy so cancelling training!\"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from os import path, getcwd, chdir\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Flatten, Dense, Conv2D, MaxPooling2D\n",
"from tensorflow.keras.callbacks import Callback\n",
"\n",
"# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
"# environment, then grab mnist.npz from the Coursera Jupyter Notebook\n",
"# and place it inside a local folder and edit the path to that location\n",
"path = f\"{getcwd()}/../tmp2/mnist.npz\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"config = tf.ConfigProto()\n",
"config.gpu_options.allow_growth = True\n",
"sess = tf.Session(config=config)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# GRADED FUNCTION: train_mnist_conv\n",
"def train_mnist_conv():\n",
" # Please write your code only where you are indicated.\n",
" # please do not remove model fitting inline comments.\n",
"\n",
" # YOUR CODE STARTS HERE\n",
" class myCallback(Callback):\n",
" def on_epoch_end(self, epoch, logs={}):\n",
" if (logs.get('acc') >= 0.998):\n",
" print(\"\\nReached 99% accuracy so cancelling training!\")\n",
" self.model.stop_training = True\n",
" callbacks = myCallback()\n",
" \n",
" # YOUR CODE ENDS HERE\n",
"\n",
" mnist = tf.keras.datasets.mnist\n",
" (training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)\n",
" # YOUR CODE STARTS HERE\n",
" training_images = training_images.reshape(60000, 28, 28, 1)/255.0\n",
" test_images = test_images.reshape(10000, 28, 28, 1)/255.0\n",
" # YOUR CODE ENDS HERE\n",
"\n",
" model = tf.keras.models.Sequential([\n",
" # YOUR CODE STARTS HERE\n",
" Conv2D(64, (3,3), activation = 'relu', input_shape = (28,28,1)),\n",
" MaxPooling2D(2,2),\n",
" Flatten(),\n",
" Dense(128, activation = 'relu'),\n",
" Dense(10, activation = 'softmax')\n",
" # YOUR CODE ENDS HERE\n",
" ])\n",
"\n",
" model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n",
" # model fitting\n",
" history = model.fit(\n",
" # YOUR CODE STARTS HERE\n",
" training_images, training_labels, epochs = 20, callbacks = [callbacks]\n",
" # YOUR CODE ENDS HERE\n",
" )\n",
" # model fitting\n",
" return history.epoch, history.history['acc'][-1]\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"_, _ = train_mnist_conv()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Now click the 'Submit Assignment' button above.\n",
"# Once that is complete, please run the following two cells to save your work and close the notebook"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%javascript\n",
"<!-- Save the notebook -->\n",
"IPython.notebook.save_checkpoint();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%javascript\n",
"IPython.notebook.session.delete();\n",
"window.onbeforeunload = null\n",
"setTimeout(function() { window.close(); }, 1000);"
]
}
],
"metadata": {
"coursera": {
"course_slug": "introduction-tensorflow",
"graded_item_id": "ml06H",
"launcher_item_id": "hQF8A"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af20fae

Please sign in to comment.