09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Convolutional Neural Networks

Then we have a pretty standard flattening and a dense network of 500 neurons,

followed by a softmax classifier with 10 classes:

# Flatten => RELU layers

model.add(layers.Flatten())

model.add(layers.Dense(500, activation='relu'))

# a softmax classifier

model.add(layers.Dense(classes, activation="softmax"))

return model

Congratulations, you have just defined your first deep convolutional learning

network! Let's see how it looks visually:

Figure 5: Visualization of LeNet

Now we need some additional code for training the network, but this is very similar

to what we have already described in Chapter 1, Neural Network Foundations with

TensorFlow 2.0. This time we also show the code for printing the loss:

# data: shuffled and split between train and test sets

(X_train, y_train), (X_test, y_test) = datasets.mnist.load_data()

# reshape

X_train = X_train.reshape((60000, 28, 28, 1))

X_test = X_test.reshape((10000, 28, 28, 1))

# normalize

[ 116 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!