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

add utils.py file

parent 820db5ec
No related branches found
No related tags found
No related merge requests found
...@@ -4,15 +4,18 @@ import numpy as np ...@@ -4,15 +4,18 @@ import numpy as np
import cv2 import cv2
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
maxNbrImages = 484845
nbrImages = 35887
maxNbrImages = nbrImages
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"] emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
def traitement(a,b,c): #For testing def traitement(a,b,c): #For testing
arr = strToArray(b)
print(a)
plt.imshow(arr)
plt.show()
pass pass
# arr = strToArray(b)
# print(a)
# plt.imshow(arr)
# plt.show()
# pass
def strToArray(string): #Fer2013 provides images as string so it needs to be transformed def strToArray(string): #Fer2013 provides images as string so it needs to be transformed
A = [] A = []
...@@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file: ...@@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file:
X.append(strToArray(stringImage)) X.append(strToArray(stringImage))
Y.append(emotionNbr) Y.append(emotionNbr)
print(f"Image {i} sur {nbrImages} chargée", end='\r')
X = np.array(X) X = np.array(X)
Y = np.array(Y) Y = np.array(Y)
\ No newline at end of file
utils.py 0 → 100644
def afficher(image):
if len(image.shape) == 3:
if image.shape[2] == 3: # (h,l,3)
plt.imshow(image)
elif image.shape[2] == 1: # (h,l,1)->(h,l)
image2 = image
plt.imshow(tf.squeeze(image))
elif len(image.shape)== 2: # (h,l)
plt.imshow(image)
def predir():
pass
def normAndResize(image):
#For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
image = cv2.resize(image, dsize=(h,l), interpolation=cv2.INTER_CUBIC) #resize for h and l #
if len(image.shape) == 3 and p==1 and image.shape[2] != 1 : #if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
image = image.mean(2)
image = np.reshape(image, (h,l,p)) #restore third dimension
image = image.astype("float32")
image = image/255 #normalisation
return image
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment