{"cells": [{"metadata": {"_cell_guid": "1c408096-e2ed-4b1a-96dc-d97f04576a0c", "_uuid": "9c02122ffd2a56cd4d81275a703de255bf3dcb50"}, "cell_type": "markdown", "source": ["# Exercise Introduction\n", "\n", "To build and test your intuition for convolutions, you will design a vertical line detector.  We'll apply it to each part of an image to create a new tensor showing where there are vertical lines.\n", "\n", "![Imgur](https://i.imgur.com/op9Maqr.png)\n", "\n", "Follow these following 4 steps:\n", "1. **Fork this notebook**\n", "2. **Run this full notebook and scroll down to see the output**  You will see the original image, as well as an example of the image we get from applying our horizontal line detector to the image.\n", "3. **Fill in the code cell for `vertical_line_conv`.**  You will have to think about what numbers in the list will create a vertical line detector.  Run this cell.\n", "4. **Add `vertical_line_conv` to `conv_list`.  Run that cell.**  You will see the output of your vertical line filter underneath the horizontal line filter.  You will also see a printed hint indicating if you got this right.  \n", "\n", "Once that's done, you are ready to learn about deep convolutional models, the key to modern computer vision breakthroughs.\n", "\n", "---\n", "\n", "# Import Utility Functions\n", "We'll use some small utilty functions to load raw image data, visualize the results and give hints on your answert, etc.  Don't worry about these, but execute the next cell to load the utility functions.\n"]}, {"metadata": {"_cell_guid": "ee82df62-e608-4bc5-8262-f6ad4961054b", "_uuid": "1c812b255b9e577cd5f5118823ad3c7725bc8872", "collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["import sys\n", "# Add directory holding utility functions to path to allow importing\n", "sys.path.append('/kaggle/input/python-utility-code-for-deep-learning-exercises/utils')\n", "from exercise_1 import load_my_image, apply_conv_to_image, show, print_hints"], "outputs": []}, {"metadata": {"_cell_guid": "805ef092-0efe-4a85-a0df-5e5d17404469", "_uuid": "aef8e139775e21a4e01ad07547aa83a6f3a72919"}, "cell_type": "markdown", "source": ["# Example Convolution: Horizontal Line Detector\n", "Here is the convolution you saw in the video.  It's provided here as an example, and you shouldn't need to change it."]}, {"metadata": {"_cell_guid": "8b1ac6d7-521e-4591-b076-af0be8185b45", "_uuid": "c8f6a7c3503c2bcc5922b1a01000b13fcdf7055e", "collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["# Detects bright pixels over dark pixels. \n", "horizontal_line_conv = [[1, 1], \n", "                        [-1, -1]]"], "outputs": []}, {"metadata": {"_cell_guid": "0ed4659f-9661-404d-8b0c-710bf4666425", "_uuid": "bd7f2171bb84fa25e8a106b5834bf34ad2201d93"}, "cell_type": "markdown", "source": ["# Your Turn: Vertical Line Detector\n", "\n", "**Replace the question marks with numbers to make a vertical line detector and uncomment both lines of code in the cell below.**"]}, {"metadata": {"_cell_guid": "51919a23-0fa4-4d60-b616-2cb96bccf0e7", "_uuid": "22aff839d64cc10f7d1b88a845d4eac12cdf549e", "collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["vertical_line_conv = [[1, -1], \n", "                      [1, -1]]"], "outputs": []}, {"metadata": {"_cell_guid": "eb1d9588-cb01-45eb-a0f3-af81d4e3f164", "_uuid": "bdbe9e7d79d138b493886c583969da62bcdee69a"}, "cell_type": "markdown", "source": ["**Once you have created vertical_line_conv in the cell above, add it as an additional item to `conv_list` in the next cell. Then run that cell.**"]}, {"metadata": {"_cell_guid": "42ff7e62-aa38-4263-a8f5-86acaf5e82ae", "_uuid": "fbc4e47d0a4bb86166d858046cc7b6e65f7521e4", "collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["conv_list = [horizontal_line_conv, vertical_line_conv]\n", "\n", "original_image = load_my_image()\n", "print(\"Original image\")\n", "show(original_image)\n", "for conv in conv_list:\n", "    filtered_image = apply_conv_to_image(conv, original_image)\n", "    print(\"Output: \")\n", "    show(filtered_image)"], "outputs": []}, {"metadata": {"_cell_guid": "182683d4-dd85-443d-b430-7c23e649112e", "_uuid": "9813c870835696f2916b93c33ccf1639bc69cf6e"}, "cell_type": "markdown", "source": ["\n", "**Above, you'll see the output of the horizontal line filter as well as the filter you added. If you got it right, the output of your filter will looks like this.**\n", "![Imgur](https://i.imgur.com/uR2ngvK.png)\n", "\n", "---\n", "# Keep Going\n", "**Now you are ready to [combine convolutions into powerful models](https://www.kaggle.com/dansbecker/building-models-from-convolutions). These models are fun to work with, so keep going.**\n", "\n", "**[Deep Learning Track Home](https://www.kaggle.com/education/deep-learning)**"]}], "metadata": {"language_info": {"mimetype": "text/x-python", "name": "python", "version": "3.6.4", "codemirror_mode": {"name": "ipython", "version": 3}, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py"}, "kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}}, "nbformat": 4, "nbformat_minor": 1}