pdfcoffee
Chapter 4Pooling layersLet's suppose that we want to summarize the output of a feature map. Again, wecan use the spatial contiguity of the output produced from a single feature mapand aggregate the values of a sub-matrix into one single output value syntheticallydescribing the "meaning" associated with that physical region.Max poolingOne easy and common choice is the so-called max-pooling operator, which simplyoutputs the maximum activation as observed in the region. In Keras, if we wantto define a max pooling layer of size 2×2, we write:model.add(layers.MaxPooling2D((2, 2)))An example of the max-pooling operation is given in Figure 4:Figure 4: An example of max poolingAverage poolingAnother choice is average pooling, which simply aggregates a region into the averagevalues of the activations observed in that region.Note that Keras implements a large number of pooling layers and a complete list isavailable online (https://keras.io/layers/pooling/). In short, all the poolingoperations are nothing more than a summary operation on a given region.ConvNets summarySo far, we have described the basic concepts of ConvNets. CNNs apply convolutionand pooling operations in 1 dimension for audio and text data along the timedimension, in two dimensions for images along the (height × width) dimensionsand in three dimensions for videos along the (height × width × time) dimensions.For images, sliding the filter over an input volume produces a map that providesthe responses of the filter for each spatial position.[ 113 ]
Convolutional Neural NetworksIn other words, a CNN has multiple filters stacked together that learn to recognizespecific visual features independently from the location in the image itself. Thosevisual features are simple in the initial layers of the network and become moreand more sophisticated deeper in the network. Training of a CNN requires theidentification of the right values for each filter so that an input, when passed throughmultiple layers, activates certain neurons of the last layer so that it will predict thecorrect values.An example of DCNN ‒ LeNetYann LeCun, who very recently won the Turing Award, proposed [1] a familyof convnets named LeNet trained for recognizing MNIST handwritten characterswith robustness to simple geometric transformations and distortion. The core ideaof LeNets is to have lower layers alternating convolution operations with maxpoolingoperations. The convolution operations are based on carefully chosen localreceptive fields with shared weights for multiple feature maps. Then, higher levelsare fully connected based on a traditional MLP with hidden layers and softmax asoutput layer.LeNet code in TensorFlow 2.0To define a LeNet in code we use a convolutional 2D module:layers.Convolution2D(20, (5, 5), activation='relu', input_shape=input_shape))Note that tf.keras.layers.Conv2D is an alias of tf.keras.layers.Convolution2D so the two can be used in aninterchangeable way. See https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D.Where the first parameter is the number of output filters in the convolution, andthe next tuple is the extension of each filter. An interesting optional parameter ispadding. There are two options: padding='valid' means that the convolution isonly computed where the input and the filter fully overlap and therefore the outputis smaller than the input, while padding='same' means that we have an outputwhich is the same size as the input, for which the area around the input is paddedwith zeros.In addition, we use a MaxPooling2D module:layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2))[ 114 ]
- Page 98 and 99: Chapter 2state = [tf.zeros([100, 10
- Page 100 and 101: Chapter 2For now, there's no need t
- Page 102 and 103: Chapter 2Let's see an example of a
- Page 104 and 105: Chapter 2If you want to save a mode
- Page 106 and 107: Chapter 2supervised=True)train_data
- Page 108 and 109: Chapter 2There, tf.feature_column.n
- Page 110 and 111: Chapter 2print (dz_dx)print (dy_dx)
- Page 112 and 113: Chapter 2In our toy example we use
- Page 114 and 115: Chapter 2For multi-machine training
- Page 116 and 117: Chapter 25. Use tf.layers modules t
- Page 118 and 119: Chapter 2Keras or tf.keras?Another
- Page 120: • tf.data can be used to load mod
- Page 123 and 124: RegressionLet us imagine a simpler
- Page 125 and 126: RegressionTake a look at the last t
- Page 127 and 128: Regression3. Now, we calculate the
- Page 129 and 130: RegressionIn the next section we wi
- Page 131 and 132: Regression2. Now, we define the fea
- Page 133 and 134: Regression2. Download the dataset:(
- Page 135 and 136: RegressionThe following is the Tens
- Page 137 and 138: RegressionIn regression the aim is
- Page 139 and 140: RegressionThe Estimator outputs the
- Page 141 and 142: RegressionThe following is the grap
- Page 143 and 144: RegressionReferencesHere are some g
- Page 145 and 146: Convolutional Neural NetworksIn thi
- Page 147: Convolutional Neural NetworksIn thi
- Page 151 and 152: Convolutional Neural NetworksThen w
- Page 153 and 154: Convolutional Neural NetworksHoweve
- Page 155 and 156: Convolutional Neural NetworksPlotti
- Page 157 and 158: Convolutional Neural NetworksIn gen
- Page 159 and 160: Convolutional Neural NetworksOur ne
- Page 161 and 162: Convolutional Neural NetworksThese
- Page 163 and 164: Convolutional Neural NetworksSo, we
- Page 165 and 166: Convolutional Neural NetworksEach i
- Page 167 and 168: Convolutional Neural NetworksVery d
- Page 169 and 170: Convolutional Neural NetworksRecogn
- Page 171 and 172: Convolutional Neural NetworksIf we
- Page 173 and 174: Convolutional Neural NetworksRefere
- Page 175 and 176: Advanced Convolutional Neural Netwo
- Page 177 and 178: Advanced Convolutional Neural Netwo
- Page 179 and 180: Advanced Convolutional Neural Netwo
- Page 181 and 182: Advanced Convolutional Neural Netwo
- Page 183 and 184: Advanced Convolutional Neural Netwo
- Page 185 and 186: Advanced Convolutional Neural Netwo
- Page 187 and 188: Advanced Convolutional Neural Netwo
- Page 189 and 190: Advanced Convolutional Neural Netwo
- Page 191 and 192: Advanced Convolutional Neural Netwo
- Page 193 and 194: Advanced Convolutional Neural Netwo
- Page 195 and 196: Advanced Convolutional Neural Netwo
- Page 197 and 198: Advanced Convolutional Neural Netwo
Chapter 4
Pooling layers
Let's suppose that we want to summarize the output of a feature map. Again, we
can use the spatial contiguity of the output produced from a single feature map
and aggregate the values of a sub-matrix into one single output value synthetically
describing the "meaning" associated with that physical region.
Max pooling
One easy and common choice is the so-called max-pooling operator, which simply
outputs the maximum activation as observed in the region. In Keras, if we want
to define a max pooling layer of size 2×2, we write:
model.add(layers.MaxPooling2D((2, 2)))
An example of the max-pooling operation is given in Figure 4:
Figure 4: An example of max pooling
Average pooling
Another choice is average pooling, which simply aggregates a region into the average
values of the activations observed in that region.
Note that Keras implements a large number of pooling layers and a complete list is
available online (https://keras.io/layers/pooling/). In short, all the pooling
operations are nothing more than a summary operation on a given region.
ConvNets summary
So far, we have described the basic concepts of ConvNets. CNNs apply convolution
and pooling operations in 1 dimension for audio and text data along the time
dimension, in two dimensions for images along the (height × width) dimensions
and in three dimensions for videos along the (height × width × time) dimensions.
For images, sliding the filter over an input volume produces a map that provides
the responses of the filter for each spatial position.
[ 113 ]