Deliverable 4

Visual and Lingual Emotional Recognition using Deep Learning Techniques

We deployed the model which was trained and tested in Deliverable 1 on the android application. For the initial testing, we tried to test it on static images. Whenever the application starts, the model is loaded on the creation of the instance of the application. The images are reshaped in (1, 48, 48, 1) dimension and passed it to the model. As the last layer is Softmax, the model returns the array of probability of 7 classes (Angry, Disgust, Fear, Happy, Sad, Surprise, Neutral). The class having maximum probability is returned as the result. This model will be further enhanced and deployed with functionality of recognizing emotions based on speech as well.

  • Code Snippet for Prediction

  • protected void onCreate(Bundle savedInstanceState) {
    if (null == savedInstanceState) {
    .replace(, FirstFragment.getFragment())
    try {
    tflite = new Interpreter(loadModelFile());
    System.out.println("Model loaded Successfully");
    }catch (Exception ex){
    float [][][][] resizedarray = new float[1][48][48][1];
    int index = 0;
    for(int i = 0 ; I < 48 ; i++) {
      for(int j = 0 ; j < 48 ; j++){
      resizedarray[0][i][j][0] = image[index++];
    float[][] prediction = new float[1][7];,prediction);
    int maxIndex = 0;
    float max = prediction[0][0];
    for(int i = 0 ; I < prediction[0].length ; i++)
      max = prediction[0][I];
      maxIndex = I;
    System.out.println("Prediction Class\t" +emotions[maxIndex]);

  • image [] represents an array containing 2304 values. Each value represents single pixel of image flattened in one dimension. Each image is of dimension 48x48. OnCreate() function is called whenever the application starts. After starting the application, it creates an object of Interpreter in which tflite model is stored., output) method runs the model on the input which is provided. It returns the array of probabilities that the image belongs to which class. Highest class is selected based on the probability.
  • Code Snippet for loading the model

  • private MappedByteBuffer loadModelFile() throws IOException {
      AssetFileDescriptor fileDescriptor=this.getAssets().openFd("sequential.tflite");
      FileInputStream inputStream=new FileInputStream(fileDescriptor.getFileDescriptor());
      FileChannel fileChannel=inputStream.getChannel();
      long startOffset=fileDescriptor.getStartOffset();
      long declareLength=fileDescriptor.getDeclaredLength();
  • Predicted Output

  • Output