liveBook · Manning

Convolutional neural network

As explained in Distributed Machine Learning Patterns

A convolutional neural network is a neural network model that uses convolutional operations to learn spatial or locally structured representations.

A convolutional neural network (CNN) learns image representations through convolutional layers. A practical classifier can process 28 × 28 video frames, use convolution and pooling to learn feature mappings, then use dense layers to assign one of 10 entities. section 3.2.2

A TensorFlow CNN can be assembled sequentially: name the input, add three convolutional layers with max pooling, flatten the resulting features, and finish with dense and softmax layers. Compile it with Adam, sparse categorical cross-entropy, and accuracy before training. section 9.2.1

Listing 9.4 Defining the basic CNN model
def build_and_compile_cnn_model():
 print("Training CNN model")
 model = models.Sequential()
 model.add(layers.Input(shape=(28, 28, 1), name='image_bytes'))
 model.add(
         layers.Conv2D(32, (3, 3), activation='relu'))
 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'))
 model.add(layers.Flatten())
 model.add(layers.Dense(64, activation='relu'))
 model.add(layers.Dense(10, activation='softmax'))
 model.summary()
 model.compile(optimizer='adam',
          loss='sparse_categorical_crossentropy',
          metrics=['accuracy'])
 return model

This implementation shows the complete layer flow for a 28 × 28 single-channel input: Conv2D and pooling stages, flattening, a dense hidden layer, and 10-class softmax output. section 9.2.1

Useful training and model-variant choices include:

  • Train locally with fit() and callbacks for learning-rate reporting, TensorBoard monitoring, checkpoints, and learning-rate decay. section 9.2.1
  • Compare a basic CNN with batch-normalized and dropout variants; batch normalization standardizes layer pre-activations, while dropout randomly removes half of hidden units to reduce complexity. section 9.2.1
  • Run distributed training for the three variants in parallel, persist their trained models, select a model, and send it to a serving step. section 9.4.1

Parallel CNN selection pipeline

A workflow downloads Fashion-MNIST into persistent storage, launches separate two-worker TFJobs for the basic, dropout, and batch-normalized CNNs, selects a trained model, and creates a TensorFlow inference service. section 9.4.1

How Distributed Machine Learning Patterns covers it

How deep it goes
Works through TensorFlow layer construction, compilation, callbacks, variants, and distributed execution; defers convolution operation internals.
Examples
Uses LeNet for 10-entity video classification and Fashion-MNIST CNN variants trained through parallel TFJobs.
What it assumes
Assumes an input pipeline and introduces CNN construction from a named 28 × 28 input layer.
What you can do after
Operate/configure it as a TensorFlow CNN, train variants, and run their distributed selection-and-serving workflow.
How it connects
Connects convolutional layers, max pooling, dense layers, batch normalization, dropout, TensorFlow, TFJob, and model serving.

Also explained in

Compare how 18 books explain convolutional neural network →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Distributed Machine Learning Patterns. The section links point to the parts of the book it draws on.