Ex 5
Ex 5
AIM:
To write the python code for Pattern Recognition System by utilizing training algorithm for
pattern association in images.
ALGORITHM:
STEP 2: Load the MNIST dataset using mnist.load_data() and split it into training and testing sets.
STEP 3: Normalize the image data by converting pixel values to the range [0, 1] using astype('float32') /
255.0.
STEP 4: Flatten the 28x28 images into 1D vectors of size 784 using reshape().
5.1 Add a Dense layer with 64 neurons and ReLU activation (Encoder).
5.2 Add a Dense layer with 784 neurons and Sigmoid activation (Decoder).
STEP 6: Compile the model using the Adam optimizer and Binary Crossentropy loss function.
7.1 10 epochs
7.2 Batch size of 256
7.3 Validation data from the test set
STEP 8: Predict the reconstructed images using autoencoder.predict() on the test data.
STEP 9: Visualize the original and reconstructed images using matplotlib.pyplot with a 2-row layout.
PROGRAM:
import numpy as np
CSE/NM/NN&DL / 513322104003/DHIVYA G
(x_train, _), (x_test, _) = mnist.load_data()
autoencoder = Sequential()
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
decoded_imgs = autoencoder.predict(x_test)
plt.figure(figsize=(20, 4))
for i in range(n):
# Display original
ax = plt.subplot(2, n, i + 1)
plt.axis('off')
# Display reconstruction
ax = plt.subplot(2, n, i + 1 + n)
CSE/NM/NN&DL / 513322104003/DHIVYA G
plt.imshow(decoded_imgs[i].reshape(28, 28), cmap='gray')
plt.axis('off')
plt.show()
OUTPUT:
RESULT:
Thus, the python code for Pattern Recognition System is executed successfully.
CSE/NM/NN&DL / 513322104003/DHIVYA G