This commit is contained in:
Pei-Yun Sun 2020-10-20 00:40:47 +11:00
parent 3b4241f165
commit 5af2071aa0
15 changed files with 41 additions and 45 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
from flask import Flask from flask import Flask
from flask_mongoengine import MongoEngine from flask_mongoengine import MongoEngine
from deepface import DeepFaceLite from deepface.DeepFaceLite import DeepFaceLite
# import tensorflow as tf # import tensorflow as tf
# from tensorflow.python.keras.backend import set_session # from tensorflow.python.keras.backend import set_session
import os import os

Binary file not shown.

View File

@ -62,9 +62,9 @@ class DeepFaceLite(object):
all_emotions = {} all_emotions = {}
for i in range(0, len(emotion_labels)): for j in range(0, len(emotion_labels)):
emotion_label = emotion_labels[i] emotion_label = emotion_labels[j]
emotion_prediction = 100 * emotion_predictions[i] / sum_of_predictions emotion_prediction = 100 * emotion_predictions[j] / sum_of_predictions
all_emotions[emotion_label] = emotion_prediction all_emotions[emotion_label] = emotion_prediction
emotion = { emotion = {

View File

@ -138,14 +138,16 @@ def detect_face(img, detector_backend='opencv', enforce_detection=True):
# drawing settings # drawing settings
font = ImageFont.truetype(font='font/FiraMono-Medium.otf', font = ImageFont.truetype(font='font/FiraMono-Medium.otf',
size=np.floor(3e-2 * img.size[1] + 0.5).astype('int32')) size=np.floor(2e-2 * img.size[1] + 0.5).astype('int32'))
thickness = (img.size[0] + img.size[1]) // 300 thickness = (img.size[0] + img.size[1]) // 300
hsv_tuples = [(x / 50, 1., 1.)
for x in range(50)] # # colors
colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples)) # hsv_tuples = [(x / 50, 1., 1.)
colors = list( # for x in range(50)]
map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)), colors)) # colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
np.random.shuffle(colors) # Shuffle colors to decorrelate adjacent classes. # colors = list(
# map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)), colors))
# np.random.shuffle(colors) # Shuffle colors to decorrelate adjacent classes.
# keep PIL image and cv2 image # keep PIL image and cv2 image
@ -205,12 +207,12 @@ def detect_face(img, detector_backend='opencv', enforce_detection=True):
for i in range(thickness): for i in range(thickness):
draw.rectangle( draw.rectangle(
[left + i, top + i, right - i, bottom - i], [left + i, top + i, right - i, bottom - i],
outline=colors[i]) outline='blue')
if showid: if showid:
draw.rectangle( draw.rectangle(
[tuple(text_origin), tuple(text_origin + label_size)], [tuple(text_origin), tuple(text_origin + label_size)],
fill=colors[i] fill='blue'
) )
draw.text(text_origin, label, fill=(0, 0, 0), font=font) draw.text(text_origin, label, fill=(0, 0, 0), font=font)
del draw del draw
@ -325,12 +327,12 @@ def detect_face(img, detector_backend='opencv', enforce_detection=True):
for i in range(thickness): for i in range(thickness):
draw.rectangle( draw.rectangle(
[left + i, top + i, right - i, bottom - i], [left + i, top + i, right - i, bottom - i],
outline=colors[i]) outline='blue')
if showid: if showid:
draw.rectangle( draw.rectangle(
[tuple(text_origin), tuple(text_origin + label_size)], [tuple(text_origin), tuple(text_origin + label_size)],
fill=colors[i] fill='blue'
) )
draw.text(text_origin, label, fill=(0, 0, 0), font=font) draw.text(text_origin, label, fill=(0, 0, 0), font=font)
del draw del draw
@ -391,12 +393,12 @@ def detect_face(img, detector_backend='opencv', enforce_detection=True):
for i in range(thickness): for i in range(thickness):
draw.rectangle( draw.rectangle(
[left + i, top + i, right - i, bottom - i], [left + i, top + i, right - i, bottom - i],
outline=colors[i]) outline='blue')
if showid: if showid:
draw.rectangle( draw.rectangle(
[tuple(text_origin), tuple(text_origin + label_size)], [tuple(text_origin), tuple(text_origin + label_size)],
fill=colors[i] fill='blue'
) )
draw.text(text_origin, label, fill=(0, 0, 0), font=font) draw.text(text_origin, label, fill=(0, 0, 0), font=font)
del draw del draw
@ -452,12 +454,12 @@ def detect_face(img, detector_backend='opencv', enforce_detection=True):
for i in range(thickness): for i in range(thickness):
draw.rectangle( draw.rectangle(
[left + i, top + i, right - i, bottom - i], [left + i, top + i, right - i, bottom - i],
outline=colors[i]) outline='blue')
if showid: if showid:
draw.rectangle( draw.rectangle(
[tuple(text_origin), tuple(text_origin + label_size)], [tuple(text_origin), tuple(text_origin + label_size)],
fill=colors[i] fill='blue'
) )
draw.text(text_origin, label, fill=(0, 0, 0), font=font) draw.text(text_origin, label, fill=(0, 0, 0), font=font)
del draw del draw

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.