diff --git a/Course 1: Introduction to Tensorflow/README.md b/Course 1: Introduction to Tensorflow/README.md index 40c2b5b..9df7615 100644 --- a/Course 1: Introduction to Tensorflow/README.md +++ b/Course 1: Introduction to Tensorflow/README.md @@ -21,7 +21,6 @@

-

@@ -32,22 +31,32 @@ - Quiz:

- +

- +

-

- +

- [Programming assignment](). ### Week 3 +- Quiz: +

+ +

+ +

+ +

+ +- [Programming assignment](). + ### Week 4 ## Contributors: diff --git a/Course 1: Introduction to Tensorflow/Week 3/Excercise-3-Question.ipynb b/Course 1: Introduction to Tensorflow/Week 3/Excercise-3-Question.ipynb new file mode 100644 index 0000000..4610e8b --- /dev/null +++ b/Course 1: Introduction to Tensorflow/Week 3/Excercise-3-Question.ipynb @@ -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", + "\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 +} diff --git a/Course 1: Introduction to Tensorflow/img/w1_quizz2a.png b/Course 1: Introduction to Tensorflow/img/w2_quizz1a.png similarity index 100% rename from Course 1: Introduction to Tensorflow/img/w1_quizz2a.png rename to Course 1: Introduction to Tensorflow/img/w2_quizz1a.png diff --git a/Course 1: Introduction to Tensorflow/img/w1_quizz2b.png b/Course 1: Introduction to Tensorflow/img/w2_quizz1b.png similarity index 100% rename from Course 1: Introduction to Tensorflow/img/w1_quizz2b.png rename to Course 1: Introduction to Tensorflow/img/w2_quizz1b.png diff --git a/Course 1: Introduction to Tensorflow/img/w1_quizz2c.png b/Course 1: Introduction to Tensorflow/img/w2_quizz1c.png similarity index 100% rename from Course 1: Introduction to Tensorflow/img/w1_quizz2c.png rename to Course 1: Introduction to Tensorflow/img/w2_quizz1c.png diff --git a/Course 1: Introduction to Tensorflow/img/w3_quizz1a.png b/Course 1: Introduction to Tensorflow/img/w3_quizz1a.png new file mode 100644 index 0000000..1219dec Binary files /dev/null and b/Course 1: Introduction to Tensorflow/img/w3_quizz1a.png differ diff --git a/Course 1: Introduction to Tensorflow/img/w3_quizz1b.png b/Course 1: Introduction to Tensorflow/img/w3_quizz1b.png new file mode 100644 index 0000000..6b5db09 Binary files /dev/null and b/Course 1: Introduction to Tensorflow/img/w3_quizz1b.png differ