diff --git a/loadFer2013ds.py b/loadFer2013ds.py index e7aea3716f1cb76b52608b1c0546fb3d84d5a1a8..6e4f76c267c5056c35a555c3d8e2af7e561490bb 100644 --- a/loadFer2013ds.py +++ b/loadFer2013ds.py @@ -4,15 +4,18 @@ import numpy as np import cv2 import matplotlib.pyplot as plt -maxNbrImages = 484845 + +nbrImages = 35887 +maxNbrImages = nbrImages emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"] def traitement(a,b,c): #For testing - arr = strToArray(b) - print(a) - plt.imshow(arr) - plt.show() 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 A = [] @@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file: X.append(strToArray(stringImage)) Y.append(emotionNbr) + print(f"Image {i} sur {nbrImages} chargée", end='\r') + X = np.array(X) Y = np.array(Y) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..6edd9d5accb809cbd3fd906a6bdf8e464f2e2866 --- /dev/null +++ b/utils.py @@ -0,0 +1,24 @@ +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