text: # -*- coding: utf-8 -*-
  """fashion_mnist_90acc_with_convnet.ipynb
  
  Automatically generated by Colaboratory.
  
  Original file is located at
      https://colab.research.google.com/drive/1yCLd9wvis7rEVVuG_I2ZonwxZiIQp1p8
  """
  
  import tensorflow as tf
  print(tf.__version__)
  
  import matplotlib.pyplot as plt
  from tensorflow import keras
  
  #loading the fashion mnist dataset
  fashion_mnist = keras.datasets.fashion_mnist
  (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
  
  #noramalizing the image pixels
  x_train , x_test = train_images/255.0, test_images/255.0
  
  #defining the model architecture 
  class mycallback(keras.callbacks.Callback):
    def on_epoch_end(self, epoch, logs ={}):
      if(logs.get('accuracy') is not None and logs.get('accuracy')>0.95):
        print('\nReached 95% accruacy! so canceling training')
        self.model.stop_training = True
  
  
  model = keras.Sequential([keras.layers.Conv2D(64, (3,3), activation = 'relu', input_shape = (28,28,1)),
                            keras.layers.MaxPooling2D((2,2)),
                            keras.layers.Conv2D(64, (3,3), activation = 'relu'),
                            keras.layers.MaxPooling2D((2,2)),
                            keras.layers.Flatten(),
                            keras.layers.Dense(128, activation = 'relu'),
                            keras.layers.Dense(10, activation ='softmax')])
  model.compile(optimizer = 'adam',
                loss = 'sparse_categorical_crossentropy',
                metrics = ['accuracy'])
  
  model.summary()
  
  callbacks = mycallback()
  
  model.fit(x_train, train_labels, epochs = 10, callbacks = [callbacks])
  
  
  
  f, axarr = plt.subplots(3,4)
  from matplotlib.pyplot import figure
  figure(figsize=(20, 6))
  
  FIRST_IMAGE=0
  SECOND_IMAGE=7
  THIRD_IMAGE=26
  CONVOLUTION_NUMBER = 1
  
  from tensorflow.keras import models
  layer_outputs = [layer.output for layer in model.layers]
  activation_model = models.Model(inputs = model.input, outputs = layer_outputs)
  for x in range(0, 4):
    f1 = activation_model.predict(x_test[FIRST_IMAGE].reshape(1,28,28,1))[x]
    axarr[0,x].imshow(f1[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
    axarr[0,x].grid(False)
    f2 = activation_model.predict(test_images[SECOND_IMAGE].reshape(1, 28, 28, 1))[x]
    axarr[1,x].imshow(f2[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
    axarr[1,x].grid(False)
    f3 = activation_model.predict(test_images[THIRD_IMAGE].reshape(1, 28, 28, 1))[x]
    axarr[2,x].imshow(f3[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
    axarr[2,x].grid(False)
  
  test_loss, test_acc = model.evaluate(x_test, test_labels)
  
  print('test accuracy: {}'.format(test_acc))
  
  