0% found this document useful (0 votes)
39 views2 pages

MNIST Neural Network with TensorFlow

Uploaded by

shahmurrawat
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)
39 views2 pages

MNIST Neural Network with TensorFlow

Uploaded by

shahmurrawat
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

1

import tensorflow as tf
from [Link] import models, layers

# Define the model


network = [Link]()

# Add layers to the model


[Link]([Link](512, activation='relu', input_shape=(28 * 28,)))
[Link]([Link](0.5))
[Link]([Link](10, activation='softmax'))

# Display the model's architecture


[Link]()
2
import tensorflow as tf
from [Link] import models, layers

# Define the model


network = [Link]()

# Add layers to the model


[Link]([Link](512, activation='relu', input_shape=(28 * 28,)))
[Link]([Link](0.5))
[Link]([Link](10, activation='softmax'))

# Compile the model


[Link](optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])

# Display the model's architecture


[Link]()
3
import tensorflow as tf
from [Link] import models, layers
from [Link] import mnist

# Load the MNIST dataset


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

# Normalize the images to the range [0, 1]


train_images = train_images / 255.0
test_images = test_images / 255.0

# Flatten the images from 28x28 to 784 for the dense layer
train_images = train_images.reshape((60000, 28 * 28))
test_images = test_images.reshape((10000, 28 * 28))

# Convert the labels to one-hot encoding


train_labels = [Link].to_categorical(train_labels)
test_labels = [Link].to_categorical(test_labels)

# Define the model


network = [Link]()
[Link]([Link](512, activation='relu', input_shape=(28 * 28,)))
[Link]([Link](0.5))
[Link]([Link](10, activation='softmax'))
# Compile the model
[Link](
optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy']
)

# Train the model


[Link](train_images, train_labels, epochs=5, batch_size=128)

# Evaluate the model


test_loss, test_acc = [Link](test_images, test_labels)
print(f'Test accuracy: {test_acc}')

You might also like