{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Build Your First Convolutional Neural Network\nOne of the earliest susscess of Convolutional Neural Network (CNNs) was in handwritten digit recognition using the LeNet architecture.\n\nIn this project-based workshop, we will be recreating the LeNet architecture using the MNIST database of handwritten digits and explore the many design changes that could improve classification accuracy.\n\nThis notebook willl provide a template and some hints on how to get going on creating you first CNN using Keras\n\nSome helpful resources:\n* [Training and evaluation with the built-in methods](https://www.tensorflow.org/guide/keras/train_and_evaluate)\n* [Keras Documentation](https://www.tensorflow.org/guide/keras/)\n* [Keras MNIST Example](https://www.tensorflow.org/datasets/keras_example)\n* [Google](https://www.google.com/) ... **I'm not joking** there is a stackoverflow post for almost every problem you'll encounter.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"# Step 1: Import you packages/modules\nJust to name a few you might need:\n* tensorflow\n* keras\n* numpy\n* pandas\n* matplotlib\n","metadata":{}},{"cell_type":"code","source":"## import statements here ...","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:47.931832Z","iopub.execute_input":"2022-03-09T18:59:47.932743Z","iopub.status.idle":"2022-03-09T18:59:47.957076Z","shell.execute_reply.started":"2022-03-09T18:59:47.932599Z","shell.execute_reply":"2022-03-09T18:59:47.955876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Step 2: Load Dataset\n\nAfter you load the dataset it is good practice to take a peak at it. maybe you should:\n* Print the first couple rows, see what kind of features you have\n* Print the shape of the dataset\n* Visualize the image your are working with.","metadata":{}},{"cell_type":"code","source":"# Load in the train and test datasets\n\n# Print first 5 rows of the train dataset\n\n# Display a image from the dataset.","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:47.959252Z","iopub.execute_input":"2022-03-09T18:59:47.959903Z","iopub.status.idle":"2022-03-09T18:59:47.964544Z","shell.execute_reply.started":"2022-03-09T18:59:47.959848Z","shell.execute_reply":"2022-03-09T18:59:47.963586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Does the Data need to be reshaped or normalized?","metadata":{}},{"cell_type":"markdown","source":"# Step 3: Create Model\n\nLast week we discused 5 layer CNN model:\n* [Conv2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D)\n* [Pooling layers](https://keras.io/api/layers/pooling_layers/)\n* [Dropout](https://keras.io/api/layers/regularization_layers/dropout/)\n* [Dense](https://keras.io/api/layers/core_layers/dense/)\n\nLeNet Architecture \n\n<a href=\"https://ibb.co/kV1j9p\"><img src=\"https://preview.ibb.co/nRkBpp/gec2.jpg\" alt=\"gec2\" border=\"0\"></a>\n\nHere is where you build your model. \n* How many layer do you want? \n* What type of layers are you going to use ? \n* What hyperparemters will you use for the fiiter? \n* What activation functions will you use?\n","metadata":{}},{"cell_type":"code","source":"# Design your CNN ","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:47.971724Z","iopub.execute_input":"2022-03-09T18:59:47.97239Z","iopub.status.idle":"2022-03-09T18:59:47.976966Z","shell.execute_reply.started":"2022-03-09T18:59:47.972332Z","shell.execute_reply":"2022-03-09T18:59:47.975862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Step 4: [Compile](https://keras.io/api/models/model_training_apis/) Model\n* What [optimizer](https://keras.io/api/optimizers/) will you use? \n    * For example, [Adam](https://keras.io/api/optimizers/adam/) and [rmsprop](https://keras.io/api/optimizers/rmsprop/)\n    * Which one will you choose? Why?\n* What [loss function](https://keras.io/api/losses/) will you optimize?\n    * For example, [Categorical Crossentropy](https://keras.io/api/losses/probabilistic_losses/#categoricalcrossentropy-class)\n* What [metrics](https://keras.io/api/metrics/) will you keep track of?","metadata":{}},{"cell_type":"code","source":"# Compile mode using compile()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:47.978707Z","iopub.execute_input":"2022-03-09T18:59:47.979581Z","iopub.status.idle":"2022-03-09T18:59:47.9891Z","shell.execute_reply.started":"2022-03-09T18:59:47.979523Z","shell.execute_reply":"2022-03-09T18:59:47.988169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Step 5: [Train](https://keras.io/api/models/model_training_apis/#fit-method) model\n* Will you split the data into train and validation?\n* How many epochs will you train for?\n* Will you use batches? How many examples per batch?","metadata":{}},{"cell_type":"code","source":"# train model using fit()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:47.990325Z","iopub.execute_input":"2022-03-09T18:59:47.9911Z","iopub.status.idle":"2022-03-09T18:59:48.00303Z","shell.execute_reply.started":"2022-03-09T18:59:47.991065Z","shell.execute_reply":"2022-03-09T18:59:48.002017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Step 6: Evaluate Test Data\n\nHow would you evaluate the model. What strategies/methods would you use?\n* [Confusion matrix](https://en.wikipedia.org/wiki/Confusion_matrix)\n* If you kept track of the loss/metrics over time can you plot a graph?","metadata":{}},{"cell_type":"code","source":"# evaluate the test data using evaluate()\n# plot a graph using matplotlib, ploty etc","metadata":{"execution":{"iopub.status.busy":"2022-03-09T18:59:48.004849Z","iopub.execute_input":"2022-03-09T18:59:48.005672Z","iopub.status.idle":"2022-03-09T18:59:48.014881Z","shell.execute_reply.started":"2022-03-09T18:59:48.005622Z","shell.execute_reply":"2022-03-09T18:59:48.01368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* How can you improve the model? [Data Augmentation](https://www.tensorflow.org/tutorials/images/data_augmentation)?","metadata":{}}]}