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

build model

parent efa4273e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
This diff is collapsed.
...@@ -10,12 +10,15 @@ def extractDataFromVideo_(filename, videoName, facesList, labelsList, maxNbrImag ...@@ -10,12 +10,15 @@ def extractDataFromVideo_(filename, videoName, facesList, labelsList, maxNbrImag
emotions = ["Neutral", "Angry", "Disgust", emotions = ["Neutral", "Angry", "Disgust",
"Fear", "Happy", "Sad", "Suprise"] "Fear", "Happy", "Sad", "Suprise"]
# Start capture of a video and reading of a label file # Start capture of a video and reading of a label file. Dont change the lists if file can not be read.
cap = cv2.VideoCapture(filename) cap = cv2.VideoCapture(filename)
if (cap.isOpened() == False): if (cap.isOpened() == False):
print("Error opening video") print("Error opening video")
try:
file = open("data/affwild/labels/"+videoName[:-4]+'.txt', 'r') file = open("data/affwild/labels/"+videoName[:-4]+'.txt', 'r')
except FileNotFoundError:
return facesList, labelsList
file.readline() file.readline()
# Read until video is completed # Read until video is completed
...@@ -37,7 +40,8 @@ def extractDataFromVideo_(filename, videoName, facesList, labelsList, maxNbrImag ...@@ -37,7 +40,8 @@ def extractDataFromVideo_(filename, videoName, facesList, labelsList, maxNbrImag
newFaces = ip.imageProcess(frame, writeEmotion=False) newFaces = ip.imageProcess(frame, writeEmotion=False)
# If 2 faces were detected, it means an error was made since there is only single-person videos here. # If 2 faces were detected, it means an error was made since there is only single-person videos here.
if len(newFaces) == 1: # The second condition means the image is irrelevant (no face on the picture)
if len(newFaces) == 1 and line[0] != '-':
facesList += newFaces facesList += newFaces
emotionNbr = emotionToNumber(emotions[int(line[0])]) emotionNbr = emotionToNumber(emotions[int(line[0])])
......
...@@ -41,3 +41,39 @@ def emotionToNumber(emotion): ...@@ -41,3 +41,39 @@ def emotionToNumber(emotion):
emotions = ["Angry", "Disgust", "Fear", emotions = ["Angry", "Disgust", "Fear",
"Happy", "Sad", "Suprise", "Neutral"] "Happy", "Sad", "Suprise", "Neutral"]
return emotions.index(emotion) return emotions.index(emotion)
def mergeToDatabase(listOfX, listOfY, validation_repart=[0.025, 0.025, 0.025, 0.025]):
# This shuffle each X, extract validation data, merge differents X, shuffle again.
listOfX_train, listOfY_train = [], []
listOfX_test, listOfY_test = [], []
for X, Y, rate in zip(listOfX, listOfY, validation_repart):
N = X.shape[0]
# Shuffle each X and Y the same way
shuffler = np.random.permutation(N)
X, Y = X[shuffler], Y[shuffler]
# Extract validation data
X_train, Y_train = X[:N*(1-rate)], Y[:N*(1-rate)]
X_test, Y_test = X[N*(1-rate):], Y[N*(1-rate):]
listOfX_train.append(X_train)
listOfY_train.append(Y_train)
listOfX_test.append(X_test)
listOfY_test.append(Y_test)
# Merge
BigX_train = np.stack(listOfX_train)
BigY_train = np.stack(listOfY_train)
BigX_test = np.stack(listOfX_test)
BigY_test = np.stack(listOfY_test)
# Shuffle the whole
shuffler = np.random.permutation(len(BigX_train))
BigX_train = BigX_train[shuffler]
BigY_train = BigY_train[shuffler]
shuffler = np.random.permutation(len(BigX_test))
BigX_test = BigX_test[shuffler]
BigY_test = BigY_test[shuffler]
return BigX_train, BigY_train, BigX_test, BigY_test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment