Convolutions: several convolutions in parallel, generating a set of linear activations
Nonlinear activation: applied to each linear output (typically ReLU)
(detector stage)
Pooling: aggregates the outputs in a single output for each region
Pooling
Pooling: aggregating outputs
Example: max pooling
Image: Aphex34, CC-SA
Pooling
Pooling: aggregating outputs
Typical pooling functions:
Max pooling, average pooling, L$^2$ norm pooling: $\sqrt{ \sum x_i^2}$
Pooling makes model nearly invariant to small shifts in input
Pooling Stride
We may want to regulate the overlap of pooling regions
If the stride is equal to the size of the regions, then there is no overlap
Stride also reduces the dimension
(pooling of stride 1, with padding, preserves dimension)
Classificaton with CNN
For classification, conv layers combined with MLP
Fully connected layers at the end to predict class for example
Forces fixed-sized input and output not spacial
Alex Krizhevsky, Ilya Sutskever, Geoffrey E. Hinton, 2012
Convolutional networks
Tutorial: Keras Sequential API
Keras Sequential
Building a model with Keras
Start by importing classes:
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization,Conv2D,MaxPooling2D,
from tensorflow.keras.layers import Activation, Flatten, Dropout, Dense
Auto MPG Data Set, available at the UCI repository
Some pointers:
Shuffle the data before splitting into training and validation sets
Target: first column, MPG (miles per gallon)
Standardize features and target value
Standardizing target centers the output and minimizes numerical problems
Only 392 examples. Use 300 for training and 92 for validation.
Linear output for the last neuron (only one neuron)
Mean squared error loss function for training
Try different activations and learning parameters (rate, momentum)
Tutorial
Regression with the Auto MPG Data Set
Load, standardize, use 300 for train and rest for validation:
data = np.loadtxt('AutoMPG.tsv',skiprows=1)
np.random.shuffle(data)
means = np.mean(data,axis=0)
stds = np.std(data,axis=0)
data = (data-means)/stds
valid_Y = data[300:,0]
valid_X = data[300:,1:]
Y = data[:300,0]
X = data[:300,1:]
Tutorial
Fashion MNIST
https://github.com/zalandoresearch/fashion-mnist
Grayscale images, 28x28, 10 classes of clothing
Tutorial
Import the dataset and set up the data
from tensorflow import keras
((trainX, trainY), (testX, testY)) = keras.datasets.fashion_mnist.load_data()
trainX = trainX.reshape((trainX.shape[0], 28, 28, 1))
testX = testX.reshape((testX.shape[0], 28, 28, 1))
trainX = trainX.astype("float32") / 255.0
testX = testX.astype("float32") / 255.0
# one-hot encode the training and testing labels
trainY = keras.utils.to_categorical(trainY, 10)
testY = keras.utils.to_categorical(testY, 10)