text: from keras.preprocessing.image import array_to_img, img_to_array, load_img
  
  def convert_image_to_array(files):
      images_as_array=[]
      for file in files:
          # Convert to Numpy Array
          images_as_array.append(img_to_array(load_img(file)))
      return images_as_array
  
  x_train = np.array(convert_image_to_array(x_train))
  print('Training set shape : ',x_train.shape)
  
  x_valid = np.array(convert_image_to_array(x_valid))
  print('Validation set shape : ',x_valid.shape)
  
  x_test = np.array(convert_image_to_array(x_test))
  print('Test set shape : ',x_test.shape)
  
  from keras.models import Sequential
  from keras.layers import Conv2D,MaxPooling2D
  from keras.layers import Activation, Dense, Flatten, Dropout
  from keras.preprocessing.image import ImageDataGenerator
  from keras.callbacks import ModelCheckpoint
  from keras import backend as K
  
  model=Sequential()
  model.add(Conv2D(filters = 16, kernel_size = 2,input_shape=(100,100,3),padding='same'))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=2))
  
  model.add(Conv2D(filters = 32,kernel_size = 2,activation= 'relu',padding='same'))
  model.add(MaxPooling2D(pool_size=2))
  
  model.add(Conv2D(filters = 64,kernel_size = 2,activation= 'relu',padding='same'))
  model.add(MaxPooling2D(pool_size=2))
  
  model.add(Conv2D(filters = 128,kernel_size = 2,activation= 'relu',padding='same'))
  model.add(MaxPooling2D(pool_size=2))
  
  model.add(Conv2D(filters = 256,kernel_size = 2,activation= 'relu',padding='same'))
  model.add(MaxPooling2D(pool_size=2))
  
  model.add(Dropout(0.2))
  model.add(Flatten())
  model.add(Dense(150))
  model.add(Activation('relu'))
  model.add(Dropout(0.3))
  model.add(Dense(41,activation = 'softmax'))
  model.summary()
  
  model.compile(loss='categorical_crossentropy',
                optimizer='adam',
                metrics=['accuracy'])
  print('Compiled!')
  
  from keras.models import Sequential
  from keras.layers import Conv2D,MaxPooling2D
  from keras.layers import Activation, Dense, Flatten, Dropout
  from keras.preprocessing.image import ImageDataGenerator
  from keras.callbacks import ModelCheckpoint
  from keras import backend as K
  batch_size = 50
  
  checkpointer = ModelCheckpoint(filepath = 'cnn_from_scratch_fruits.hdf5', verbose = 1, save_best_only = True)
  
  history = model.fit(x_train,y_train,
          batch_size = 50,
          epochs=15,
          validation_data=(x_valid, y_vaild),
          callbacks = [checkpointer],
                      verbose=2,shuffle=True
          )
          
  model.load_weights('cnn_from_scratch_fruits.hdf5')
  score = model.evaluate(x_test, y_test, verbose=0)
  print('\n', 'Test accuracy:', score[1])
  
  import matplotlib.pyplot as plt
  
  # Plot training & validation accuracy values
  plt.plot(history.history['accuracy'])
  plt.plot(history.history['val_accuracy'])
  plt.title('Model accuracy')
  plt.ylabel('Accuracy')
  plt.xlabel('Epoch')
  plt.legend(['Train', 'Test'], loc='upper left')
  plt.show()
  
  # Plot training & validation loss values
  plt.plot(history.history['loss'])
  plt.plot(history.history['val_loss'])
  plt.title('Model loss')
  plt.ylabel('Loss')
  plt.xlabel('Epoch')
  plt.legend(['Train', 'Test'], loc='upper left')
  plt.show()
  