Skip to content

Commit 0d9804a

Browse files
committed
cnn_mnist.py: For the Convolutional Neural Network (CNN) model.
1 parent 2603c8a commit 0d9804a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

machine_learning/neural_networks/cnn_mnist.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from tensorflow.keras.utils import to_categorical
2020

2121
# Load and preprocess the MNIST data
22-
(X_train, y_train), (X_test, y_test) = mnist.load_data()
22+
(x_train, y_train), (x_test, y_test) = mnist.load_data()
2323

2424
# Normalize the pixel values (0 to 1)
25-
X_train = X_train.reshape(-1, 28, 28, 1).astype("float32") / 255
26-
X_test = X_test.reshape(-1, 28, 28, 1).astype("float32") / 255
25+
x_train = x_train.reshape(-1, 28, 28, 1).astype("float32") / 255
26+
x_test = x_test.reshape(-1, 28, 28, 1).astype("float32") / 255
2727

2828
# Convert labels to one-hot encoding
2929
y_train = to_categorical(y_train, 10)
@@ -64,9 +64,9 @@
6464

6565
# Train the model
6666
history = model.fit(
67-
X_train, y_train, epochs=5, batch_size=32, validation_data=(X_test, y_test)
67+
x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test)
6868
)
6969

7070
# Evaluate the model on test data
71-
test_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)
71+
test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2)
7272
print(f"\nTest accuracy: {test_acc}")

0 commit comments

Comments
 (0)