0% found this document useful (0 votes)
11 views1 page

Training

The document loads and preprocesses the MNIST dataset, defines a convolutional neural network model to classify MNIST digits, compiles and trains the model on the training data, and evaluates it on the test data.

Uploaded by

raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Training

The document loads and preprocesses the MNIST dataset, defines a convolutional neural network model to classify MNIST digits, compiles and trains the model on the training data, and evaluates it on the test data.

Uploaded by

raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

from keras.

datasets import mnist


from keras import models
from keras import layers
from keras.utils import to_categorical

import matplotlib.pyplot as plt

# trainX = train_image
# trainy = train_labels
# testX = test_images
# testy = test_labels

(train_image, train_labels), (test_images, test_labels) = mnist.load_data()


train_image.shape
train_labels.shape
len(train_labels)
test_image.shape
test_labels.shape
len(test_labels)
network.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)))
network.add(layers.MaxPooling2D((2, 2)))
network.add(layers.Conv2D(64, (3,3), activation='relu'))
network.add(layers.MaxPooling2D(2,2))
network.add(layers.Conv2D(64, (3,3), activation='relu'))
network.add(layers.Flatten())
network.add(layers.Dense(64, activation='relu'))
network.add(layers.Dense(10, activation='softmax'))
train_image = train_image.reshape((60000, 28 , 28, 1))
train_image = train_image.astype('float32') / 255

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


test_images = test_images.astype('float32') / 255

train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)

network.compile(optimizer='rmsprop', loss='categorical_crossentropy',
metrics=['accuracy'])

history = network.fit(train_image, train_labels, epochs=60)

test_loss, test_acc = network.evaluate(test_images, test_labels)


print('test_acc: ', test_acc)

You might also like