text: # -*- coding: utf-8 -*-
  """emotion_prediction.ipynb
  
  Automatically generated by Colaboratory.
  
  Original file is located at
      https://colab.research.google.com/drive/1H-MGtaY7x4osjYowCoBADqCkro5tr6oS
  """
  
  from keras.models import Sequential
  import keras as k
  import tensorflow as tf
  from keras.models import Sequential
  from keras.layers import Conv2D, Activation, BatchNormalization, GlobalAvgPool2D, MaxPooling2D, Dropout
  
  from keras import preprocessing
  
  from google.colab import drive
  drive.mount("/content/gdrive")
  
  from keras.layers import Conv2D, MaxPool2D, Flatten,Dense,Dropout,BatchNormalization, Input
  
  import zipfile
  from google.colab import drive
  
  drive.mount('/content/drive/')
  
  zip_ref = zipfile.ZipFile("/content/emotion.zip", 'r')
  zip_ref.extractall()
  zip_ref.close()
  
  file = ('/content/train')
  
  file1=('/content/test')
  
  from keras.preprocessing.image import ImageDataGenerator
  
  train_datagen = k.preprocessing.image.ImageDataGenerator(rescale=1./255, horizontal_flip=True)
  
  train_gen = train_datagen.flow_from_directory(directory = file, subset='training', target_size=(150,150), shuffle=True, class_mode='categorical', batch_size=16)
  test_datagen = k.preprocessing.image.ImageDataGenerator(rescale=1./255)
  test_gen = test_datagen.flow_from_directory(directory= file1, subset='validation', shuffle=True, class_mode='categorical', target_size=(150,150), batch_size=16)
  
  model = Sequential()
  model.add(Dense(512, activation='relu'))
  model.add(BatchNormalization())
  model.add(Dropout(.25))
  model.add(Dense(256, activation='relu'))
  model.add(MaxPooling2D(pool_size=[3,3], strides=2, padding='valid'))
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(.15))
  
  model.add(Dense(64, activation='relu'))
  model.add(Flatten())
  
  model.add(Dense(7, activation='sigmoid'))
  
  model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['categorical_accuracy'])
  
  model= model.fit(train_gen, validation_data = test_gen, epochs=90, verbose=2)
  
  model.history['categorical_accuracy']
  
  model.history['loss']
  
  model.model.save('emotion_pred.h5')
  
  train_loss, train_acc = model.model.evaluate(train_gen)
  print("final train accuracy = {:.2f} , train loss = {:.2f}".format(train_acc*100, train_loss*100))
  
  import cv2
  
  import matplotlib.pyplot as plt
  
  import numpy as np
  
  
  x = plt.imread('/sad1.jpg')
  plt.imshow(x)
  
  x = x/255
  
  x = np.resize(x,(1,150,150,3))
  
  x.shape
  
  classes = list(train_gen.class_indices)
  
  print(classes[np.argmax(model.model.predict(x))])