From 56c8e9692232b32be3eef356d8faaa56e35e93be Mon Sep 17 00:00:00 2001 From: Andreas Leitherer <leitherer@fhi-berlin.mpg.de> Date: Mon, 4 Jan 2021 11:11:48 +0100 Subject: [PATCH] Further small text modifications --- convolutional_nn.ipynb | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/convolutional_nn.ipynb b/convolutional_nn.ipynb index 9a28df9..3ff8bda 100644 --- a/convolutional_nn.ipynb +++ b/convolutional_nn.ipynb @@ -14,7 +14,7 @@ "\n", " \n", " <div style=\"text-align:center\">\n", - " <b><font size=\"6.4\">Convolutional Neural networks</font></b> \n", + " <b><font size=\"6.4\">Convolutional neural networks</font></b> \n", " </div>\n", " \n", "<p>\n", @@ -174,7 +174,7 @@ "### 3.1 Summary and intuition\n", "The convolutional layer's parameters consist of a set of learnable filters. Every filter is small spatially (along width and height), but extends through the full depth of the input volume. For example, a typical filter on a first layer of a ConvNet might have size 5x5x3 (i.e. 5 pixels width and height, and 3 because images have depth 3, the color channels). \n", "\n", - "* During the forward pass, we slide (more precisely, convolve) each filter across the width and height of the input volume and compute dot products between the entries of the filter and the input at any position. Intuitively, a convolution can be thought as a sliding (weigthed) average. \n", + "* During the forward pass, we slide (more precisely, convolve) each filter across the width and height of the input volume and compute dot products between the entries of the filter and the input at any position. Intuitively, a convolution can be thought as a sliding (weighted) average. \n", "\n", "* As we slide the filter over the width and height of the input volume we will produce a 2-dimensional activation map that gives the responses of that filter at every spatial position. Intuitively, the network will learn filters that activate when they see some type of visual feature such as an edge of some orientation or a blotch of some color on the first layer, or eventually entire honeycomb or wheel-like patterns on higher layers of the network. \n", "\n", @@ -275,7 +275,7 @@ "print(\"Retrieving picture of Max Planck. Saving image to './img_max_planck.jpg'.\")\n", "urllib.request.urlretrieve(\"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Max_Planck_1933.jpg/220px-Max_Planck_1933.jpg\", \"./img_max_planck.jpg\")\n", "\n", - "# retrive a picture of Berlin\n", + "# retrieve a picture of Berlin\n", "print(\"Retrieving picture of Berlin landscape. Saving image to './img_berlin_landscape.jpg'.\")\n", "urllib.request.urlretrieve(\"http://vivalifestyleandtravel.com/images/cache/c-1509326560-44562570.jpg\", \"./img_berlin_landscape.jpg\")\n", "\n", @@ -471,7 +471,7 @@ " [-1., 8., -1.], \n", " [-1., -1., -1.]])\n", "\n", - "#the emboss kernel givens the illusion of depth by emphasizing the differences of pixels in a given direction\n", + "# the emboss kernel gives the illusion of depth by emphasizing the differences of pixels in a given direction\n", "# in this case, in a direction along a line from the top left to the bottom right.\n", "k_emboss = np.array([[-2., -1., 0.], \n", " [-1., 1., 1.], \n", @@ -541,7 +541,7 @@ "\n", "As you can see above, the effect are similar for both pictures, and it is defined by the kernel with which the image is convolved.\n", "\n", - "In the case of **convolutional neural network**, the **kernels** will not be the one reported above, but they are going to be **learned by the network** from the data (by minimizing the classification error). " + "In the case of **convolutional neural networks**, the **kernels** will not be the one reported above, but they are going to be **learned by the network** from the data (by minimizing the classification error). " ] }, { @@ -633,7 +633,8 @@ "\n", "We now build a convolutional neural network using Keras, a simple and intuitive high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano; it also runs seamlessly on CPU and GPU.\n", "\n", - "For more information on Keras, please visit https://keras.io/\n", + "For more information on Keras, please visit https://keras.io/. Note that this link refers to the newest version of Keras (>2.4), which only supports Tensorflow (https://www.tensorflow.org/) as a backend. This tutorial (as well as the one on multilayer perceptrons) is compatible with versions <=2.3 which allows multiple backends (CNTK, Tensorflow, Theano). There are only slight differences in syntax and you can find archived documentations at https://github.com/faroit/keras-docs, e.g., for \n", + "version 2.1.5 https://faroit.com/keras-docs/2.1.5/. In both tutorials, we use tensorflow as backend (version <2.0).\n", "\n", "We start by defining the architecture (i.e. the shape) of the network. We use two convolutional layers, one max pooling, and one fully connected layer. There is no particular reason behind this choice, and other - better performing - choices are possible." ] @@ -667,7 +668,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now, we train the neural network; you can decide the number of epoch you want to use. The more epochs, the more time the network will be able to see the training samples, but this will results in an increase of computational time (proportial to `nb_epochs`).\n", + "Now, we train the neural network; you can decide the number of epoch you want to use. The more epochs, the more time the network will be able to see the training samples, but this will results in an increase of computational time (proportional to `nb_epochs`).\n", "\n", "An **epoch** is a single step in training a neural network; one epoch is completed when the neural network has seen every training sample once. \n", "\n", @@ -742,9 +743,9 @@ "#### Questions\n", "\n", "1. Look at the *Accuracy plot* above. Which information can you gather from it? What is happening to the *training* and *test* accuracy over epochs?\n", - "2. Is the behaviour of *training* and *test* accuracy that you are observing desirable? Is *overfitting* occuring?\n", + "2. Is the behavior of *training* and *test* accuracy that you are observing desirable? Is *overfitting* occurring?\n", "3. Should you look at the *training* or at the *test* accuracy to have an estimate of the generalization ability of the model?\n", - "4. Compare the *Accuracy plot* with the *Model loss plot* below. Do they show the same qualititive behaviour?\n" + "4. Compare the *Accuracy plot* with the *Model loss plot* below. Do they show the same qualitative behavior?\n" ] }, { @@ -758,7 +759,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As we discussed in the tutorial on multilayer perceptrons, regularization techniques are extremely useful to improve the generalization ability of machine learning models. We will again use dropout, now in context of convolutional neural networks, and investigate its influence on the model performance." + "As we discussed in the tutorial on multilayer perceptrons, regularization techniques are extremely useful to improve the generalization ability of machine learning models. We will again use dropout, now in context of convolutional neural networks, and investigate its influence on model performance." ] }, { @@ -870,7 +871,7 @@ "\n", "To answer this question, in this tutorial we will compute **attentive response maps**.\n", "\n", - "The main idea is to invert the data flow of a convolutional neural network, going from the last layers activations until image space. Then, an heatmap is constructed to shows which parts of the input image are most strongly activating when a classification decision is made - and thus are the most discriminative. \n", + "The main idea is to invert the data flow of a convolutional neural network, going from the last layers activations until image space. Then, a heatmap is constructed to shows which parts of the input image are most strongly activating when a classification decision is made - and thus are the most discriminative. \n", "\n", "Specifically, in this tutorial we will use **guided back-propagation**, as introduced in J. Springenberg, A. Dosovitskiy, T. Brox, and Riedmiller, *Striving for Simplicity: The All Convolutional Net*, https://arxiv.org/pdf/1412.6806.pdf (2015), and implemented in the Keras-vis package (https://raghakot.github.io/keras-vis/)\n", "\n", @@ -975,7 +976,7 @@ "source": [ "#### Questions\n", "\n", - "1. Have a look at the attentive response maps. Do they look reasonable? How to you evaluate their quality?\n", + "1. Have a look at the attentive response maps. Do they look reasonable? How do you evaluate their quality?\n", "2. Try to train another neural network - even a bad one - and calculate its attentive response maps. Are they similar to the one of this network? \n", "3. Are there materials-science-oriented applications of this technique that can be useful in your research?" ] @@ -992,6 +993,13 @@ "4. Code from MNIST example: https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py\n", "5. Keras-vis MNIST example: https://github.com/raghakot/keras-vis/blob/master/examples/mnist/attention.ipynb" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { -- GitLab