Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/emotion.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions emotion/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions emotion/.idea/emotion.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions emotion/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions emotion/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions emotion/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions emotion/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion emotion/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#Facial Emotion Sensing
# Facial Expression Recognition

Binary file added emotion/__pycache__/deepface.cpython-37.pyc
Binary file not shown.
Binary file added emotion/__pycache__/train.cpython-36.pyc
Binary file not shown.
Binary file added emotion/__pycache__/train.cpython-37.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions emotion/deepface2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

from deepface import DeepFace
#model = load_model('model.h5')
#demography = DeepFace.analyze("h.jpg") #passing nothing as 2nd argument will find everything
demography = DeepFace.analyze("h.jpg", ['age', 'gender', 'emotion']) #identical to the line above
#demographies = DeepFace.analyze(["img1.jpg", "img2.jpg", "img3.jpg"]) #analyzing multiple faces same time
print('\n', "-------------------")
print("Age: ", demography["age"])
print("Gender: ", demography["gender"])
print("Emotion: ", demography["dominant_emotion"])
#print("Race: ", demography["dominant_race"])
Binary file added emotion/emojis/Angry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/emojis/Fear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/emojis/Happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/emojis/Neutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/emojis/Sad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/emojis/Surprised.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emotion/h.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions emotion/lite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import cv2
import numpy as np
import tensorflow as tf


#from translator import translate_eg_ar


def init():
global labels, Arabic_labels
global interpreter

#labels = ['Angry', 'Disgusted', 'Fear', 'Happy', 'Neutral', 'Sad', 'Surprised']
#Arabic_labels = translate_eg_ar(labels)
Arabic_labels = ['غاضب', 'مشمئز', 'خائف', 'سعيد', 'طبيعى', 'حزين', 'متفاجىء']
interpreter = tf.lite.Interpreter(model_path="model2.tflite")
interpreter.allocate_tensors()




def detect(image):

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# check the type of the input tensor
floating_model = input_details[0]['dtype'] == np.float32

height = 48
width = 48
img = image
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# print(img.shape)
img = np.asarray(img)
img = cv2.resize(img, (width, height))
img = np.expand_dims(img, axis=-1)
# print(img.shape)
img = img.astype('float')
img /= 255.0

input_data = np.expand_dims(img, axis=0)
# print(input_data.shape)

if floating_model:
#input_data = (np.float32(input_data) - 127.5) / 127.5
input_data = (np.float32(input_data))


interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()

output_data = interpreter.get_tensor(output_details[0]['index'])
# print(output_data)
results = np.squeeze(output_data)
# print(results)

top_k = results.argsort()[-2:][::-1]
# print(Arabic_labels[top_k[0]])

for i in top_k:


if floating_model:
return float(results[i]), Arabic_labels[i]

else:
return float(results[i] / 255.0), Arabic_labels[i]
# exp = Arabic_labels[i]
#return exp




if __name__ == '__main__':
init()
img = cv2.imread('1happy.jpg')
emotion = detect(img)
print(emotion)
Binary file added emotion/model/emotion_best_weights.h5
Binary file not shown.
Binary file added emotion/model/emotion_recognition.h5
Binary file not shown.
Loading