Question: Why i getting value error at history here is my code below import tensorflow as tf import matplotlib.pyplot as plt import numpy as np #

Why i getting value error at history here is my code below
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
# Check if TensorFlow detects a GPU
print(tf.config.list_physical_devices('GPU'))
# Load the MNIST dataset
mnist = tf.keras.datasets.mnist
(train_xs, train_ys),(test_xs, test_ys)= mnist.load_data()
# Normalize the data
train_xs = train_xs /255.0
test_xs = test_xs /255.0
# Reshape the data to match the input shape expected by Conv2D layers
train_xs = train_xs.reshape(60000,28,28,1)
test_xs = test_xs.reshape(10000,28,28,1)
# One-hot encode the labels
num_classes =10
train_ys = tf.keras.utils.to_categorical(train_ys, num_classes)
test_ys = tf.keras.utils.to_categorical(test_ys, num_classes)
# Import required layers and Sequential model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
# Initialize the model
model = Sequential()
# Add layers to the model
model.add(Conv2D(filters=64, kernel_size=(5,5), activation='relu', input_shape=(28,28,1)))
model.add(MaxPooling2D(pool_size=(2,2), strides=1))
model.add(Conv2D(filters=64, kernel_size=(5,5), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=1))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
# Print model summary
model.summary()
# Compile the model
model.compile(
optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
# Train the model
history = model.fit(train_xs, train_ys, epochs=5, validation_data=(test_xs, test_ys))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!