diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..97493a3 Binary files /dev/null and b/db.sqlite3 differ diff --git a/deepemotion/__init__.py b/deepemotion/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deepemotion/__init__.pyc b/deepemotion/__init__.pyc new file mode 100644 index 0000000..b6a0b6c Binary files /dev/null and b/deepemotion/__init__.pyc differ diff --git a/deepemotion/__pycache__/__init__.cpython-35.pyc b/deepemotion/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..c8c2879 Binary files /dev/null and b/deepemotion/__pycache__/__init__.cpython-35.pyc differ diff --git a/deepemotion/__pycache__/admin.cpython-35.pyc b/deepemotion/__pycache__/admin.cpython-35.pyc new file mode 100644 index 0000000..af104c5 Binary files /dev/null and b/deepemotion/__pycache__/admin.cpython-35.pyc differ diff --git a/deepemotion/__pycache__/models.cpython-35.pyc b/deepemotion/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000..e70ca76 Binary files /dev/null and b/deepemotion/__pycache__/models.cpython-35.pyc differ diff --git a/deepemotion/__pycache__/views.cpython-35.pyc b/deepemotion/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..d4441e1 Binary files /dev/null and b/deepemotion/__pycache__/views.cpython-35.pyc differ diff --git a/deepemotion/admin.py b/deepemotion/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/deepemotion/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/deepemotion/admin.pyc b/deepemotion/admin.pyc new file mode 100644 index 0000000..7e2a2ab Binary files /dev/null and b/deepemotion/admin.pyc differ diff --git a/deepemotion/apps.py b/deepemotion/apps.py new file mode 100644 index 0000000..34d29bc --- /dev/null +++ b/deepemotion/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DeepemotionConfig(AppConfig): + name = 'deepemotion' diff --git a/deepemotion/core/__init__.py b/deepemotion/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deepemotion/core/__init__.pyc b/deepemotion/core/__init__.pyc new file mode 100644 index 0000000..3d50963 Binary files /dev/null and b/deepemotion/core/__init__.pyc differ diff --git a/deepemotion/core/effect.py b/deepemotion/core/effect.py new file mode 100644 index 0000000..55f5f72 --- /dev/null +++ b/deepemotion/core/effect.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +######## REFs face detection ######## +# https://www.superdatascience.com/opencv-face-detection/ +##################################### + +from keras.models import load_model +from keras import backend as K +import tensorflow as tf + +import os +import numpy as np +import cv2 + +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt + +os.environ["CUDA_VISIBLE_DEVICES"] = "" # do not use the GPU + +img_rows, img_cols = 48, 48 + +labels_txt = np.array(['Colère', 'Peur', 'Joie', 'Tristesse', 'Surprise', 'Neutre']) + +num_classes = labels_txt.size + +graph = tf.get_default_graph() +model = load_model(r'/home/jeremie/jeremie/topten/static/model/trained_model') +IMP = np.load(r'/home/jeremie/jeremie/topten/static/model/IMP.npy') +print "model loaded" + +face_cascade = cv2.CascadeClassifier() +face_cascade_name = "/home/jeremie/miniconda2/envs/keras/lib/python2.7/site-packages/cv2/data/haarcascade_frontalface_default.xml" +face_cascade.load(face_cascade_name) +print "face detector loaded" + +def transform_image(im): + im2 = im.astype(np.float32)*1 + im2 -= 127.817 + im2 /= 74.3659 + return im2 + +def cut_face(im, cascade_classifier): + faces = cascade_classifier.detectMultiScale(im) + print(len(faces), "face(s) detected") + if len(faces) != 0: + x, y, w, h = [ v for v in faces[0] ] + return im[y:y+h, x:x+w] + else: + return im*0 + return im + +def reconstruct_image(im): + im2 = im.astype(np.float32)*1 + im2 *= 74.3659 + im2 += 127.817 + return np.squeeze(im2.astype(np.uint8)) + +def transform(fname): + image_path = fname + custom_image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) + custom_image = cut_face(custom_image, face_cascade) + + clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) + custom_input = clahe.apply(custom_image) + + sh = custom_input.shape + custom_input = cv2.resize(custom_input, (img_rows, img_cols)) + custom_input = transform_image(custom_input) + custom_input = np.expand_dims(custom_input, axis=0) + custom_input = np.expand_dims(custom_input, axis=0) + with graph.as_default(): + res1 = model.predict(custom_input, verbose=0)[0] + res2 = model.predict(np.fliplr(custom_input), verbose=0)[0] + res = (res1+res2)/2. + k = np.argmax(res) + + input_img = model.layers[0].input + for l in model.layers: + if(l.name == 'last_conv'): + layer_output = l.output + get_acti = K.function([input_img, K.learning_phase()], [layer_output[:,:,:,:]]) + + fig = plt.figure() + img = np.zeros((sh[0], sh[1])) + acti = np.squeeze(get_acti([custom_input,0])[0]) + for i in range(IMP[k].size): + img += IMP[k][i]*cv2.resize(np.abs(acti[i]), (sh[1], sh[0])) + plt.imshow(custom_image, cmap='gray') + plt.imshow(img, alpha=0.4, cmap='bwr') + plt.axis('off') + fig.tight_layout() + fig.savefig("static/temp2.jpeg") + return res[0], labels_txt[k] + diff --git a/deepemotion/core/effect.pyc b/deepemotion/core/effect.pyc new file mode 100644 index 0000000..1ced883 Binary files /dev/null and b/deepemotion/core/effect.pyc differ diff --git a/deepemotion/migrations/__init__.py b/deepemotion/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deepemotion/migrations/__init__.pyc b/deepemotion/migrations/__init__.pyc new file mode 100644 index 0000000..22f2398 Binary files /dev/null and b/deepemotion/migrations/__init__.pyc differ diff --git a/deepemotion/migrations/__pycache__/__init__.cpython-35.pyc b/deepemotion/migrations/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..a5f9766 Binary files /dev/null and b/deepemotion/migrations/__pycache__/__init__.cpython-35.pyc differ diff --git a/deepemotion/models.py b/deepemotion/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/deepemotion/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/deepemotion/models.pyc b/deepemotion/models.pyc new file mode 100644 index 0000000..75b81b2 Binary files /dev/null and b/deepemotion/models.pyc differ diff --git a/deepemotion/templates/deepemotion/index.html b/deepemotion/templates/deepemotion/index.html new file mode 100644 index 0000000..f0622c2 --- /dev/null +++ b/deepemotion/templates/deepemotion/index.html @@ -0,0 +1,80 @@ + +{% load static %} + +
+ + +* plus une zone est rouge, plus celle-ci a été déterminante dans la décision du réseau.
+`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\n// stylelint-disable font-family-no-duplicate-names\npre,\ncode,\nkbd,\nsamp {\n font-family: monospace, monospace; // Correct the inheritance and scaling of font size in all browsers.\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n// stylelint-enable font-family-no-duplicate-names\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg:not(:root) {\n overflow: hidden; // Hide the overflow in IE\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $text-muted;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `
`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\n// stylelint-disable font-family-no-duplicate-names\npre,\ncode,\nkbd,\nsamp {\n font-family: monospace, monospace; // Correct the inheritance and scaling of font size in all browsers.\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n// stylelint-enable font-family-no-duplicate-names\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg:not(:root) {\n overflow: hidden; // Hide the overflow in IE\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $text-muted;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `
`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\n// stylelint-disable font-family-no-duplicate-names\npre,\ncode,\nkbd,\nsamp {\n font-family: monospace, monospace; // Correct the inheritance and scaling of font size in all browsers.\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n// stylelint-enable font-family-no-duplicate-names\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg:not(:root) {\n overflow: hidden; // Hide the overflow in IE\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $text-muted;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `