diff --git a/doc/pub/week42/html/._week42-bs000.html b/doc/pub/week42/html/._week42-bs000.html index 13a511a78..027791251 100644 --- a/doc/pub/week42/html/._week42-bs000.html +++ b/doc/pub/week42/html/._week42-bs000.html @@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec1'), + ('Neural Networks vs CNNs', 2, None, '___sec2'), ('Regular NNs don’t scale well to full images', 2, None, - '___sec2'), - ('3D volumes of neurons', 2, None, '___sec3'), - ('Layers used to build CNNs', 2, None, '___sec4'), - ('Transforming images', 2, None, '___sec5'), - ('CNNs in brief', 2, None, '___sec6'), + '___sec3'), + ('3D volumes of neurons', 2, None, '___sec4'), + ('Layers used to build CNNs', 2, None, '___sec5'), + ('Transforming images', 2, None, '___sec6'), + ('CNNs in brief', 2, None, '___sec7'), ('CNNs in more detail, building convolutional neural networks in ' 'Tensorflow and Keras', 2, None, - '___sec7'), - ('Setting it up', 2, None, '___sec8'), - ('The MNIST dataset again', 2, None, '___sec9'), - ('Strong correlations', 2, None, '___sec10'), - ('Layers of a CNN', 2, None, '___sec11'), - ('Systematic reduction', 2, None, '___sec12'), + '___sec8'), + ('Setting it up', 2, None, '___sec9'), + ('The MNIST dataset again', 2, None, '___sec10'), + ('Strong correlations', 2, None, '___sec11'), + ('Layers of a CNN', 2, None, '___sec12'), + ('Systematic reduction', 2, None, '___sec13'), ('Prerequisites: Collect and pre-process data', 2, None, - '___sec13'), - ('Importing Keras and Tensorflow', 2, None, '___sec14'), - ('Running with Keras', 2, None, '___sec15'), - ('Final part', 2, None, '___sec16'), - ('Final visualization', 2, None, '___sec17'), - ('The CIFAR01 data set', 2, None, '___sec18'), - ('Verifying the data set', 2, None, '___sec19'), - ('Set up the model', 2, None, '___sec20'), - ('Add Dense layers on top', 2, None, '___sec21'), - ('Compile and train the model', 2, None, '___sec22'), - ('Finally, evaluate the model', 2, None, '___sec23'), + '___sec14'), + ('Importing Keras and Tensorflow', 2, None, '___sec15'), + ('Running with Keras', 2, None, '___sec16'), + ('Final part', 2, None, '___sec17'), + ('Final visualization', 2, None, '___sec18'), + ('The CIFAR01 data set', 2, None, '___sec19'), + ('Verifying the data set', 2, None, '___sec20'), + ('Set up the model', 2, None, '___sec21'), + ('Add Dense layers on top', 2, None, '___sec22'), + ('Compile and train the model', 2, None, '___sec23'), + ('Finally, evaluate the model', 2, None, '___sec24'), ('Recurrent neural networks: Overarching view', 2, None, - '___sec24'), - ('Set up of an RNN', 2, None, '___sec25'), + '___sec25'), + ('Set up of an RNN', 2, None, '___sec26'), ('Solving differential equations and eigenvalue problems with ' 'RNNs', 2, None, - '___sec26'), - ('Long-Short Time Memory', 2, None, '___sec27'), - ('Autoencoders: Overarching view', 2, None, '___sec28'), - ('Simple examples of Autoencoders', 2, None, '___sec29')]} + '___sec27'), + ('Long-Short Time Memory', 2, None, '___sec28'), + ('Autoencoders: Overarching view', 2, None, '___sec29'), + ('Simple examples of Autoencoders', 2, None, '___sec30')]} end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({ @@ -192,7 +194,7 @@ MathJax.Hub.Config({-
@@ -216,7 +218,7 @@ MathJax.Hub.Config({
-As an example, consider -an image of size \( 32\times 32\times 3 \) (32 wide, 32 high, 3 color channels), so a -single fully-connected neuron in a first hidden layer of a regular -Neural Network would have \( 32\times 32\times 3 = 3072 \) weights. This amount still -seems manageable, but clearly this fully-connected structure does not -scale to larger images. For example, an image of more respectable -size, say \( 200\times 200\times 3 \), would lead to neurons that have -\( 200\times 200\times 3 = 120,000 \) weights. +Neural networks are defined as affine transformations, that is +a vector is received as input and is multiplied with a matrix of so-called weights (our unknown paramters) to produce an +output (to which a bias vector is usually added before passing the result +through a nonlinear activation function). This is applicable to any type of input, be it an +image, a sound clip or an unordered collection of features: whatever their +dimensionality, their representation can always be flattened into a vector +before the transformation.
-We could have -several such neurons, and the parameters would add up quickly! Clearly, -this full connectivity is wasteful and the huge number of parameters -would quickly lead to possible overfitting. +However, when we consider images, sound clips and many other similar kinds of data, these data have an intrinsic +structure. More formally, they share these important properties: + +
-
Figure 1: A regular 3-layer Neural Network.

@@ -217,7 +228,7 @@ would quickly lead to possible overfitting.
-Convolutional Neural Networks take advantage of the fact that the -input consists of images and they constrain the architecture in a more -sensible way. +As an example, consider +an image of size \( 32\times 32\times 3 \) (32 wide, 32 high, 3 color channels), so a +single fully-connected neuron in a first hidden layer of a regular +Neural Network would have \( 32\times 32\times 3 = 3072 \) weights. This amount still +seems manageable, but clearly this fully-connected structure does not +scale to larger images. For example, an image of more respectable +size, say \( 200\times 200\times 3 \), would lead to neurons that have +\( 200\times 200\times 3 = 120,000 \) weights.
-In particular, unlike a regular Neural Network, the -layers of a CNN have neurons arranged in 3 dimensions: width, -height, depth. (Note that the word depth here refers to the third -dimension of an activation volume, not to the depth of a full Neural -Network, which can refer to the total number of layers in a network.) - -
-To understand it better, the above example of an image -with an input volume of -activations has dimensions \( 32\times 32\times 3 \) (width, height, -depth respectively). - -
-The neurons in a layer will -only be connected to a small region of the layer before it, instead of -all of the neurons in a fully-connected manner. Moreover, the final -output layer could for this specific image have dimensions \( 1\times 1 \times 10 \), -because by the -end of the CNN architecture we will reduce the full image into a -single vector of class scores, arranged along the depth -dimension. +We could have +several such neurons, and the parameters would add up quickly! Clearly, +this full connectivity is wasteful and the huge number of parameters +would quickly lead to possible overfitting.
Figure 2: A CNN arranges its neurons in three dimensions (width, height, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D output volume of neuron activations. In this example, the red input layer holds the image, so its width and height would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels).

Figure 1: A regular 3-layer Neural Network.

@@ -230,7 +220,7 @@ dimension.
- + -
-A simple CNN is a sequence of layers, and every layer of a CNN -transforms one volume of activations to another through a -differentiable function. We use three main types of layers to build -CNN architectures: Convolutional Layer, Pooling Layer, and -Fully-Connected Layer (exactly as seen in regular Neural Networks). We -will stack these layers to form a full CNN architecture. +Convolutional Neural Networks take advantage of the fact that the +input consists of images and they constrain the architecture in a more +sensible way.
-A simple CNN for image classification could have the architecture: +In particular, unlike a regular Neural Network, the +layers of a CNN have neurons arranged in 3 dimensions: width, +height, depth. (Note that the word depth here refers to the third +dimension of an activation volume, not to the depth of a full Neural +Network, which can refer to the total number of layers in a network.) -
+To understand it better, the above example of an image +with an input volume of +activations has dimensions \( 32\times 32\times 3 \) (width, height, +depth respectively). +
+The neurons in a layer will +only be connected to a small region of the layer before it, instead of +all of the neurons in a fully-connected manner. Moreover, the final +output layer could for this specific image have dimensions \( 1\times 1 \times 10 \), +because by the +end of the CNN architecture we will reduce the full image into a +single vector of class scores, arranged along the depth +dimension. + +
+
Figure 2: A CNN arranges its neurons in three dimensions (width, height, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D output volume of neuron activations. In this example, the red input layer holds the image, so its width and height would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels).

- + -
-CNNs transform the original image layer by layer from the original -pixel values to the final class scores. +A simple CNN is a sequence of layers, and every layer of a CNN +transforms one volume of activations to another through a +differentiable function. We use three main types of layers to build +CNN architectures: Convolutional Layer, Pooling Layer, and +Fully-Connected Layer (exactly as seen in regular Neural Networks). We +will stack these layers to form a full CNN architecture.
-Observe that some layers contain -parameters and other don’t. In particular, the CNN layers perform -transformations that are a function of not only the activations in the -input volume, but also of the parameters (the weights and biases of -the neurons). On the other hand, the RELU/POOL layers will implement a -fixed function. The parameters in the CONV/FC layers will be trained -with gradient descent so that the class scores that the CNN computes -are consistent with the labels in the training set for each image. +A simple CNN for image classification could have the architecture: + +
-In summary: +CNNs transform the original image layer by layer from the original +pixel values to the final class scores. -
+Observe that some layers contain +parameters and other don’t. In particular, the CNN layers perform +transformations that are a function of not only the activations in the +input volume, but also of the parameters (the weights and biases of +the neurons). On the other hand, the RELU/POOL layers will implement a +fixed function. The parameters in the CONV/FC layers will be trained +with gradient descent so that the class scores that the CNN computes +are consistent with the labels in the training set for each image.
@@ -214,7 +214,7 @@ and the slides of 16
-As discussed above, CNNs are neural networks built from the assumption that the inputs -to the network are 2D images. This is important because the number of features or pixels in images -grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. +In summary: -
-As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks -are the convolutional and pooling layers stacked in pairs between the input and the hidden layer. -In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D -matrices, typically 1 for each color dimension (Red, Green, Blue). +
@@ -210,7 +217,7 @@ matrices, typically 1 for each color dimension (Red, Green, Blue).
-It means that to represent the entire -dataset of images, we require a 4D matrix or tensor. This tensor has the dimensions: -$$ -(n_{inputs},\, n_{pixels, width},\, n_{pixels, height},\, depth) . -$$ +As discussed above, CNNs are neural networks built from the assumption that the inputs +to the network are 2D images. This is important because the number of features or pixels in images +grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. + +
+As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks +are the convolutional and pooling layers stacked in pairs between the input and the hidden layer. +In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D +matrices, typically 1 for each color dimension (Red, Green, Blue).
@@ -207,7 +213,7 @@ $$
-The MNIST dataset consists of grayscale images with a pixel size of -\( 28\times 28 \), meaning we require \( 28 \times 28 = 724 \) weights to each -neuron in the first hidden layer. - -
-If we were to analyze images of size \( 128\times 128 \) we would require -\( 128 \times 128 = 16384 \) weights to each neuron. Even worse if we were -dealing with color images, as most images are, we have an image matrix -of size \( 128\times 128 \) for each color dimension (Red, Green, Blue), -meaning 3 times the number of weights \( = 49152 \) are required for every -single neuron in the first hidden layer. +It means that to represent the entire +dataset of images, we require a 4D matrix or tensor. This tensor has the dimensions: +$$ +(n_{inputs},\, n_{pixels, width},\, n_{pixels, height},\, depth) . +$$
@@ -214,7 +210,7 @@ single neuron in the first hidden layer.
-Images typically have strong local correlations, meaning that a small -part of the image varies little from its neighboring regions. If for -example we have an image of a blue car, we can roughly assume that a -small blue part of the image is surrounded by other blue regions. +The MNIST dataset consists of grayscale images with a pixel size of +\( 28\times 28 \), meaning we require \( 28 \times 28 = 724 \) weights to each +neuron in the first hidden layer.
-Therefore, instead of connecting every single pixel to a neuron in the -first hidden layer, as we have previously done with deep neural -networks, we can instead connect each neuron to a small part of the -image (in all 3 RGB depth dimensions). The size of each small area is -fixed, and known as a receptive. +If we were to analyze images of size \( 128\times 128 \) we would require +\( 128 \times 128 = 16384 \) weights to each neuron. Even worse if we were +dealing with color images, as most images are, we have an image matrix +of size \( 128\times 128 \) for each color dimension (Red, Green, Blue), +meaning 3 times the number of weights \( = 49152 \) are required for every +single neuron in the first hidden layer.
@@ -214,7 +216,7 @@ fixed, and known as a 20
- + -
-A convolution is performed on the image which outputs -a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as filters. +Images typically have strong local correlations, meaning that a small +part of the image varies little from its neighboring regions. If for +example we have an image of a blue car, we can roughly assume that a +small blue part of the image is surrounded by other blue regions.
-Each filter slides along the input image, taking the dot product -between each small part of the image and the filter, in all depth -dimensions. This is then passed through a non-linear function, -typically the Rectified Linear (ReLu) function, which serves as the -activation of the neurons in the first convolutional layer. This is -further passed through a pooling layer, which reduces the size of the -convolutional layer, e.g. by taking the maximum or average across some -small regions, and this serves as input to the next convolutional -layer. +Therefore, instead of connecting every single pixel to a neuron in the +first hidden layer, as we have previously done with deep neural +networks, we can instead connect each neuron to a small part of the +image (in all 3 RGB depth dimensions). The size of each small area is +fixed, and known as a receptive.
@@ -218,7 +216,7 @@ layer.
- + -
-By systematically reducing the size of the input volume, through -convolution and pooling, the network should create representations of -small parts of the input, and then from them assemble representations -of larger areas. The final pooling layer is flattened to serve as -input to a hidden layer, such that each neuron in the final pooling -layer is connected to every single neuron in the hidden layer. This -then serves as input to the output layer, e.g. a softmax output for -classification. +A convolution is performed on the image which outputs +a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as filters. + +
+Each filter slides along the input image, taking the dot product +between each small part of the image and the filter, in all depth +dimensions. This is then passed through a non-linear function, +typically the Rectified Linear (ReLu) function, which serves as the +activation of the neurons in the first convolutional layer. This is +further passed through a pooling layer, which reduces the size of the +convolutional layer, e.g. by taking the maximum or average across some +small regions, and this serves as input to the next convolutional +layer.
@@ -211,7 +220,7 @@ classification.
+By systematically reducing the size of the input volume, through +convolution and pooling, the network should create representations of +small parts of the input, and then from them assemble representations +of larger areas. The final pooling layer is flattened to serve as +input to a hidden layer, such that each neuron in the final pooling +layer is connected to every single neuron in the hidden layer. This +then serves as input to the output layer, e.g. a softmax output for +classification. - -
# import necessary packages
-import numpy as np
-import matplotlib.pyplot as plt
-from sklearn import datasets
-
-
-# ensure the same random numbers appear every time
-np.random.seed(0)
-
-# display images in notebook
-%matplotlib inline
-plt.rcParams['figure.figsize'] = (12,12)
-
-
-# download MNIST dataset
-digits = datasets.load_digits()
-
-# define inputs and labels
-inputs = digits.images
-labels = digits.target
-
-# RGB images have a depth of 3
-# our images are grayscale so they should have a depth of 1
-inputs = inputs[:,:,:,np.newaxis]
-
-print("inputs = (n_inputs, pixel_width, pixel_height, depth) = " + str(inputs.shape))
-print("labels = (n_inputs) = " + str(labels.shape))
-
-
-# choose some random images to display
-n_inputs = len(inputs)
-indices = np.arange(n_inputs)
-random_indices = np.random.choice(indices, size=5)
-
-for i, image in enumerate(digits.images[random_indices]):
- plt.subplot(1, 5, i+1)
- plt.axis('off')
- plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
- plt.title("Label: %d" % digits.target[random_indices[i]])
-plt.show()
-
@@ -244,7 +213,7 @@ plt.show()
-
from tensorflow.keras import datasets, layers, models
-from tensorflow.keras.layers import Input
-from tensorflow.keras.models import Sequential #This allows appending layers to existing models
-from tensorflow.keras.layers import Dense #This allows defining the characteristics of a particular layer
-from tensorflow.keras import optimizers #This allows using whichever optimiser we want (sgd,adam,RMSprop)
-from tensorflow.keras import regularizers #This allows using whichever regularizer we want (l1,l2,l1_l2)
-from tensorflow.keras.utils import to_categorical #This allows using categorical cross entropy as the cost function
-#from tensorflow.keras import Conv2D
-#from tensorflow.keras import MaxPooling2D
-#from tensorflow.keras import Flatten
+# import necessary packages
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn import datasets
-from sklearn.model_selection import train_test_split
-# representation of labels
-labels = to_categorical(labels)
+# ensure the same random numbers appear every time
+np.random.seed(0)
-# split into train and test data
-# one-liner from scikit-learn library
-train_size = 0.8
-test_size = 1 - train_size
-X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
- test_size=test_size)
+# display images in notebook
+%matplotlib inline
+plt.rcParams['figure.figsize'] = (12,12)
+
+
+# download MNIST dataset
+digits = datasets.load_digits()
+
+# define inputs and labels
+inputs = digits.images
+labels = digits.target
+
+# RGB images have a depth of 3
+# our images are grayscale so they should have a depth of 1
+inputs = inputs[:,:,:,np.newaxis]
+
+print("inputs = (n_inputs, pixel_width, pixel_height, depth) = " + str(inputs.shape))
+print("labels = (n_inputs) = " + str(labels.shape))
+
+
+# choose some random images to display
+n_inputs = len(inputs)
+indices = np.arange(n_inputs)
+random_indices = np.random.choice(indices, size=5)
+
+for i, image in enumerate(digits.images[random_indices]):
+ plt.subplot(1, 5, i+1)
+ plt.axis('off')
+ plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
+ plt.title("Label: %d" % digits.target[random_indices[i]])
+plt.show()
@@ -226,7 +246,7 @@ X_train, X_test, Y_train, Y_test = train_tes
- - -
-
def create_convolutional_neural_network_keras(input_shape, receptive_field,
- n_filters, n_neurons_connected, n_categories,
- eta, lmbd):
- model = Sequential()
- model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',
- activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
- model.add(layers.MaxPooling2D(pool_size=(2, 2)))
- model.add(layers.Flatten())
- model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
- model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))
-
- sgd = optimizers.SGD(lr=eta)
- model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
-
- return model
+from tensorflow.keras import datasets, layers, models
+from tensorflow.keras.layers import Input
+from tensorflow.keras.models import Sequential #This allows appending layers to existing models
+from tensorflow.keras.layers import Dense #This allows defining the characteristics of a particular layer
+from tensorflow.keras import optimizers #This allows using whichever optimiser we want (sgd,adam,RMSprop)
+from tensorflow.keras import regularizers #This allows using whichever regularizer we want (l1,l2,l1_l2)
+from tensorflow.keras.utils import to_categorical #This allows using categorical cross entropy as the cost function
+#from tensorflow.keras import Conv2D
+#from tensorflow.keras import MaxPooling2D
+#from tensorflow.keras import Flatten
-epochs = 100
-batch_size = 100
-input_shape = X_train.shape[1:4]
-receptive_field = 3
-n_filters = 10
-n_neurons_connected = 50
-n_categories = 10
+from sklearn.model_selection import train_test_split
-eta_vals = np.logspace(-5, 1, 7)
-lmbd_vals = np.logspace(-5, 1, 7)
+# representation of labels
+labels = to_categorical(labels)
+
+# split into train and test data
+# one-liner from scikit-learn library
+train_size = 0.8
+test_size = 1 - train_size
+X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
+ test_size=test_size)
@@ -231,7 +228,7 @@ lmbd_vals = np.
25
26
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs017.html b/doc/pub/week42/html/._week42-bs017.html
index a1c375e73..c4fd23fc3 100644
--- a/doc/pub/week42/html/._week42-bs017.html
+++ b/doc/pub/week42/html/._week42-bs017.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -171,29 +173,39 @@ MathJax.Hub.Config({
-
+
-Final part
+Running with Keras
-
CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
-
-for i, eta in enumerate(eta_vals):
- for j, lmbd in enumerate(lmbd_vals):
- CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,
+def create_convolutional_neural_network_keras(input_shape, receptive_field,
n_filters, n_neurons_connected, n_categories,
- eta, lmbd)
- CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
- scores = CNN.evaluate(X_test, Y_test)
-
- CNN_keras[i][j] = CNN
-
- print("Learning rate = ", eta)
- print("Lambda = ", lmbd)
- print("Test accuracy: %.3f" % scores[1])
- print()
+ eta, lmbd):
+ model = Sequential()
+ model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',
+ activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+ model.add(layers.MaxPooling2D(pool_size=(2, 2)))
+ model.add(layers.Flatten())
+ model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+ model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))
+
+ sgd = optimizers.SGD(lr=eta)
+ model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
+
+ return model
+
+epochs = 100
+batch_size = 100
+input_shape = X_train.shape[1:4]
+receptive_field = 3
+n_filters = 10
+n_neurons_connected = 50
+n_categories = 10
+
+eta_vals = np.logspace(-5, 1, 7)
+lmbd_vals = np.logspace(-5, 1, 7)
@@ -221,7 +233,7 @@ MathJax.Hub.Config({
26
27
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs018.html b/doc/pub/week42/html/._week42-bs018.html
index 4b8a3425f..80d890ca7 100644
--- a/doc/pub/week42/html/._week42-bs018.html
+++ b/doc/pub/week42/html/._week42-bs018.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,41 +175,27 @@ MathJax.Hub.Config({
-Final visualization
+Final part
-
# visual representation of grid search
-# uses seaborn heatmap, could probably do this in matplotlib
-import seaborn as sns
-
-sns.set()
-
-train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
-test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
-
-for i in range(len(eta_vals)):
- for j in range(len(lmbd_vals)):
- CNN = CNN_keras[i][j]
-
- train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]
- test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]
-
+CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
-fig, ax = plt.subplots(figsize = (10, 10))
-sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
-ax.set_title("Training Accuracy")
-ax.set_ylabel("$\eta$")
-ax.set_xlabel("$\lambda$")
-plt.show()
-
-fig, ax = plt.subplots(figsize = (10, 10))
-sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
-ax.set_title("Test Accuracy")
-ax.set_ylabel("$\eta$")
-ax.set_xlabel("$\lambda$")
-plt.show()
+for i, eta in enumerate(eta_vals):
+ for j, lmbd in enumerate(lmbd_vals):
+ CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,
+ n_filters, n_neurons_connected, n_categories,
+ eta, lmbd)
+ CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
+ scores = CNN.evaluate(X_test, Y_test)
+
+ CNN_keras[i][j] = CNN
+
+ print("Learning rate = ", eta)
+ print("Lambda = ", lmbd)
+ print("Test accuracy: %.3f" % scores[1])
+ print()
@@ -235,7 +223,7 @@ plt.show()
27
28
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs019.html b/doc/pub/week42/html/._week42-bs019.html
index 8be427815..c3c4825d5 100644
--- a/doc/pub/week42/html/._week42-bs019.html
+++ b/doc/pub/week42/html/._week42-bs019.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,27 +175,41 @@ MathJax.Hub.Config({
-The CIFAR01 data set
-
-
-The CIFAR10 dataset contains 60,000 color images in 10 classes, with
-6,000 images in each class. The dataset is divided into 50,000
-training images and 10,000 testing images. The classes are mutually
-exclusive and there is no overlap between them.
+
Final visualization
-
import tensorflow as tf
+# visual representation of grid search
+# uses seaborn heatmap, could probably do this in matplotlib
+import seaborn as sns
-from tensorflow.keras import datasets, layers, models
-import matplotlib.pyplot as plt
+sns.set()
-# We import the data set
-(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
+train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
-# Normalize pixel values to be between 0 and 1 by dividing by 255.
-train_images, test_images = train_images / 255.0, test_images / 255.0
+for i in range(len(eta_vals)):
+ for j in range(len(lmbd_vals)):
+ CNN = CNN_keras[i][j]
+
+ train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]
+ test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]
+
+
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Training Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Test Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
@@ -221,7 +237,7 @@ train_images, test_images = train_images 28
29
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs020.html b/doc/pub/week42/html/._week42-bs020.html
index 04300720f..6601a1f1d 100644
--- a/doc/pub/week42/html/._week42-bs020.html
+++ b/doc/pub/week42/html/._week42-bs020.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,28 +175,27 @@ MathJax.Hub.Config({
-Verifying the data set
+The CIFAR01 data set
-To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image.
+The CIFAR10 dataset contains 60,000 color images in 10 classes, with
+6,000 images in each class. The dataset is divided into 50,000
+training images and 10,000 testing images. The classes are mutually
+exclusive and there is no overlap between them.
-
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
- 'dog', 'frog', 'horse', 'ship', 'truck']
-
-plt.figure(figsize=(10,10))
-for i in range(25):
- plt.subplot(5,5,i+1)
- plt.xticks([])
- plt.yticks([])
- plt.grid(False)
- plt.imshow(train_images[i], cmap=plt.cm.binary)
- # The CIFAR labels happen to be arrays,
- # which is why you need the extra index
- plt.xlabel(class_names[train_labels[i][0]])
-plt.show()
+import tensorflow as tf
+
+from tensorflow.keras import datasets, layers, models
+import matplotlib.pyplot as plt
+
+# We import the data set
+(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
+
+# Normalize pixel values to be between 0 and 1 by dividing by 255.
+train_images, test_images = train_images / 255.0, test_images / 255.0
@@ -222,7 +223,7 @@ plt.show()
29
30
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs021.html b/doc/pub/week42/html/._week42-bs021.html
index 35bf76957..4de7b2312 100644
--- a/doc/pub/week42/html/._week42-bs021.html
+++ b/doc/pub/week42/html/._week42-bs021.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,31 +175,29 @@ MathJax.Hub.Config({
-Set up the model
+Verifying the data set
-The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.
-
-
-As input, a CNN takes tensors of shape (image_height, image_width, color_channels), ignoring the batch size. If you are new to these dimensions, color_channels refers to (R,G,B). In this example, you will configure our CNN to process inputs of shape (32, 32, 3), which is the format of CIFAR images. You can do this by passing the argument input_shape to our first layer.
+To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image.
-
model = models.Sequential()
-model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
-model.add(layers.MaxPooling2D((2, 2)))
-model.add(layers.Conv2D(64, (3, 3), activation='relu'))
-model.add(layers.MaxPooling2D((2, 2)))
-model.add(layers.Conv2D(64, (3, 3), activation='relu'))
-
-# Let's display the architecture of our model so far.
-
-model.summary()
+class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
+ 'dog', 'frog', 'horse', 'ship', 'truck']
+
+plt.figure(figsize=(10,10))
+for i in range(25):
+ plt.subplot(5,5,i+1)
+ plt.xticks([])
+ plt.yticks([])
+ plt.grid(False)
+ plt.imshow(train_images[i], cmap=plt.cm.binary)
+ # The CIFAR labels happen to be arrays,
+ # which is why you need the extra index
+ plt.xlabel(class_names[train_labels[i][0]])
+plt.show()
-
-You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tensor of shape (height, width, channels). The width and height dimensions tend to shrink as you go deeper in the network. The number of output channels for each Conv2D layer is controlled by the first argument (e.g., 32 or 64). Typically, as the width and height shrink, you can afford (computationally) to add more output channels in each Conv2D layer.
-
@@ -223,6 +223,8 @@ You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tenso
29
30
31
+ ...
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs022.html b/doc/pub/week42/html/._week42-bs022.html
index c7fd6aa04..08ae8a7ab 100644
--- a/doc/pub/week42/html/._week42-bs022.html
+++ b/doc/pub/week42/html/._week42-bs022.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,29 +175,30 @@ MathJax.Hub.Config({
-Add Dense layers on top
+Set up the model
-To complete our model, you will feed the last output tensor from the
-convolutional base (of shape (4, 4, 64)) into one or more Dense layers
-to perform classification. Dense layers take vectors as input (which
-are 1D), while the current output is a 3D tensor. First, you will
-flatten (or unroll) the 3D output to 1D, then add one or more Dense
-layers on top. CIFAR has 10 output classes, so you use a final Dense
-layer with 10 outputs and a softmax activation.
+The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.
+
+
+As input, a CNN takes tensors of shape (image_height, image_width, color_channels), ignoring the batch size. If you are new to these dimensions, color_channels refers to (R,G,B). In this example, you will configure our CNN to process inputs of shape (32, 32, 3), which is the format of CIFAR images. You can do this by passing the argument input_shape to our first layer.
-
model.add(layers.Flatten())
-model.add(layers.Dense(64, activation='relu'))
-model.add(layers.Dense(10))
-Here's the complete architecture of our model.
+model = models.Sequential()
+model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
+model.add(layers.MaxPooling2D((2, 2)))
+model.add(layers.Conv2D(64, (3, 3), activation='relu'))
+model.add(layers.MaxPooling2D((2, 2)))
+model.add(layers.Conv2D(64, (3, 3), activation='relu'))
+
+# Let's display the architecture of our model so far.
model.summary()
-As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (1024) before going through two Dense layers.
+You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tensor of shape (height, width, channels). The width and height dimensions tend to shrink as you go deeper in the network. The number of output channels for each Conv2D layer is controlled by the first argument (e.g., 32 or 64). Typically, as the width and height shrink, you can afford (computationally) to add more output channels in each Conv2D layer.
@@ -221,6 +224,7 @@ As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (102
29
30
31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs023.html b/doc/pub/week42/html/._week42-bs023.html
index 7574d65dc..a716661cd 100644
--- a/doc/pub/week42/html/._week42-bs023.html
+++ b/doc/pub/week42/html/._week42-bs023.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,18 +175,30 @@ MathJax.Hub.Config({
-Compile and train the model
+Add Dense layers on top
+
+
+To complete our model, you will feed the last output tensor from the
+convolutional base (of shape (4, 4, 64)) into one or more Dense layers
+to perform classification. Dense layers take vectors as input (which
+are 1D), while the current output is a 3D tensor. First, you will
+flatten (or unroll) the 3D output to 1D, then add one or more Dense
+layers on top. CIFAR has 10 output classes, so you use a final Dense
+layer with 10 outputs and a softmax activation.
-
model.compile(optimizer='adam',
- loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
- metrics=['accuracy'])
-
-history = model.fit(train_images, train_labels, epochs=10,
- validation_data=(test_images, test_labels))
+model.add(layers.Flatten())
+model.add(layers.Dense(64, activation='relu'))
+model.add(layers.Dense(10))
+Here's the complete architecture of our model.
+
+model.summary()
+
+As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (1024) before going through two Dense layers.
+
@@ -208,6 +222,7 @@ history = model
29
30
31
+ 32
»
diff --git a/doc/pub/week42/html/._week42-bs024.html b/doc/pub/week42/html/._week42-bs024.html
index fb0243964..0265afff6 100644
--- a/doc/pub/week42/html/._week42-bs024.html
+++ b/doc/pub/week42/html/._week42-bs024.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -173,21 +175,17 @@ MathJax.Hub.Config({
-Finally, evaluate the model
+Compile and train the model
-
plt.plot(history.history['accuracy'], label='accuracy')
-plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
-plt.xlabel('Epoch')
-plt.ylabel('Accuracy')
-plt.ylim([0.5, 1])
-plt.legend(loc='lower right')
-
-test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
-
-print(test_acc)
+model.compile(optimizer='adam',
+ loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
+ metrics=['accuracy'])
+
+history = model.fit(train_images, train_labels, epochs=10,
+ validation_data=(test_images, test_labels))
@@ -211,6 +209,7 @@ test_loss, test_acc = model29
30
31
+ 32
»
diff --git a/doc/pub/week42/html/week42-bs.html b/doc/pub/week42/html/week42-bs.html
index 13a511a78..027791251 100644
--- a/doc/pub/week42/html/week42-bs.html
+++ b/doc/pub/week42/html/week42-bs.html
@@ -46,51 +46,52 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -130,34 +131,35 @@ MathJax.Hub.Config({
@@ -192,7 +194,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Oct 11, 2020
+Oct 12, 2020
@@ -216,7 +218,7 @@ MathJax.Hub.Config({
9
10
...
- 31
+ 32
»
diff --git a/doc/pub/week42/html/week42-reveal.html b/doc/pub/week42/html/week42-reveal.html
index a6315472d..c5afdba58 100644
--- a/doc/pub/week42/html/week42-reveal.html
+++ b/doc/pub/week42/html/week42-reveal.html
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Oct 11, 2020
+Oct 12, 2020
@@ -212,7 +212,45 @@ Another good read is the article here Regular NNs don’t scale well to full images
+Neural Networks vs CNNs
+
+
+Neural networks are defined as affine transformations, that is
+a vector is received as input and is multiplied with a matrix of so-called weights (our unknown paramters) to produce an
+output (to which a bias vector is usually added before passing the result
+through a nonlinear activation function). This is applicable to any type of input, be it an
+image, a sound clip or an unordered collection of features: whatever their
+dimensionality, their representation can always be flattened into a vector
+before the transformation.
+
+
+However, when we consider images, sound clips and many other similar kinds of data, these data have an intrinsic
+structure. More formally, they share these important properties:
+
+
+- They are stored as multi-dimensional arrays (think of the pixels of a figure) .
+- They feature one or more axes for which ordering matters (e.g., width and height axes for an image, time axis for a sound clip).
+- One axis, called the channel axis, is used to access different views of the data (e.g., the red, green and blue channels of a color image, or the left and right channels of a stereo audio track).
+
+
+
+These properties are not exploited when an affine transformation is applied; in
+fact, all the axes are treated in the same way and the topological information
+is not taken into account. Still, taking advantage of the implicit structure of
+the data may prove very handy in solving some tasks, like computer vision and
+speech recognition, and in these cases it would be best to preserve it. This is
+where discrete convolutions come into play.
+
+
+A discrete convolution is a linear transformation that preserves this notion of
+ordering. It is sparse (only a few input units contribute to a given output
+unit) and reuses parameters (the same weights are applied to multiple locations
+in the input).
+
+
+
+
+Regular NNs don’t scale well to full images
As an example, consider
@@ -240,7 +278,7 @@ would quickly lead to possible overfitting.
-3D volumes of neurons
+3D volumes of neurons
Convolutional Neural Networks take advantage of the fact that the
@@ -280,7 +318,7 @@ dimension.
-Layers used to build CNNs
+Layers used to build CNNs
A simple CNN is a sequence of layers, and every layer of a CNN
@@ -304,7 +342,7 @@ A simple CNN for image classification could have the architecture:
-Transforming images
+Transforming images
CNNs transform the original image layer by layer from the original
@@ -323,7 +361,7 @@ are consistent with the labels in the training set for each image.
-CNNs in brief
+CNNs in brief
In summary:
@@ -345,7 +383,7 @@ and the slides of
-CNNs in more detail, building convolutional neural networks in Tensorflow and Keras
+CNNs in more detail, building convolutional neural networks in Tensorflow and Keras
As discussed above, CNNs are neural networks built from the assumption that the inputs
@@ -361,7 +399,7 @@ matrices, typically 1 for each color dimension (Red, Green, Blue).
-Setting it up
+Setting it up
It means that to represent the entire
@@ -376,7 +414,7 @@ $$
-The MNIST dataset again
+The MNIST dataset again
The MNIST dataset consists of grayscale images with a pixel size of
@@ -394,7 +432,7 @@ single neuron in the first hidden layer.
-Strong correlations
+Strong correlations
Images typically have strong local correlations, meaning that a small
@@ -412,7 +450,7 @@ fixed, and known as a
-Layers of a CNN
+Layers of a CNN
The layers of a convolutional neural network arrange neurons in 3D: width, height and depth.
The input image is typically a square matrix of depth 3.
@@ -434,7 +472,7 @@ layer.
-Systematic reduction
+Systematic reduction
By systematically reducing the size of the input volume, through
@@ -449,7 +487,7 @@ classification.
-Prerequisites: Collect and pre-process data
+Prerequisites: Collect and pre-process data
@@ -498,7 +536,7 @@ plt.show()
-Importing Keras and Tensorflow
+Importing Keras and Tensorflow
@@ -529,7 +567,7 @@ X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=t
-Running with Keras
+Running with Keras
@@ -565,7 +603,7 @@ lmbd_vals = np.logspace(-5, Final part
+Final part
@@ -591,7 +629,7 @@ lmbd_vals = np.logspace(-5, Final visualization
+Final visualization
@@ -631,7 +669,7 @@ plt.show()
-The CIFAR01 data set
+The CIFAR01 data set
The CIFAR10 dataset contains 60,000 color images in 10 classes, with
@@ -657,7 +695,7 @@ train_images, test_images = train_images / 255.0
-Verifying the data set
+Verifying the data set
To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image.
@@ -684,7 +722,7 @@ plt.show()
-Set up the model
+Set up the model
The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.
@@ -712,7 +750,7 @@ You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tenso
-Add Dense layers on top
+Add Dense layers on top
To complete our model, you will feed the last output tensor from the
@@ -739,7 +777,7 @@ As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (102
-Compile and train the model
+Compile and train the model
@@ -755,7 +793,7 @@ history = model.fit(train_images, train_labels, epochs=Finally, evaluate the model
+Finally, evaluate the model
@@ -775,7 +813,7 @@ test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=
-Recurrent neural networks: Overarching view
+Recurrent neural networks: Overarching view
Till now our focus has been, including convolutional neural networks
@@ -800,7 +838,7 @@ systems such as automatic translation and speech-to-text.
-Set up of an RNN
+Set up of an RNN
The figure here displays a simple example of an RNN, with inputs \( x_t \)
@@ -821,7 +859,7 @@ More material will be added here.
-Solving differential equations and eigenvalue problems with RNNs
+Solving differential equations and eigenvalue problems with RNNs
In our discussions of ordinary differential equations and partial
@@ -837,7 +875,7 @@ we start directly with an eigenvaule problem.
-Long-Short Time Memory
+Long-Short Time Memory
Discussions about dynamic unrolling through time. discuss memory cells, input and output
@@ -845,7 +883,7 @@ Discussions about dynamic unrolling through time. discuss memory cells, input an
-Autoencoders: Overarching view
+Autoencoders: Overarching view
Autoencoders are artificial neural networks capable of learning
@@ -877,7 +915,7 @@ learn the identity function under some constraints.
-Simple examples of Autoencoders
+Simple examples of Autoencoders
diff --git a/doc/pub/week42/html/week42-solarized.html b/doc/pub/week42/html/week42-solarized.html
index e28a1ebe8..16f12514a 100644
--- a/doc/pub/week42/html/week42-solarized.html
+++ b/doc/pub/week42/html/week42-solarized.html
@@ -40,51 +40,52 @@ div { text-align: justify; text-justify: inter-word; }
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -126,7 +127,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Oct 11, 2020
+Oct 12, 2020
@@ -183,7 +184,44 @@ Another good read is the article here Regular NNs don’t scale well to full images
+Neural Networks vs CNNs
+
+
+Neural networks are defined as affine transformations, that is
+a vector is received as input and is multiplied with a matrix of so-called weights (our unknown paramters) to produce an
+output (to which a bias vector is usually added before passing the result
+through a nonlinear activation function). This is applicable to any type of input, be it an
+image, a sound clip or an unordered collection of features: whatever their
+dimensionality, their representation can always be flattened into a vector
+before the transformation.
+
+
+However, when we consider images, sound clips and many other similar kinds of data, these data have an intrinsic
+structure. More formally, they share these important properties:
+
+
+- They are stored as multi-dimensional arrays (think of the pixels of a figure) .
+- They feature one or more axes for which ordering matters (e.g., width and height axes for an image, time axis for a sound clip).
+- One axis, called the channel axis, is used to access different views of the data (e.g., the red, green and blue channels of a color image, or the left and right channels of a stereo audio track).
+
+
+These properties are not exploited when an affine transformation is applied; in
+fact, all the axes are treated in the same way and the topological information
+is not taken into account. Still, taking advantage of the implicit structure of
+the data may prove very handy in solving some tasks, like computer vision and
+speech recognition, and in these cases it would be best to preserve it. This is
+where discrete convolutions come into play.
+
+
+A discrete convolution is a linear transformation that preserves this notion of
+ordering. It is sparse (only a few input units contribute to a given output
+unit) and reuses parameters (the same weights are applied to multiple locations
+in the input).
+
+
+
+
+
Regular NNs don’t scale well to full images
As an example, consider
@@ -211,7 +249,7 @@ would quickly lead to possible overfitting.
-
3D volumes of neurons
+3D volumes of neurons
Convolutional Neural Networks take advantage of the fact that the
@@ -251,7 +289,7 @@ dimension.
-
Layers used to build CNNs
+Layers used to build CNNs
A simple CNN is a sequence of layers, and every layer of a CNN
@@ -274,7 +312,7 @@ A simple CNN for image classification could have the architecture:
-
Transforming images
+Transforming images
CNNs transform the original image layer by layer from the original
@@ -293,7 +331,7 @@ are consistent with the labels in the training set for each image.
-
CNNs in brief
+CNNs in brief
In summary:
@@ -314,7 +352,7 @@ and the slides of
-CNNs in more detail, building convolutional neural networks in Tensorflow and Keras
+CNNs in more detail, building convolutional neural networks in Tensorflow and Keras
As discussed above, CNNs are neural networks built from the assumption that the inputs
@@ -330,7 +368,7 @@ matrices, typically 1 for each color dimension (Red, Green, Blue).
-
Setting it up
+Setting it up
It means that to represent the entire
@@ -342,7 +380,7 @@ $$
-
The MNIST dataset again
+The MNIST dataset again
The MNIST dataset consists of grayscale images with a pixel size of
@@ -360,7 +398,7 @@ single neuron in the first hidden layer.
-
Strong correlations
+Strong correlations
Images typically have strong local correlations, meaning that a small
@@ -378,7 +416,7 @@ fixed, and known as a
-Layers of a CNN
+Layers of a CNN
The layers of a convolutional neural network arrange neurons in 3D: width, height and depth.
The input image is typically a square matrix of depth 3.
@@ -400,7 +438,7 @@ layer.
-
Systematic reduction
+Systematic reduction
By systematically reducing the size of the input volume, through
@@ -415,7 +453,7 @@ classification.
-
Prerequisites: Collect and pre-process data
+Prerequisites: Collect and pre-process data
@@ -463,7 +501,7 @@ plt.show()
-
Importing Keras and Tensorflow
+Importing Keras and Tensorflow
@@ -493,7 +531,7 @@ X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=t
-
Running with Keras
+Running with Keras
@@ -528,7 +566,7 @@ lmbd_vals = np.logspace(-5, Final part
+Final part
@@ -553,7 +591,7 @@ lmbd_vals = np.logspace(-5, Final visualization
+Final visualization
@@ -592,7 +630,7 @@ plt.show()
-
The CIFAR01 data set
+The CIFAR01 data set
The CIFAR10 dataset contains 60,000 color images in 10 classes, with
@@ -617,7 +655,7 @@ train_images, test_images = train_images / 255.0
-Verifying the data set
+Verifying the data set
To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image.
@@ -643,7 +681,7 @@ plt.show()
-
Set up the model
+Set up the model
The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.
@@ -671,7 +709,7 @@ You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tenso
-
Add Dense layers on top
+Add Dense layers on top
To complete our model, you will feed the last output tensor from the
@@ -698,7 +736,7 @@ As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (102
-
Compile and train the model
+Compile and train the model
@@ -713,7 +751,7 @@ history = model.fit(train_images, train_labels, epochs=Finally, evaluate the model
+Finally, evaluate the model
@@ -732,7 +770,7 @@ test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=
-Recurrent neural networks: Overarching view
+Recurrent neural networks: Overarching view
Till now our focus has been, including convolutional neural networks
@@ -757,7 +795,7 @@ systems such as automatic translation and speech-to-text.
-
Set up of an RNN
+Set up of an RNN
The figure here displays a simple example of an RNN, with inputs \( x_t \)
@@ -778,7 +816,7 @@ More material will be added here.
-
Solving differential equations and eigenvalue problems with RNNs
+Solving differential equations and eigenvalue problems with RNNs
In our discussions of ordinary differential equations and partial
@@ -794,7 +832,7 @@ we start directly with an eigenvaule problem.
-
Long-Short Time Memory
+Long-Short Time Memory
Discussions about dynamic unrolling through time. discuss memory cells, input and output
@@ -802,7 +840,7 @@ Discussions about dynamic unrolling through time. discuss memory cells, input an
-
Autoencoders: Overarching view
+Autoencoders: Overarching view
Autoencoders are artificial neural networks capable of learning
@@ -834,7 +872,7 @@ learn the identity function under some constraints.
-
Simple examples of Autoencoders
+Simple examples of Autoencoders
diff --git a/doc/pub/week42/html/week42.html b/doc/pub/week42/html/week42.html
index a7e8c9099..153bc0fe0 100644
--- a/doc/pub/week42/html/week42.html
+++ b/doc/pub/week42/html/week42.html
@@ -45,51 +45,52 @@ div { text-align: justify; text-justify: inter-word; }
2,
None,
'___sec1'),
+ ('Neural Networks vs CNNs', 2, None, '___sec2'),
('Regular NNs don’t scale well to full images',
2,
None,
- '___sec2'),
- ('3D volumes of neurons', 2, None, '___sec3'),
- ('Layers used to build CNNs', 2, None, '___sec4'),
- ('Transforming images', 2, None, '___sec5'),
- ('CNNs in brief', 2, None, '___sec6'),
+ '___sec3'),
+ ('3D volumes of neurons', 2, None, '___sec4'),
+ ('Layers used to build CNNs', 2, None, '___sec5'),
+ ('Transforming images', 2, None, '___sec6'),
+ ('CNNs in brief', 2, None, '___sec7'),
('CNNs in more detail, building convolutional neural networks in '
'Tensorflow and Keras',
2,
None,
- '___sec7'),
- ('Setting it up', 2, None, '___sec8'),
- ('The MNIST dataset again', 2, None, '___sec9'),
- ('Strong correlations', 2, None, '___sec10'),
- ('Layers of a CNN', 2, None, '___sec11'),
- ('Systematic reduction', 2, None, '___sec12'),
+ '___sec8'),
+ ('Setting it up', 2, None, '___sec9'),
+ ('The MNIST dataset again', 2, None, '___sec10'),
+ ('Strong correlations', 2, None, '___sec11'),
+ ('Layers of a CNN', 2, None, '___sec12'),
+ ('Systematic reduction', 2, None, '___sec13'),
('Prerequisites: Collect and pre-process data',
2,
None,
- '___sec13'),
- ('Importing Keras and Tensorflow', 2, None, '___sec14'),
- ('Running with Keras', 2, None, '___sec15'),
- ('Final part', 2, None, '___sec16'),
- ('Final visualization', 2, None, '___sec17'),
- ('The CIFAR01 data set', 2, None, '___sec18'),
- ('Verifying the data set', 2, None, '___sec19'),
- ('Set up the model', 2, None, '___sec20'),
- ('Add Dense layers on top', 2, None, '___sec21'),
- ('Compile and train the model', 2, None, '___sec22'),
- ('Finally, evaluate the model', 2, None, '___sec23'),
+ '___sec14'),
+ ('Importing Keras and Tensorflow', 2, None, '___sec15'),
+ ('Running with Keras', 2, None, '___sec16'),
+ ('Final part', 2, None, '___sec17'),
+ ('Final visualization', 2, None, '___sec18'),
+ ('The CIFAR01 data set', 2, None, '___sec19'),
+ ('Verifying the data set', 2, None, '___sec20'),
+ ('Set up the model', 2, None, '___sec21'),
+ ('Add Dense layers on top', 2, None, '___sec22'),
+ ('Compile and train the model', 2, None, '___sec23'),
+ ('Finally, evaluate the model', 2, None, '___sec24'),
('Recurrent neural networks: Overarching view',
2,
None,
- '___sec24'),
- ('Set up of an RNN', 2, None, '___sec25'),
+ '___sec25'),
+ ('Set up of an RNN', 2, None, '___sec26'),
('Solving differential equations and eigenvalue problems with '
'RNNs',
2,
None,
- '___sec26'),
- ('Long-Short Time Memory', 2, None, '___sec27'),
- ('Autoencoders: Overarching view', 2, None, '___sec28'),
- ('Simple examples of Autoencoders', 2, None, '___sec29')]}
+ '___sec27'),
+ ('Long-Short Time Memory', 2, None, '___sec28'),
+ ('Autoencoders: Overarching view', 2, None, '___sec29'),
+ ('Simple examples of Autoencoders', 2, None, '___sec30')]}
end of tocinfo -->
@@ -131,7 +132,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Oct 11, 2020
+Oct 12, 2020
@@ -188,7 +189,44 @@ Another good read is the article here Regular NNs don’t scale well to full images
+Neural Networks vs CNNs
+
+
+Neural networks are defined as affine transformations, that is
+a vector is received as input and is multiplied with a matrix of so-called weights (our unknown paramters) to produce an
+output (to which a bias vector is usually added before passing the result
+through a nonlinear activation function). This is applicable to any type of input, be it an
+image, a sound clip or an unordered collection of features: whatever their
+dimensionality, their representation can always be flattened into a vector
+before the transformation.
+
+
+However, when we consider images, sound clips and many other similar kinds of data, these data have an intrinsic
+structure. More formally, they share these important properties:
+
+
+- They are stored as multi-dimensional arrays (think of the pixels of a figure) .
+- They feature one or more axes for which ordering matters (e.g., width and height axes for an image, time axis for a sound clip).
+- One axis, called the channel axis, is used to access different views of the data (e.g., the red, green and blue channels of a color image, or the left and right channels of a stereo audio track).
+
+
+These properties are not exploited when an affine transformation is applied; in
+fact, all the axes are treated in the same way and the topological information
+is not taken into account. Still, taking advantage of the implicit structure of
+the data may prove very handy in solving some tasks, like computer vision and
+speech recognition, and in these cases it would be best to preserve it. This is
+where discrete convolutions come into play.
+
+
+A discrete convolution is a linear transformation that preserves this notion of
+ordering. It is sparse (only a few input units contribute to a given output
+unit) and reuses parameters (the same weights are applied to multiple locations
+in the input).
+
+
+
+
+
Regular NNs don’t scale well to full images
As an example, consider
@@ -216,7 +254,7 @@ would quickly lead to possible overfitting.
-
3D volumes of neurons
+3D volumes of neurons
Convolutional Neural Networks take advantage of the fact that the
@@ -256,7 +294,7 @@ dimension.
-
Layers used to build CNNs
+Layers used to build CNNs
A simple CNN is a sequence of layers, and every layer of a CNN
@@ -279,7 +317,7 @@ A simple CNN for image classification could have the architecture:
-
Transforming images
+Transforming images
CNNs transform the original image layer by layer from the original
@@ -298,7 +336,7 @@ are consistent with the labels in the training set for each image.
-
CNNs in brief
+CNNs in brief