Skip to content
Snippets Groups Projects
Commit 1ee47b07 authored by Timothé Boulet's avatar Timothé Boulet :alien:
Browse files

build model

parent 011d6525
No related branches found
No related tags found
No related merge requests found
Showing
with 1358 additions and 122 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed.
This diff is collapsed.
...@@ -6,3 +6,4 @@ emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"] ...@@ -6,3 +6,4 @@ emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
# Shape of input of the model # Shape of input of the model
input_shape = (48, 48, 1) input_shape = (48, 48, 1)
# input_shape = (64,64,1)
This diff is collapsed.
File added
File added
File added
...@@ -5,7 +5,7 @@ import imageProcess as ip ...@@ -5,7 +5,7 @@ import imageProcess as ip
import numpy as np import numpy as np
def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=False): def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=False, count=False):
print(f"\nCHARGEMENT DE {nbrMaxImages} DONNEES DEPUIS EXPW...") print(f"\nCHARGEMENT DE {nbrMaxImages} DONNEES DEPUIS EXPW...")
folderImages = 'data/expW/images/' folderImages = 'data/expW/images/'
fileLabels = 'data/expW/labels.lst' fileLabels = 'data/expW/labels.lst'
...@@ -20,11 +20,10 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal ...@@ -20,11 +20,10 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal
if nbrImages>=nbrMaxImages: break if nbrImages>=nbrMaxImages: break
k+= 1 k+= 1
#Face extraction, according to the dataset annotations AND the face detector (cascade) #Face extraction, according to the dataset annotations
imageName, Id, top, left, right, bottom, cofidence, label = line.strip().split(' ') imageName, Id, top, left, right, bottom, cofidence, label = line.strip().split(' ')
image = cv2.imread(folderImages+imageName) image = cv2.imread(folderImages+imageName)
faceAccordingToDS = image[int(top):int(bottom), int(left):int(right)] faceAccordingToDS = image[int(top):int(bottom), int(left):int(right)]
facesDetected = ip.imageProcess(faceAccordingToDS, writeEmotion=False, writeRectangle=False)
#Suivi visuel (facultatif, fait un peu peur sans attendre 1000ms entre deux images...) #Suivi visuel (facultatif, fait un peu peur sans attendre 1000ms entre deux images...)
if False: if False:
...@@ -35,11 +34,15 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal ...@@ -35,11 +34,15 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal
#Add extracted data to our dataset #Add extracted data to our dataset
if len(facesDetected) == 1 or not onlyDetected: #Otherwise no face were detected or a no-face was detected as face if len(facesDetected) == 1 or not onlyDetected: #Otherwise no face were detected or a no-face was detected as face
#Select in priority image detected by detector #Select detected face (if there is 1) or face according to the dataset
if len(facesDetected) != 0 and detectedFace: if detectedFace:
facesDetected = ip.imageProcess(faceAccordingToDS, writeEmotion=False, writeRectangle=False)
if len(facesDetected) ==1:
face = facesDetected[0] face = facesDetected[0]
else: else:
face = faceAccordingToDS face = faceAccordingToDS
else:
face = faceAccordingToDS
#Colored N*M*3 face to gray 48*48*1 image. #Colored N*M*3 face to gray 48*48*1 image.
gray = normAndResize(face, input_shape) gray = normAndResize(face, input_shape)
...@@ -49,7 +52,8 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal ...@@ -49,7 +52,8 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal
nbrImages += 1 nbrImages += 1
print(f"{nbrImages} données chargées depuis expW (sur {k} données traités).", end='\r') #Print number of datas loaded every 1000 datas
if count and nbrImages%1000==0: print(f"{nbrImages} données chargées depuis expW (sur {k} données traités).")
X = np.array(X) X = np.array(X)
Y = np.array(Y) Y = np.array(Y)
......
...@@ -25,7 +25,7 @@ def strToArray(string): # Fer2013 provides images as string so it needs to be t ...@@ -25,7 +25,7 @@ def strToArray(string): # Fer2013 provides images as string so it needs to be t
A.append(int(nbr)) A.append(int(nbr))
A = np.array(A) A = np.array(A)
A = np.reshape(A, input_shape) A = np.reshape(A, (48,48,1))
return A return A
......
This diff is collapsed.
File added
File added
File added
...@@ -25,7 +25,8 @@ def normAndResize(image, input_shape): ...@@ -25,7 +25,8 @@ def normAndResize(image, input_shape):
# For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it. # For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
h, l, p = input_shape h, l, p = input_shape
# resize for h and l # # resize for h and l
# print(image.shape) #
image = cv2.resize(image, dsize=(h, l), interpolation=cv2.INTER_CUBIC) image = cv2.resize(image, dsize=(h, l), interpolation=cv2.INTER_CUBIC)
# if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image) # if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
if len(image.shape) == 3 and p == 1 and image.shape[2] != 1: if len(image.shape) == 3 and p == 1 and image.shape[2] != 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment