0% found this document useful (0 votes)
8 views6 pages

SiddharthShah 1032221195 DivC 50 DL LabAssignment4

Description

Uploaded by

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

SiddharthShah 1032221195 DivC 50 DL LabAssignment4

Description

Uploaded by

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

import tensorflow as tf

from tensorflow.keras import layers, models


import datetime

# Load the MNIST dataset


mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0 # Normalize the data

# Define the model


model = tf.keras.Sequential([
tf.keras.Input(shape=(28, 28)),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(10, activation='softmax')
])

# Compile the model


model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

# Create a TensorBoard callback


log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir,
histogram_freq=1)

# Train the model with TensorBoard callback


model.fit(x_train, y_train, epochs=5, validation_data=(x_test, y_test),
callbacks=[tensorboard_callback])

# Evaluate the model


test_loss, test_acc = model.evaluate(x_test, y_test)
print(f"Test accuracy: {test_acc}")

You might also like