21MCI1126 - Nikhil - Raj 2.1
21MCI1126 - Nikhil - Raj 2.1
Aim/Overview of the practical: Take a image data set from any online repository and use
ANN for classification
import pandas as pd
import numpy as np
import keras
import matplotlib.pyplot as plt
%matplotlib inline
mnist = keras.datasets.fashion_mnist
(x_train, y_train), (x_test, y_test)= mnist.load_data()
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)
x_train[0].shape
plt.imshow(x_train[0],cmap='gray')
y_train[0]
image_height,image_width=28,28
x_train = x_train.reshape(60000,image_height*image_width)
x_test=x_test.reshape(10000,image_height*image_width)
print(x_train.shape)
print(x_test.shape)
print(x_train[0])
x_train=x_train.astype('float32')
x_test=x_test.astype('float32')
x_train/=255.0
x_test/=255.0
print(x_train[0])
print(y_train.shape)
print(y_test.shape)
y_train = to_categorical(y_train,10)
print(y_train.shape)
y_test= to_categorical(y_test,10)
print(y_test)
model=Sequential()
model.add(Dense(512, input_shape=(784,), name='HiddenLayer-1', activation='relu'))
model.add(Dense(512, name='HiddenLayer-2', activation='relu'))
model.add(Dense(10, name='OutputLayer', activation='softmax'))
model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
model.summary()
print("\nTraining Progress:\n------------------------------------")
#Fit the model. This will perform the entire training cycle, including
#forward propagation, loss computation, backward propagation and gradient descent.
#Execute for the specified batch sizes and epoch
#Perform validation after each epoch
history=model.fit(x_train,
y_train,
batch_size=BATCH_SIZE,
epochs=EPOCHS,
verbose=VERBOSE,
validation_split=VALIDATION_SPLIT)
plt.plot(history.history["accuracy"])
plt.plot(history.history["accuracy"])
plt.plot(history.history["val_accuracy"])
plt.plot(history.history["accuracy"])
plt.plot(history.history["val_accuracy"])
plt.plot(history.history["loss"])
score=model.evaluate(x_test,y_test)
# Returns the loss and metrics value of the model
Score
3. Result/Output/Writing Summary:
Learning outcomes (What I have learnt):
Evaluation Grid: