<jupyter_start><jupyter_text>Deep Learning for Image Classification AssessmentWelcome to your assessment! Follow the instructions in bold below to complete the assessment.If you get stuck, check out the solutions video and notebook. (Make sure to run the solutions notebook before posting a question to the QA forum please, thanks!)------------ The Challenge**Your task is to build an image classifier with Keras and Convolutional Neural Networks for the Fashion MNIST dataset. This data set includes 10 labels of different clothing types with 28 by 28 *grayscale* images. There is a training set of 60,000 images and 10,000 test images.**    Label	Description    0	    T-shirt/top    1	    Trouser    2	    Pullover    3	    Dress    4	    Coat    5	    Sandal    6	    Shirt    7	    Sneaker    8	    Bag    9	    Ankle boot       The Data**TASK 1: Run the code below to download the dataset using Keras.**<jupyter_code>from keras.datasets import fashion_mnist

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()<jupyter_output>Using TensorFlow backend.<jupyter_text>Visualizing the Data**TASK 2: Use matplotlib to view an image from the data set. It can be any image from the data set.**<jupyter_code>import matplotlib.pyplot as plt
import cv2
plt.imshow(x_train[0])<jupyter_output><empty_output><jupyter_text>Preprocessing the Data**TASK 3: Normalize the X train and X test data by dividing by the max value of the image arrays.**<jupyter_code>x_train = x_train / x_train.max()
x_test = x_test / x_test.max()<jupyter_output><empty_output><jupyter_text>**Task 4: Reshape the X arrays to include a 4 dimension of the single channel. Similar to what we did for the numbers MNIST data set.**<jupyter_code>x_train.shape
x_train = x_train.reshape(60000,28,28,1)
x_test = x_test.reshape(10000,28,28,1)<jupyter_output><empty_output><jupyter_text>**TASK 5: Convert the y_train and y_test values to be one-hot encoded for categorical analysis by Keras.**<jupyter_code>from keras.utils import to_categorical
y_cat_train = to_categorical(y_train)
y_cat_test = to_categorical(y_test)<jupyter_output><empty_output><jupyter_text>Building the Model**TASK 5: Use Keras to create a model consisting of at least the following layers (but feel free to experiment):*** 2D Convolutional Layer, filters=32 and kernel_size=(4,4)* Pooling Layer where pool_size = (2,2)* Flatten Layer* Dense Layer (128 Neurons, but feel free to play around with this value), RELU activation* Final Dense Layer of 10 Neurons with a softmax activation**Then compile the model with these parameters: loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']**<jupyter_code>from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPool2D, Flatten
model = Sequential()


model.add(Conv2D(filters=32, kernel_size=(4,4),input_shape=(28, 28, 1), activation='relu',))

model.add(MaxPool2D(pool_size=(2, 2)))

model.add(Flatten())

model.add(Dense(128, activation='relu'))

model.add(Dense(10, activation='softmax'))


model.compile(loss='categorical_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])
model.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 25, 25, 32)        544       
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 12, 12, 32)        0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 4608)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 128)               589952    
_________________________________________________________________
dense_2 (Dense)              (None, 10)                1290      
=================================================================
Total params: 591,786
Trainable params: 591,786
Non-trainable params: 0
_________________________________________________________________<jupyter_text>Training the Model**TASK 6: Train/Fit the model to the x_train set. Amount of epochs is up to you.**<jupyter_code>history = model.fit(x_train,y_cat_train,epochs = 10)<jupyter_output>Epoch 1/10
60000/60000 [==============================] - 99s 2ms/step - loss: 0.4019 - acc: 0.8570: 1s - loss:
Epoch 2/10
60000/60000 [==============================] - 94s 2ms/step - loss: 0.2755 - acc: 0.9016
Epoch 3/10
60000/60000 [==============================] - 87s 1ms/step - loss: 0.2356 - acc: 0.9151
Epoch 4/10
60000/60000 [==============================] - 82s 1ms/step - loss: 0.2115 - acc: 0.9234
Epoch 5/10
60000/60000 [==============================] - 93s 2ms/step - loss: 0.1955 - acc: 0.9300
Epoch 6/10
60000/60000 [==============================] - 90s 1ms/step - loss: 0.1791 - acc: 0.9363
Epoch 7/10
60000/60000 [==============================] - 82s 1ms/step - loss: 0.1681 - acc: 0.9397
Epoch 8/10
60000/60000 [==============================] - 92s 2ms/step - loss: 0.1549 - acc: 0.9451: 0s - loss: 0.154
Epoch 9/10
60000/60000 [==============================] - 103s 2ms/step - loss: 0.1491 - acc: 0.9478
Epoch 10/10
60000/60000 [==============================] - 105s 2ms/s[...]<jupyter_text>Evaluating the Model**TASK 7: Show the accuracy,precision,recall,f1-score the model achieved on the x_test data set. Keep in mind, there are quite a few ways to do this, but we recommend following the same procedure we showed in the MNIST lecture.**<jupyter_code>model.metrics_names
model.evaluate(x_test,y_cat_test)
from sklearn.metrics import classification_report
predictions = model.predict_classes(x_test)
print(classification_report(y_test,predictions))<jupyter_output>precision    recall  f1-score   support

          0       0.87      0.86      0.87      1000
          1       1.00      0.97      0.98      1000
          2       0.88      0.84      0.86      1000
          3       0.92      0.92      0.92      1000
          4       0.80      0.90      0.85      1000
          5       0.98      0.97      0.98      1000
          6       0.78      0.73      0.75      1000
          7       0.95      0.98      0.96      1000
          8       0.97      0.99      0.98      1000
          9       0.98      0.96      0.97      1000

avg / total       0.91      0.91      0.91     10000
{'fraction_non_alphanumeric': 0.14995371798827523, 'fraction_numerical': 0.08701018204257945, 'mean_word_length': 3.42827868852459, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '597350', 'license': 'MIT', 'n_tokens_mistral': 2325, 'n_tokens_neox': 1934, 'n_words': 601, 'path': '08DLCVAssessment.ipynb', 'repo_name': 'MBadriNarayanan/OpenCV', 'size': '6482'}